I have a gem called "fantastic" with a dummy app inside to test. When running the dummy app, everything works well.
However, when I run the tests, unit tests works fine, but integration tests (Capybara + Poltergeist) fail with the message:
Sprockets::FileNotFound: couldn't find file 'jquery' with type 'application/javascript'.
Checked in these paths:
/fantastic/spec/dummy/app/assets/images, /fantastic/spec/dummy/app/assets/javascripts, /fantastic/spec/dummy/app/assets/stylesheets, /fantastic/app/assets/javascripts, /fantastic/app/assets/stylesheets, /fantastic/vendor/assets/javascripts
Some of my files:
fantastic.gemspec
# ...
s.add_development_dependency "capybara"
s.add_development_dependency "poltergeist"
s.add_development_dependency "jquery-rails"
# ...
spec/dummy/app/assets/javascripts/application.js
//= require jquery // Error is produced in this line
//= require jquery_ujs
//= require fantastic
//= require_tree .
The thing is that when running rails server everything works fine, and jQuery is loaded properly (I tested it in the browser's console).
Any idea of what's happening on tests?
EDIT
I tried creating a custom Capybara.app
:
spec/spec_helper.rb
ENV["RAILS_ENV"] = 'test'
# Require dummy Rails app
require File.expand_path("../../spec/dummy/config/environment", __FILE__)
require 'database_cleaner'
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/poltergeist'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
require 'capybara/dsl'
Capybara.app = Rack::Builder.new do
map "/spec/dummy/" { run Rails.application }
end.to_app
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {js_errors: false})
end
Capybara.javascript_driver = :poltergeist
RSpec.configure do |config|
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
config.infer_spec_type_from_file_location!
end
Given the dummy app is in spec/dummy/
folder.
And this is the error I get when I run the tests
Failure/Error: expect(page).to have_content "Users" expected to find text "Users" in "Not Found: /users". (However, it was found 1 time using a case insensitive search.) # ./spec/features/record_updated_spec.rb:6:in `block (2 levels) in '
Capybara.app
- see how Capybara defines the default - github.com/teamcapybara/capybara/blob/master/lib/capybara/… – Angiosperm