2013-04-26 50 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 
相关问题