RSpec - invalid space character causes undefined method ` should'?

↘锁芯ラ 提交于 2019-12-10 11:54:56

问题


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)>'

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.

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?

Added

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

回答1:


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.

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



来源:https://stackoverflow.com/questions/31629580/rspec-invalid-space-character-causes-undefined-method-should

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!