测试 Test::Unit + Capybara 怎么跑不起来呢

aisensiy · 2013年02月20日 · 最后由 aisensiy 回复于 2013年02月21日 · 2569 次阅读

按照 github 上的文档做的

# Transactional fixtures do not work with Selenium tests, because Capybara
# uses a separate server thread, which the transactions would be hidden
# from. We hence use DatabaseCleaner to truncate our test database.
DatabaseCleaner.strategy = :truncation

class ActionDispatch::IntegrationTest
  # Make the Capybara DSL available in all integration tests
  include Capybara::DSL

  # Stop ActiveRecord from wrapping tests in transactions
  self.use_transactional_fixtures = false

  teardown do
    DatabaseCleaner.clean       # Truncate the database
    Capybara.reset_sessions!    # Forget the (simulated) browser state
    Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
  end
end
rails g scaffold user email:string username:string
rake db:migrate
class UserTest < ActionDispatch::IntegrationTest
  # setup do
  #   Capybara.javascript_driver = :webkit
  #   Capybara.current_driver = Capybara.javascript_driver
  # end

  test "should show username and email" do
    get "/users/new"

    fill_in "email", with: "[email protected]"
    fill_in "Username", with: "aisensiy"
    click_button "Create User"
    assert_equal path, "/users"
  end
end

然后就报错

ArgumentError: rack-test requires a rack application, but none was given

何故呢?

喂喂喂,来个人吗~

是不是没有启动 rails,猜的。

#2 楼 @chenge 猜错了,不是。是忘记 require 什么东西了,我下班回去看看 o_o,不过最终还是换回去用 rspec 了,不然功能太少了。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号