I have a piece of code that I am trying to run with rspec.
我有一段代码,我试图用rspec运行。
require 'spec_helper'
describe "User" do
before { @user = User.new(name: "Example User", email: "user@example.com", password: "foobar", password_confirmation: "foobar") }
subject { @user }
it { should respond_to(:name)}
end
I get the following error
我收到以下错误
c:\Sites\sample_app>rspec spec/models/user_spec.rb
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec
/core/configuration.rb:819:in `load': c:/Sites/sample_app/spec/models/user_spec.
rb:1: syntax error, unexpected tIDENTIFIER, expecting end-of-input (SyntaxError)
before { @user...er'
Now I retype the test in a new file and run that and no error. I guess there is some encoding issue or something that I just have not learnt about that I am not getting. Is there anyone that could shed some light on this issue?
现在我在一个新文件中重新键入测试并运行它并且没有错误。我想有一些编码问题或者我没有学到的东西,我没有得到。有没有人可以对这个问题有所了解?
1 个解决方案
#1
19
You seem to indeed have been bitten by the "zero-width space problem". This is extremely frustrating, I know. You'd think that "show white space" should take care of the problem, particularly in an editor as advanced as Sublime.
你似乎确实被“零宽度空间问题”所困扰。我知道,这非常令人沮丧。你认为“显示空白”应该解决这个问题,特别是在像Sublime这样高级的编辑器中。
In any event, to detect the existence of these characters in Sublime 2, you can use this plugin. to display them.
无论如何,要在Sublime 2中检测这些字符的存在,您可以使用此插件。显示它们。
As an aside, I wasted hours if not days on this problem a few months ago when I copy/pasted some code from a website that had one of the little nasties in it.
顺便说一句,几个月前,当我从一个网站中复制/粘贴一些代码时,我就浪费了几个小时甚至几天的时间。
I searched the Sublime 2 site for any postings related to this (e.g. feature requests, etc.), but didn't find anything, so I don't know if this is on their radar.
我在Sublime 2网站上搜索了与此相关的任何帖子(例如功能请求等),但没有找到任何内容,所以我不知道这是否在他们的雷达上。
Note: The original version of this answer assumed that the zero-width space character was the same as the non-breaking space, which it is not. Non-breaking spaces, while they will still generate syntax errors, are much easier to detect since they "take up space" in your display (i.e. "look like" a space). There's also the "zero-width non-breaking space", which is different still. While it's easy to enter the non-breaking space on a Mac (i.e. Option-Space), I know of no way to enter any of the zero-width spaces.
注意:此答案的原始版本假设零宽度空格字符与非中断空格相同,而不是。非破坏空间虽然仍会产生语法错误,但由于它们在显示器中“占用空间”(即“看起来像是一个空间”),因此更易于检测。还有“零宽度不间断空间”,这仍然是不同的。虽然很容易进入Mac上的不间断空间(即Option-Space),但我知道无法进入任何零宽度空间。
#1
19
You seem to indeed have been bitten by the "zero-width space problem". This is extremely frustrating, I know. You'd think that "show white space" should take care of the problem, particularly in an editor as advanced as Sublime.
你似乎确实被“零宽度空间问题”所困扰。我知道,这非常令人沮丧。你认为“显示空白”应该解决这个问题,特别是在像Sublime这样高级的编辑器中。
In any event, to detect the existence of these characters in Sublime 2, you can use this plugin. to display them.
无论如何,要在Sublime 2中检测这些字符的存在,您可以使用此插件。显示它们。
As an aside, I wasted hours if not days on this problem a few months ago when I copy/pasted some code from a website that had one of the little nasties in it.
顺便说一句,几个月前,当我从一个网站中复制/粘贴一些代码时,我就浪费了几个小时甚至几天的时间。
I searched the Sublime 2 site for any postings related to this (e.g. feature requests, etc.), but didn't find anything, so I don't know if this is on their radar.
我在Sublime 2网站上搜索了与此相关的任何帖子(例如功能请求等),但没有找到任何内容,所以我不知道这是否在他们的雷达上。
Note: The original version of this answer assumed that the zero-width space character was the same as the non-breaking space, which it is not. Non-breaking spaces, while they will still generate syntax errors, are much easier to detect since they "take up space" in your display (i.e. "look like" a space). There's also the "zero-width non-breaking space", which is different still. While it's easy to enter the non-breaking space on a Mac (i.e. Option-Space), I know of no way to enter any of the zero-width spaces.
注意:此答案的原始版本假设零宽度空格字符与非中断空格相同,而不是。非破坏空间虽然仍会产生语法错误,但由于它们在显示器中“占用空间”(即“看起来像是一个空间”),因此更易于检测。还有“零宽度不间断空间”,这仍然是不同的。虽然很容易进入Mac上的不间断空间(即Option-Space),但我知道无法进入任何零宽度空间。