我对RSpec和Capybara相对较新,我正在制作一个基本的漫画书数据库应用程序来试验它们。由于某种原因,测试失败了(虽然当我手动创建漫画书时,我看到了确认文本)。
以下是测试:
require 'spec_helper.rb'
feature 'Creating Comic Books' do
scenario 'can create a comic book' do
visit '/'
click_link 'New Comic book'
fill_in 'Title', with: 'Batman'
fill_in 'Publisher', with: 'DC'
fill_in 'Issue number', with: 32
fill_in 'Summary', with: 'What a nice comic book'
expect(page).to have_content("Comic book was successfully created.")
end
end
这是失败的消息以及回溯:
1) Creating Comic Books can create a comic book
Failure/Error: expect(page).to have_content("Comic book was successfully created.")
expected to find text "Comic book was successfully created." in "Toggle navigation Project name Home About Contact New Comic Book Title Publisher Issue number Summary What a nice comic book Back"
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-expectations-3.1.2/lib/rspec/expectations/fail_with.rb:30:in `fail_with'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-expectations-3.1.2/lib/rspec/expectations/handler.rb:37:in `handle_failure'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-expectations-3.1.2/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-expectations-3.1.2/lib/rspec/expectations/expectation_target.rb:54:in `to'
# ./spec/features/creating_comics_spec.rb:14:in `block (2 levels) in <top (required)>'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example.rb:152:in `instance_exec'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example.rb:152:in `block in run'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example.rb:222:in `call'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example.rb:222:in `call'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-rails-3.1.0/lib/rspec/rails/adapters.rb:72:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example.rb:322:in `instance_exec'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example.rb:322:in `instance_exec'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/hooks.rb:380:in `execute_with'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/hooks.rb:446:in `block (2 levels) in run'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example.rb:222:in `call'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example.rb:222:in `call'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/hooks.rb:447:in `run'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/hooks.rb:500:in `run'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example.rb:331:in `with_around_example_hooks'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example.rb:149:in `run'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:490:in `block in run_examples'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:486:in `map'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:486:in `run_examples'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:453:in `run'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:111:in `block (2 levels) in run_specs'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:111:in `map'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:111:in `block in run_specs'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/reporter.rb:53:in `report'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:107:in `run_specs'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:85:in `run'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
# /Users/esteban/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
# /Users/esteban/.rbenv/versions/2.1.5/bin/rspec:23:in `load'
# /Users/esteban/.rbenv/versions/2.1.5/bin/rspec:23:in `<main>'
我尝试过使用capybara-webkit和selenium,无论如何我都会收到错误。
答案 0 :(得分:1)
在测试中,您没有点击按钮提交表单。
填写表格后可能会出现类似click_button "Create Comic Book"
的内容。