RSpec-无效的空格字符导致未定义的方法“应该"? [英] RSpec - invalid space character causes undefined method ` should'?

查看:88
本文介绍了RSpec-无效的空格字符导致未定义的方法“应该"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在RubyMine&中编写规范时,偶尔会收到一个非常烦人的错误Atom似乎有一个无效的空格字符,因此ruby将第一个(空白)字符作为方法名称的一部分进行评估.

I sporadically get an really annoying error when writing specs in RubyMine & Atom where it seems like there is an invalid space character so ruby evaluates the first (blank) character as a part of the method name.

1) Activity 
     Failure/Error: it { should belong_to :micropost }
     NoMethodError:
       undefined method ` should' for #<RSpec::ExampleGroups::Activity:0x007fd00e41bd20>
     # ./spec/models/activity_spec.rb:5:in `block (2 levels) in <top (required)>'

请注意错误消息中' should'前面的空格.

Note the space in front of ' should' in the error message.

我尝试打开不可见的字符,但看不到与正常空格不同的地方.

I have tried turning on invisible characters and I can't see anything different than the normal space.

删除it块中的第一个空格并单击空格键可以解决此问题,但是一直回去并始终修复这些块是很烦人的.

Deleting the first space inside the it block and hitting the space bar fixes the issue but it's pretty annoying to go back and fix the blocks all the time.

关于导致错误的原因有什么想法?

Any ideas about what is causing the error?

根据我的建议,我在十六进制编辑器中打开了规范.令人讨厌的字节是C2 A0-

By suggestion I added opened the spec up in a hex editor. The offending bytes are C2 A0-

it { should belong_to :micropost }


69 74 20 7B C2 A0 73 68 6F 75 6C 64 20 62 65 6C 6F 6E 67 5F 74 6F 20 3A 6D 69 63 72 6F 70 6F 73 74 20 7D

推荐答案

最可能的原因是我的胖黄油手指碰到了 alt(选项) + 空格键.这也解释了为什么即使我更换了编辑器,它仍然会发生.

Turns out the most likely cause was that my fat butter fingers was hitting alt (option) + spacebar. Which also explains why it was happening even after I switched editors.

我通过下载 Karabiner 并激活了Non Breaking Space To Normal Space来解决了该问题.

I solved the issue by downloading Karabiner and activating Non Breaking Space To Normal Space.

这篇关于RSpec-无效的空格字符导致未定义的方法“应该"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆