Nat*_*ong 4 rspec ruby-on-rails capybara
我正在尝试使用Capybara编写Rspec请求规范.似乎一切都正常,除了 Capybara将页面视为空白.
好迹象:
assert_select "h1", :text => "hello world",测试通过.不好的迹象:
page.should have_content('hello world'),它会失败,说Capybara::ElementNotFound: Unable to find xpath "/html"$stdout.puts page.html,除了doctype之外它是空的我的测试看起来像这样:
describe "working with foos" do
it "should have a 'new foo' form" do
get '/foos/new'
assert_select 'h1', text: 'hello world' # passes
page.should have_content('hello world') # fails
$stdout.puts page.html # empty except for a doctype
end
end
Run Code Online (Sandbox Code Playgroud)
这可能有什么问题?
...我正在分享以拯救他人同样的痛苦.
Capybara使用该visit方法设置其页面变量.
visit '/assembly/manage/task_lists/new'
Run Code Online (Sandbox Code Playgroud)
不要get与Capybara一起使用:
get '/assembly/manage/task_lists/new'
Run Code Online (Sandbox Code Playgroud)