为什么在进行RSpec断言时会出现ArgumentError?

时间:2011-12-30 09:07:11

标签: ruby rspec

我正在尝试做这样的事情:

describe 'hi' do
  it 'should render the home page' do
    visit '/'
    page.driver.response.status.should eql 200
    page.driver.response.content_type.should eql 'text/html'
    doc = Nokogiri::HTML(page.driver.response.body)
    div = doc.css('div#nav')
    div.length.should_not eql 0
  end
end

没有这一行,一切都按预期工作:

div.length.should_not eql 0

出现该行,我收到此错误:

<main>:659:in `method_missing': wrong number of arguments (1 for 2) (ArgumentError)
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/metadata.rb:78:in `flatten'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/metadata.rb:78:in `full_description_for'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/metadata.rb:23:in `[]'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/metadata.rb:51:in `full_description_for'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/metadata.rb:23:in `[]'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/example.rb:13:in `block (2 levels) in delegate_to_metadata'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/formatters/base_text_formatter.rb:164:in `dump_failure'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/formatters/base_text_formatter.rb:19:in `block in dump_failures'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/formatters/base_text_formatter.rb:17:in `each'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/formatters/base_text_formatter.rb:17:in `each_with_index'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/formatters/base_text_formatter.rb:17:in `dump_failures'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/reporter.rb:74:in `block in notify'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/reporter.rb:73:in `each'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/reporter.rb:73:in `notify'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/reporter.rb:23:in `finish'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/reporter.rb:14:in `report'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:21:in `run'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:80:in `run_in_process'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:69:in `run'
from /Users/Work/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:10:in `block in autorun'

这真的很奇怪 - div.length是一个fixnum。这似乎是一个非常基本的断言,我不明白我在这里做错了什么。有人有指点吗?

我正在使用RSpec 2.7.1,RSpec期望值为2.7.0。我有Ruby 1.9.2p290。

编辑:快速说明 - 我要求通过Capybara进行RSpec。

0 个答案:

没有答案