作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我使用任何基本匹配器运行这个简单的 RSpec 时,它不起作用:
文件: matcher_spec.rb
describe "a simple RSpec matcher" do
true.should be_true
end
使用的任何匹配器的输出如下所示:
/private/tmp/rspec_matcher_test/matcher_spec.rb:3:in `block in <top (required)>': undefined local variable or method `be_true' for #<Class:0x007fdcd60ccb40> (NameError)
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:242:in `module_eval'
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:242:in `subclass'
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:228:in `describe'
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/dsl.rb:18:in `describe'
from /private/tmp/rspec_matcher_test/matcher_spec.rb:2:in `<top (required)>'
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Users/jcuzella/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
(是的,我是
answering my own question)
最佳答案
这是因为您忘记了 describe 块下方的“it”块。 RSpec DSL 不知道描述块范围内的匹配器。
要修复它,只需添加一个“it”块:
describe "a simple RSpec matcher" do
it "should work now" do
true.should be_true
end
end
_spec.rb:4:in `block in <top (required)>': undefined method `be' for #<Class:0x007f9ce20ea458> (NoMethodError)
_spec.rb:6:in `block in <top (required)>': undefined local variable or method `be_false' for #<Class:0x007fc59b0d2358> (NameError)
_spec.rb:7:in `block in <top (required)>': undefined local variable or method `be_nil' for #<Class:0x007fb5912afeb0> (NameError)
_spec.rb:8:in `block in <top (required)>': undefined local variable or method `be_nil' for #<Class:0x007f9a6d21f278> (NameError)
_spec.rb:18:in `block in <top (required)>': undefined local variable or method `be_empty' for #<Class:0x007fdff23260e8> (NameError)
_spec.rb:22:in `block in <top (required)>': undefined method `eq' for #<Class:0x007f9ac2a30110> (NoMethodError)
_spec.rb:26:in `block in <top (required)>': undefined method `eql' for #<Class:0x007fe45c188588> (NoMethodError)
_spec.rb:27:in `block in <top (required)>': undefined method `equal' for #<Class:0x007fc30c9a6a10> (NoMethodError)
_spec.rb:12:in `block in <top (required)>': undefined method `match' for #<Class:0x007fb142909160> (NoMethodError)
_spec.rb:13:in `block in <top (required)>': undefined method `be_within' for #<Class:0x007fe47da21728> (NoMethodError)
_spec.rb:19:in `block in <top (required)>': undefined method `have_key' for #<Class:0x007f9adc0df1c8> (NoMethodError)
_spec.rb:15:in `block in <top (required)>': undefined method `cover' for #<Class:0x007f868a304090> (NoMethodError)
_spec.rb:16:in `block in <top (required)>': undefined method `expect' for #<Class:0x007fbe62a8b2e0> (NoMethodError)
_spec.rb:14:in `include': wrong argument type Fixnum (expected Module) (TypeError)
关于rspec - 为什么 RSpec 匹配器不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16568940/
我是一名优秀的程序员,十分优秀!