2012-03-18 38 views
2

使用Rails 3.2.2,我剛安裝的RSpec並試圖我的第一個測試:rspec的應包括嘗試的Chomp數組

require 'spec_helper' 

describe "Mains" do 
    describe "GET index" do 
    it "gets the page which has the proper content" do 
     get 'index.html' 
     response.status.should be(200) 
     response.body.should include("one") 
    end 
    end 
end 

當我運行規範,我得到

Failures: 

    1) Mains GET index gets the page which has the proper content 
    Failure/Error: response.body.should include("one") 
    NoMethodError: 
     undefined method `chomp' for ["one"]:Array 

這都兩岸出來的Ryan Bates' Railscast 257,所以我有點失落

在此先感謝,

+1

索引視圖和控制器的動作看起來怎麼樣? – nemesv 2012-03-18 08:27:05

+0

同樣的bug這裏的時候,在包括匹配單詞不存在。也許是rspec中的一個bug。 – 2012-03-21 14:50:05

回答

4

[編輯]這個問題是rspec-expectationscorrected,在master分支。你可以在你的Gemfile使用該修復:

gem 'rspec-rails', '~> 2.9' 
gem 'rspec-expectations', :git => "https://github.com/rspec/rspec-expectations.git", :branch => 'master' 

我遇到了同樣的問題上Rails 3.0.12rspec 2.9.0。恢復到rspec 2.8.0/rspec-rails 2.8.1的伎倆。

我提出an issue on Githubrspec/rspec-expectations,我們會看到,如果這真是一個錯誤。

作爲參考,這是步驟定義:

Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text| 
    current_email.default_part_body.to_s.should include(text) 
end 

...在特徵步驟:

step %{I should see "changer de mot de passe" in the email body} 

...這是提高:

undefined method `chomp' for ["changer de mot de passe"]:Array (NoMethodError) 
    ./features/step_definitions/email_steps.rb:110:in `/^(?:I|they) should see "([^"]*?)" in the email body$/'