0

我是 Rails 5.1 并使用默认系统测试进行测试

我在 RetreatTest 类中有以下代码:

test "Create a new Retreat" do
  visit retreats_url

  click_on 'Create a new Retreat'

  fill_in "Title", with: "Retreat Title"
  fill_in "Tagline", with: "Retreat tagline"
  select('Individual', from: 'Type')

  fill_in "Description", with: "Retreat Description"
  attach_file('Image', Rails.root.join('test', 'images', 'test-1.jpg'))

  click_on "Submit"

  assert_text("Retreat was successfully saved.")
end

我不明白为什么我不断收到此错误:

Error:
RetreatsTest#test_Create_a_new_Retreat:
TypeError: exception class/object expected
test/system/retreats_test.rb:36:in `block in <class:RetreatsTest>'

如果我写assert find('.alert').has_content?('Retreat was successfully saved.')而不是assert_text我所有的测试都通过了。

有人可以帮我弄这个吗?

编辑1:在使用回溯选项运行测试时,我得到以下信息:

Error:
  RetreatsTest#test_Create_a_new_Retreat:
  TypeError: exception class/object expected
  /Users/dhaliman/.rvm/gems/ruby-2.3.1/gems/capybara-2.14.2/lib/capybara/minitest.rb:52:in `raise'
  /Users/dhaliman/.rvm/gems/ruby-2.3.1/gems/capybara-2.14.2/lib/capybara/minitest.rb:52:in `rescue in assert_text'
  /Users/dhaliman/.rvm/gems/ruby-2.3.1/gems/capybara-2.14.2/lib/capybara/minitest.rb:48:in `assert_text'
  /Users/dhaliman/Code/Workspace AVR WebApp/avr/test/system/retreats_test.rb:36:in `block in <class:RetreatsTest>'
4

1 回答 1

1

升级到最新的 Capybara (2.14.4) 您当前使用的是 2.14.2,并且在 2.14.3 中有一个针对小型测试断言的修复程序,它应该修复不正确的错误,并让它返回正确的错误(它可以' t 找到文本)

于 2017-07-25T18:58:41.780 回答