【发布时间】:2014-06-22 07:14:37
【问题描述】:
我遇到了一个问题,包括 rspec 的 should have_selector 问题:
这是我的代码:
describe "GET 'home'" do
it "returns http success" do
get 'home'
expect(response).to be_success
end
it "should have the right title" do
should have_selector("title",
:content => "Ruby on Rails Tutorial Sample App | Home")
end
end
我在顶部添加了以下内容:
RSpec.describe PagesController, :type => :controller do
render_views
我的html5有以下内容:
<title>Ruby on Rails Tutorial Sample App | Home</title>
我收到一条错误消息:
失败:
1) PagesController GET 'home' should have the right title
Failure/Error: should have_selector("title",
expected #<PagesController:0x007fceef586a90> to respond to `has_selector?`
# ./spec/controllers/pages_controller_spec.rb:14:in `block (3 levels) in <top (required)>
有人可以帮忙吗?
rspec -v 3.0.2
导轨 4.1.1
提前谢谢你。
【问题讨论】:
-
如果删除
, :type => :controller会怎样?我认为检查页面内容不是控制器规范的责任。
标签: ruby-on-rails ruby-on-rails-4 rspec