Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails+Capybara+poltergeist ArgumentError: rack-test requires a rack application, but none was given

I just started playing with Capycabra+poltergeist and after execution of my Capy test rspec ./spec/features/test_spec.rb I got the following error:

 Failure/Error: visit '/item/new'
 ArgumentError: rack-test requires a rack application, but none was given

Also I have a few standard rspec tests and whenever I try to excute all tests, rspec tests are passed successfully, but only the capy test fails with weird error

ActionView::Template::Error: couldn't find file 'jquery.min' (in app/assets/javascripts/application.js:13)

Which leads me to the confusion.

I have viewed several similar threads on stackoverflow in some cases the error is about missing config.include Capybara::DSL in the spec_helper.rb or incorrect location of tests. I made appropriate changes, but it doesn't work, the error is still the same.

My spec_helper.rb file

require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'

Capybara.javascript_driver = :poltergeist

RSpec.configure do |config|
  config.include Capybara::DSL
end

Full Version of spec_helper: http://pastebin.com/qkANfu39

Test file:

#spec/features/test_spec.rb

require 'spec_helper'
describe 'accessibility of webpage' do
  it 'should access web page' do
    visit '/item/new'
    expect(page).to have_content("Something")
  end

end

Thoughts?

like image 478
ProblemSlover Avatar asked Sep 14 '14 07:09

ProblemSlover


1 Answers

  • Update

This workaround is no longer needed according to the report(see in comments), but I haven't checked it yet.


Found workaround..

I had to specify the app host url and a default driver..

#spec/spec_helper.rb

require 'capybara'
require 'database_cleaner'
require 'capybara/dsl'
require 'capybara/poltergeist'


Capybara.configure do |c|
  c.javascript_driver = :poltergeist
  c.default_driver = :poltergeist
  c.app_host = "http://localhost:3000"
end

Update 1

In order to fix error:

 Failure/Error: visit '/item/new'
 ArgumentError: rack-test requires a rack application, but none was given

I included rails_helper file into my Capy test. the final version of test:

require 'rails_helper'
require 'spec_helper'

describe 'accessibility of webpage' do
  it 'should access web page' do
    visit '/item/new'
    expect(page).to have_content I18n.t("form_input.item.item_s")
  end
end

After that for some reason specified app_host url no longer needed and it can be removed from the spec_helper helper file. The final version:

Capybara.configure do |c|
  c.javascript_driver = :poltergeist
  c.default_driver = :poltergeist
end

The full version of spec_helper.rb http://pastebin.com/DKgF1uQA

Error

ActionView::Template::Error: couldn't find file 'jquery.min' (in app/assets/javascripts/application.js:13)

Occurred because gem 'jquery-rails' wasn't available in the test scope in my Gemfile, It was available only in :development & :production environment. I moved the gem 'jquery-rails' out to the global scope. The full version of a Gemfile: http://pastebin.com/dt4KrHGG

like image 171
ProblemSlover Avatar answered Nov 03 '22 12:11

ProblemSlover