LoginSignup
14
13

More than 5 years have passed since last update.

RSpecとCapybaraでつまづいたので

Last updated at Posted at 2014-07-21

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

Rails Tutorialを見ていて、
http://railstutorial.jp/chapters/static-pages?version=4.0#sec-TDD
を実践中に、Capybaraを使ってRSpecを回そうとしたところ、下記のようなエラーに遭遇。

1) Static pages Home page should have the content 'Sample App'
Failure/Error: visit '/static_pages/home'
ArgumentError: rack-test requires a rack application, but none was given

spec/spec_helper.rbで
require 'capybara/rspec'
としているのに・・・
Tutorialでも動いているのに・・・オカシイ。

Seleniumの導入

下記URLを見て、Capybaraの設定してないと気づく。
http://stackoverflow.com/questions/17666623/running-capybara-without-rack-produces-errors-when-using-url-parameters

spec/spec_helper.rb
Capybara.configure do |config|
  config.run_server = false
  config.default_driver = :selenium
  config.app_host = 'http://0.0.0.0:3000/' # localhost(rails s)
end

これでRSpecが一応動くようになった。
(テスト駆動開発をまだちゃんと理解してないのでアレなんだが、
RSpec回すたびに、ブラウザが表示されてしまうのはどうにかならないかな。。。)
追記:これはseleniumの仕様・・・らしい?

参考までに、
Ruby - 2.1.1
Rails - 4.1.4
RSpec - 3.0.2
Capybara - 2.4.0

14
13
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
13