这是我的测试:
require "rspec"
describe HomeController do
render_views
it "should renders the home" do
get :home
response.should render_template("home")
response.should include_text("Simulate Circuits Online")
end
end
但是,我得到了:
1) HomeController should renders the home
Failure/Error: response.should include_text("Some text to be test ..")
NoMethodError:
undefined method `include_text' for #<RSpec::Core::ExampleGroup::Nested_1:0xd429a0c>
# ./spec/controllers/home_controller_spec.rb:9:in `block (2 levels) in <top (required)>'
# (eval):6:in `block in fork'
# (eval):6:in `fork'
# (eval):6:in `fork'
那么,测试呈现的文本的正确方法是什么?
编辑
如果我尝试 response.should have_content("My text ..")
我明白了
1) HomeController should renders the home
Failure/Error: response.should have_content("My text ..")
expected there to be text "My text .." in "#"
# ./spec/controllers/home_controller_spec.rb:9:in `block (2 levels) in <top (required)>'