2013-04-26 82 views
3

我收到以下錯誤在我的RSpec代碼未定義的局部變量或方法'渲染」

undefined local variable or method `render' 

這裏是我的代碼:

require 'spec_helper' 
describe "messages/show.html.erb" do 
    it "displays the text attribute of the message" do 
    render 
    rendered.should contain("Hello world!") 
    end 
end 

這是一本書:RSpec的書 以下是我添加到Gemfile中的內容。

group :development , :test do 
    gem "rspec-rails", ">= 2.0.0" 
    gem "webrat", ">= 0.7.2" 
end 

我還沒有添加文件show.html.erb的意見/郵件,但我應該得到另一個錯誤,不是這個

奇怪的是,這個工作我的機器一段時間之前。我刪除的項目,創造了一個又一個,現在,它只是不會編輯的Gemfile

bundle install 
script/rails generate rspec:install 
rake db:migrate 

回答

0

它看起來像你錯過了第一行右引號後工作

我發佈了這些命令你的代碼:

需要「spec_helper

+0

Nopes ....我可能錯過了,而複製粘貼它在這裏...它不缺少源代碼。我將編輯該問題。感謝您指出 – user773327 2013-04-26 04:25:43

0

你可以改變你的測試類似以下內容:

require 'spec_helper' 
describe "messages/show.html.erb" do 
    it "displays the text attribute of the message" do 
    FactoryGirl.create(:message) # or an other test data creator gem 
    visit "/messages/1" 
    page.should have_content("Hello world!") 
    end 
end 
+0

謝謝Mattherick – user773327 2013-04-28 16:56:03

5

對我來說,答案是改變

describe "messages/show.html.erb" do 

describe "messages/show.html.erb", type: :view do 
相關問題