I have a Rails 5.0.1 app that is NOT backed by any database. When attempting to write a controller test I get a ActiveRecord::ConnectionNotEstablished exception even though I have explicitly configured my spec/rails_helper.rb not to use ActiveRecord and removed references to active_record in config/application.rb. RSpec is trying to run such test within a transaction which requires a database connection to be established. I am attaching the stack trace for reference and I used this Github issue to setup RSpec without ActiveRecord rspec-rails for a rails project without db connection.
Failures:
1) ApplicationController the truth false not equal true
Failure/Error: raise ConnectionNotEstablished, "No connection pool with id #{spec_name} found." unless pool
ActiveRecord::ConnectionNotEstablished:
No connection pool with id primary found.
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `retrieve_connection'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_handling.rb:128:in `retrieve_connection'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_handling.rb:91:in `connection'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/fixtures.rb:516:in `create_fixtures'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/fixtures.rb:1015:in `load_fixtures'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/fixtures.rb:988:in `setup_fixtures'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/fixtures.rb:852:in `before_setup'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-rails-3.6.1/lib/rspec/rails/adapters.rb:126:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:375:in `execute_with'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:342:in `call'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:464:in `run'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:457:in `with_around_example_hooks'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:500:in `with_around_and_singleton_context_hooks'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:251:in `run'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:627:in `block in run_examples'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:623:in `map'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:623:in `run_examples'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:589:in `run'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:590:in `block in run'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:590:in `map'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:590:in `run'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `block (3 levels) in run_specs'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `map'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `block (2 levels) in run_specs'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1894:in `with_suite_hooks'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:113:in `block in run_specs'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/reporter.rb:79:in `report'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:112:in `run_specs'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:87:in `run'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:71:in `run'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:45:in `invoke'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/exe/rspec:4:in `<top (required)>'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/bin/rspec:23:in `load'
# /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/bin/rspec:23:in `<top (required)>'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `load'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:24:in `run'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:304:in `exec'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:27:in `block in <top (required)>'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
# /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'
# /vagrant/easypost_admin/vendor/bundle/bundle:23:in `load'
# /vagrant/easypost_admin/vendor/bundle/bundle:23:in `<main>'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
Finished in 0.0058 seconds (files took 2.29 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/controllers/application_controller_spec.rb:15 # ApplicationController the truth false not equal true
UPDATE
rails_help.rb
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
# Checks for pending migration and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
# ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
end
spec_helper.rb
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
config.shared_context_metadata_behavior = :apply_to_host_groups
end
I had the very same issue with a rails 5.2.0.alpha app without a database
configured. So I had a look at the rspec-rails code, and figured out this
line which causes all the trouble:
rspec-rails/lib/rspec/rails/fixture_support.rb:
if defined?(ActiveRecord::TestFixtures)
It checks for a loaded ActiveRecord constant, which actually was loaded. I
also had require 'active_record/railtie' commented out from
config/application.rb. Then I figured out who required the ActiveStorage gem
(bundle.lock). In my case it was ActiveStorage.
I just use the ActiveStorage functionality without a database, so I had to
remove the ActiveRecord constant on my spec/rails_helper.rb:
# frozen_string_literal: true
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Remove the ActiveRecord constant, because it is autloaded by
# ActiveStorage and not needed for our application. The presence
# of the ActiveRecord constant causes rspec-rails to include
# extra fixture support, which results in:
#
# ActiveRecord::ConnectionNotEstablished:
# No connection pool with 'primary' found.
#
Object.send(:remove_const, :ActiveRecord)
Mind the order, it needs to be placed after
require File.expand_path('../../config/environment', __FILE__)
and before
require 'rspec/rails'
This solution just modify the test environment.
UPDATE
I create an issue on rspec-rails which targets the creation of a global rspec configuration to turn off ActiveRecord handling.
A fix for this has just been merged into rspec-rails, and will supposedly be released along with RSpec Rails 4.0 sometimes next week.
What you have to set the following in your spec/rails_helper.rb:
config.use_active_record = false
Again, the problem is that if you didn't configure/use the database connection, but ActiveRecord is still present (due to Bundler loading it or some other reasons).
Related
I am following this guide on building a restful json api https://www.digitalocean.com/community/tutorials/build-a-restful-json-api-with-rails-5-part-one#project-setup
I have followed every single step up until the models area ( there are 5 areas, Prerequisites, Project Setup,Models,Controllers,Conclusion) where the testing begins ...
however when I am trying to run any tests all my examples (5 of them) are all failed.
C:\Users\nion1\todos-api>bundle exec rspec
FFFFF
Failures:
1) Item
Failure/Error: example.run
`name` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
# ./spec/rails_helper.rb:53:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:52:in `block (2 levels) in <top (required)>'
2) Item
Failure/Error: example.run
`name` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
# ./spec/rails_helper.rb:53:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:52:in `block (2 levels) in <top (required)>'
3) Todo
Failure/Error: example.run
`name` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
# ./spec/rails_helper.rb:53:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:52:in `block (2 levels) in <top (required)>'
4) Todo
Failure/Error: example.run
`name` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
# ./spec/rails_helper.rb:53:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:52:in `block (2 levels) in <top (required)>'
5) Todo
Failure/Error: example.run
`name` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
# ./spec/rails_helper.rb:53:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:52:in `block (2 levels) in <top (required)>'
Finished in 0.10099 seconds (files took 1.52 seconds to load)
5 examples, 5 failures
Failed examples:
rspec ./spec/models/item_spec.rb:8 # Item
rspec ./spec/models/item_spec.rb:11 # Item
rspec ./spec/models/todo_spec.rb:8 # Todo
rspec ./spec/models/todo_spec.rb:11 # Todo
rspec ./spec/models/todo_spec.rb:12 # Todo
I am really trying to understand a way to fix this error but i just cant figure it out..
Any ideas ? Anything would be really helpful
my files :
rails_helper.rb:
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
puts e.to_s.strip
exit 1
end
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.include FactoryBot::Syntax::Methods
# start by truncating all the tables but then use the faster transaction strategy the rest of the time.
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.strategy = :transaction
end
# start the transaction strategy as examples are run
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
end
spec/models/todo_spec.rb:
require 'rails_helper'
# Test suite for the Todo model
RSpec.describe Todo, type: :model do
# Association test
# ensure Todo model has a 1:m relationship with the Item model
it { should have_many(:items).dependent(:destroy) }
# Validation tests
# ensure columns title and created_by are present before saving
it { should validate_presence_of(:title) }
it { should validate_presence_of(:created_by) }
end
item_spec.rb:
require 'rails_helper'
# Test suite for the Item model
RSpec.describe Item, type: :model do
# Association test
# ensure an item record belongs to a single todo record
it { should belong_to(:todo) }
# Validation test
# ensure column name is present before saving
it { should validate_presence_of(:name) }
end
Upgrading shoulda-matchers and rspec-rails to the latest versions worked for me
I tried that tutorial as well. I am working with Ruby 2.7.2 and Rails 6.1.3, I need to update the gem 'rspec-rails', '~> 4.0' in order to fix that issue.
Okay, so the problem seemed to be the version of ruby and rails.
For some reason ruby 2.7.2 and Rails 6.0.3.4 worked for my problem.
Of course GemFile needs to be changed
In the gem file if rspec's version is < 4 try to replace it with the latest version or with the below line.
gem 'rspec-rails', '~> 4.0'
It worked for me
I solved, in my case function like was say here updating gem rspec-rails like below:
gem 'rspec-rails', ~>4.0 gem 'shoulda-matchers', '~> 5.0'
For rails 6.1.4.1 is fine
Background:
My testing suite did not handle any JS functionality until recently. I started out
only on my machine with a selenium-webdriver javascript driver and firefox 47.0.1
with no issues. I then migrated over to poltergeist supporting PhantomJS as
my javascript driver. I had to make a few changes to some broken tests, but have
very much enjoyed the changeover and am 'sold' on PhantomJS/poltergeist.
Expected Behavior:
I anticipated the tests to pass on my Gitlab-ci just as they had on my machine
(hey, we can dream), with maybe a few configuration tweaks needed.
Versions:
Ruby - 2.3.1
Rails - 5.0.0.1
poltergeist - 1.12.0
rspec - 3.5.0
rspec-rails - 3.5.1
capybara - 2.11.0
cliver - 0.3.2
factory_girl_rails - 4.7.0
phantomjs - 2.1.1 (on both my machine and CI server)
Capybara Config:
require 'capybara/rspec'
require 'capybara/poltergeist'
Capybara.default_driver = :rack_test
Capybara.register_driver :poltergeist do |app|
options = {
:js_errors => false,
:timeout => 360,
:phantomjs_options => ['--load-images=no', '--ignore-ssl-errors=yes', '--disk-cache=false']
}
Capybara::Poltergeist::Driver.new(app, options)
end
Capybara.javascript_driver = :poltergeist
DatabaseCleaner Config
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = Capybara.current_driver == :rack_test ? :transaction : :truncation
DatabaseCleaner.clean
DatabaseCleaner.start
end
config.after(:each) do |example|
puts 'RAM USAGE: ' + `pmap #{Process.pid} | tail -1`[10,40].strip
if defined?(page)
Capybara.reset_sessions!
page.driver.restart
end
DatabaseCleaner.clean
end
Actual Behavior/Backtraces:
1. Failing Tests, PhantomJS Crash
To get a full stacktrace on my failing tests before I ate up all of my memory I
used the rspec --fail-fast option to kick back results for me on my first error.
This is what I returned:
ArgumentError:
The detector #<struct Cliver::Detector command_arg=nil, version_pattern=nil> failed to detect theversion of the executable at '/usr/bin/phantomjs'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:191:in `detect_version'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:87:in `block in installed_versions'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:214:in `block in find_executables'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:208:in `map'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:208:in `find_executables'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:86:in `each'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:86:in `installed_versions'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:108:in `each'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:108:in `detect!'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:97:in `detect'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/cliver-0.3.2/lib/cliver.rb:35:in `detect'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/poltergeist-1.12.0/lib/capybara/poltergeist/client.rb:47:in `initialize'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/poltergeist-1.12.0/lib/capybara/poltergeist/client.rb:14:in `new'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/poltergeist-1.12.0/lib/capybara/poltergeist/client.rb:14:in `start'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/poltergeist-1.12.0/lib/capybara/poltergeist/driver.rb:44:in `client'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/poltergeist-1.12.0/lib/capybara/poltergeist/driver.rb:25:in `browser'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/poltergeist-1.12.0/lib/capybara/poltergeist/driver.rb:183:in `reset!'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/capybara-2.11.0/lib/capybara/session.rb:110:in `reset!'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/capybara-2.11.0/lib/capybara.rb:335:in `block in reset_sessions!'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/capybara-2.11.0/lib/capybara.rb:335:in `reverse_each'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/capybara-2.11.0/lib/capybara.rb:335:in `reset_sessions!'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/capybara-2.11.0/lib/capybara/rspec.rb:21:in `block (2 levels) in <top (required)>'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:357:in `run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:507:in `block in run_owned_hooks_for'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:506:in `each'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:506:in `run_owned_hooks_for'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:593:in `block in run_example_hooks_for'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:592:in `each'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:592:in `run_example_hooks_for'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:463:in `run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:503:in `run_after_example'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:269:in `block in run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `block in with_around_and_singleton_context_hooks'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `block in with_around_example_hooks'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `block in run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:604:in `block in run_around_example_hooks_for'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-rails-3.5.1/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:375:in `execute_with'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:98:in `block in run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:88:in `loop'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:88:in `run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-retry-0.4.5/lib/rspec_ext/rspec_ext.rb:12:in `run_with_retry'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:22:in `block (2 levels) in setup'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:375:in `execute_with'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `with_around_example_hooks'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `with_around_and_singleton_context_hooks'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:251:in `run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:627:in `block in run_examples'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `map'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `run_examples'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:589:in `run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (3 levels) in run_specs'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `map'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (2 levels) in run_specs'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1835:in `with_suite_hooks'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/reporter.rb:77:in `report'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:111:in `run_specs'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:87:in `run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/bin/rspec:23:in `load'
# /home/gitlab-runner/builds/wow_such_build/0/schwad_project/redacted/vendor/bundle/ruby/2.3.0/bin/rspec:23:in `<main>'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
Also, in my gitlab-ci.yml file, if I call phantomjs --version in before_script I receive:
QXcbConnection: Could not connect to display
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
Any help on this would be much appreciated.
2. Memory Blowup SOLVED: see update 2
The tests would eat up the memory, even after we increased memory capacity on the
servers, and crash the test suite before it would finish. To track memory usage
in my RSpec configuration after each test I ran:
puts 'enter code hereRAM USAGE: ' +pmap #{Process.pid} | tail -1[10,40].strip
The memory would be minimally affected under the model tests, but grow rapidly
under the integration tests. Like so:
Model Test-
RAM USAGE: 567800K
Model Test-
RAM USAGE: 567800K
Model Test-
RAM USAGE: 567800K
Model Test-
RAM USAGE: 568220K
Model Test-
RAM USAGE: 568220K
Model Test-
RAM USAGE: 568360K
Model Test-
RAM USAGE: 568500K
Model Test-
RAM USAGE: 568652K
Model Test-
RAM USAGE: 568788K
First Feature Test:
RAM USAGE: 1100628K
And blowing up from there.
To handle this I have made sure to use appropriate DatabaseCleaner strategies,
also cycled through trying tools such as Capybara.reset_sessions!,
Capybara.current_session.driver.quit, page.driver.quit, page.driver.restart
with no real joy.
UPDATE:
5:06 PM UTC, 15/12/16
1. Crashes
Gitlab support has suggested investigating whether our packages and dependencies are resulting in a non-headless situation with PhantomJS. We are investigating this now.
2. Memory
I've run a memory tracker against a few different iterations here, and it seems to be simply enabling our js: true feature tests with a javascript driver to be eating up the memory, going from 1G for about 1,750 tests to surpassing our 4G limit on 1,800-1,850 tests. This seems to occur, I believe, with either selenium-webdriver OR poltergeist as the js driver.
UPDATE 2:
11:45 PM UTC, 16/12/16
1. Crashing
Still awaiting proper installation of packages on our server. Will update and award answer if this is the issue.
2. Memory
On the branch where we were migrating over to the Javascript-driver enabled batch of tests, part of the configuration to speed up the tests implemented a DeferredGarbageCollector which had settings that gobbled up the memory. PhantomJS and Poltergeist are not leaking. SOLVED
http://github.com/ariya/phantomjs/issues/14240 is the cause of your PhantomJS crashing - The version of PhantomJS shipped by Ubuntu requires X to run.
Download the official release build and use that to cure your crashing issue.
You may want to add the memory issue as a separate question.
I have been trying to use RSpec with Rails 4 but came across this error that I can't get rid of.
However, when I run test on single *.rb files it works without any errors. I use guard and have tried to run rspec in single mode but received the same error.
13:46:26 - INFO - Running: spec
/Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:214:in `initialize!': Application has been already initialized. (RuntimeError)
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/xxx/Documents/Mitt_bolag/Minnesota/beställningssite/order_site/config/environment.rb:5:in `<top (required)>'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /Users/xxx/Documents/Mitt_bolag/Minnesota/beställningssite/order_site/spec/spec_helper.rb:3:in `<top (required)>'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /Users/xxx/Documents/Mitt_bolag/Minnesota/beställningssite/order_site/spec/requests/products_spec.rb:1:in `<top (required)>'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `block in load'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `each'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:22:in `run'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in `run'
from /Users/xxx/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'
This is my spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# 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
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.include Devise::TestHelpers, :type => :controller
end
class ActionController::TestCase
include Devise::TestHelpers
end
I ran into this problem while upgrading a Rails 4.2 and Ruby 2.2 app to Rails 4.2 and Rails 2.6. Apparently, ActionController::TestResponse is reused and therefore initialized multiple times. You can add a workaround reading this thread, or simply create spec/support/action_controller_workaround.rb:
if RUBY_VERSION>='2.6.0'
if Rails.version < '5'
class ActionController::TestResponse < ActionDispatch::TestResponse
def recycle!
# hack to avoid MonitorMixin double-initialize error:
#mon_mutex_owner_object_id = nil
#mon_mutex = nil
initialize
end
end
else
puts "Monkeypatch for ActionController::TestResponse no longer needed"
end
end
Try setting your spec_helper to this:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec' # NOTE: I DON'T have this but you do...
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
end
I don't know if you've already got the solution, but here I go anyway:
I'm facing the same problem since yesterday. I've found that running a
single spec by time or removing the 'require "spec_helper" from all specs but one,
it would work.
And a few minutes ago, I've found that the problem was the ruby version.
If you upgrade your ruby-2.0.0-p0 to ruby-2.0.0-p247, then the problem goes away!
I hope I've been helpful.
I'm trying to run tests with Devise and Rspec and have been unsuccessful thus far - any help would be greatly appreciated.
rake spec:requests --trace
gives me this error
`/Users/carl/.rvm/rubies/ruby-1.9.2-head/bin/ruby -S rspec ./spec/requests/users_spec.rb
/Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:503:in ‘load_missing_constant': Expected /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/devise-2.1.2/app/controllers/devise_controller.rb to define DeviseController (LoadError)
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in ‘block in const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/devise-2.1.2/app/controllers/devise/sessions_controller.rb:1:in ‘<top (required)>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘block in require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in ‘load_dependency'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in ‘require_or_load'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:502:in ‘load_missing_constant'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in ‘block in const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘const_missing'
from /Users/carl/rails_projects/my_rails_app_name/app/controllers/application_controller.rb:14:in ‘<class:ApplicationController>'
from /Users/carl/rails_projects/my_rails_app_name/app/controllers/application_controller.rb:1:in ‘<top (required)>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘block in require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in ‘load_dependency'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in ‘require_or_load'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:502:in ‘load_missing_constant'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in ‘block in const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/inflector/methods.rb:229:in ‘block in constantize'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/inflector/methods.rb:228:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/inflector/methods.rb:228:in ‘constantize'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/core_ext/string/inflections.rb:54:in ‘constantize'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/devise-2.1.2/app/controllers/devise_controller.rb:2:in ‘<top (required)>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘block in require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in ‘load_dependency'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in ‘require_or_load'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:502:in ‘load_missing_constant'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in ‘block in const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/devise-2.1.2/app/controllers/devise/confirmations_controller.rb:1:in ‘<top (required)>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘block in require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in ‘load_dependency'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in ‘require_or_load'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:313:in ‘depend_on'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:225:in ‘require_dependency'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:439:in ‘block (2 levels) in eager_load!'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:438:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:438:in ‘block in eager_load!'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:436:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:436:in ‘eager_load!'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/application/railties.rb:8:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/application/railties.rb:8:in ‘all'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:434:in ‘eager_load!'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/application/finisher.rb:53:in ‘block in <module:Finisher>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/initializable.rb:30:in ‘instance_exec'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/initializable.rb:30:in ‘run'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/initializable.rb:55:in ‘block in run_initializers'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/initializable.rb:54:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/initializable.rb:54:in ‘run_initializers'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/application.rb:136:in ‘initialize!'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in ‘method_missing'
from /Users/carl/rails_projects/my_rails_app_name/config/environment.rb:5:in ‘<top (required)>'
from /Users/carl/rails_projects/my_rails_app_name/spec/spec_helper.rb:3:in ‘require'
from /Users/carl/rails_projects/my_rails_app_name/spec/spec_helper.rb:3:in ‘<top (required)>'
from /Users/carl/rails_projects/my_rails_app_name/spec/requests/users_spec.rb:1:in ‘require'
from /Users/carl/rails_projects/my_rails_app_name/spec/requests/users_spec.rb:1:in ‘<top (required)>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in ‘load'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in ‘block in load_spec_files'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in ‘map'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in ‘load_spec_files'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in ‘run'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in ‘run'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in ‘block in autorun'
rake aborted!
/Users/carl/.rvm/rubies/ruby-1.9.2-head/bin/ruby -S rspec ./spec/requests/users_spec.rb failed
/Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/rake_task.rb:137:in ‘block (2 levels) in initialize'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:60:in ‘verbose'
/Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/rake_task.rb:127:in ‘block in initialize'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in ‘call'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in ‘block in execute'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in ‘each'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in ‘execute'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in ‘block in invoke_with_call_chain'
/Users/carl/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/monitor.rb:201:in ‘mon_synchronize'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in ‘invoke_with_call_chain'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in ‘invoke'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in ‘invoke_task'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in ‘block (2 levels) in top_level'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in ‘each'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in ‘block in top_level'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in ‘standard_exception_handling'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in ‘top_level'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in ‘block in run'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in ‘standard_exception_handling'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in ‘run'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/bin/rake:33:in ‘<top (required)>'
/Users/carl/.rvm/gems/ruby-1.9.2-head/bin/rake:19:in ‘load'
/Users/carl/.rvm/gems/ruby-1.9.2-head/bin/rake:19:in ‘<main>'
`
Gemfile for :development, :test
gem 'sqlite3'
gem 'rspec-rails'
gem 'capybara'
spec/requests/user_spec.rb
> `require 'spec_helper'
>
> describe "Users" do
> describe "GET /" do
> it "goes to homepage" do
> visit '/'
> response.status.should be(200)
> end
> end
> end`
spec/spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
#require 'capybara/rails'
# Note: To create integration test: $rails g integration_test blah --integration-tool=rspec
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# Include devise in Rspec tests
config.include Devise::TestHelpers, :type => :controller
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# 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
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end
I don't know exactly what is going wrong, but a quick search for LoadError and the "Expected ... to define" pattern brought up a few relevant discussions.
Expected ... to Define
Rails 3.1 — 'load_missing_contant': Expected ... to define ... (LoadError)
Expected x.rb to define X (LoadError)
Rails: Why does RSpec crash on my overridden Devise controller request spec?
From the first link:
The error message is misleading. Expected foo.rb to define Foo usually
just means that something bad happened when loading foo.rb (syntax
errors, missing constant etc...). You can usually get a better error
message by just typing Foo into script/console
The error is coming directly from Devise, so perhaps there is some naming conflict in your controllers with the devise controllers? I don't use devise so I don't really know much about how it works. Although I doubt that it's the problem, have a look at the file /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/devise-2.1.2/app/controllers/devise_controller.rb and make sure it's not corrupted. You might try to reinstall the gem in rvm.
A friend helped me figure this one out. In my application controller I was overriding Devise with the below code. Commenting this out allowed rake spec:requests to pass successfully.
# ===============================================
# == Commented this out to make rspec tests work
# ===============================================
# Override Devise create session controller
# Devise::SessionsController.class_eval do
# def create
# resource = warden.authenticate!(auth_options)
# set_flash_message(:notice, :signed_in) if is_navigational_format?
# sign_in(resource_name, resource)
# #sign_in_path = after_sign_in_path_for(resource)
# end
# end
Thank you again for your time and help!
I have a rails app with Cucumber 1.0.0 and cucumber-rails 1.0.2. These tests ran fine last night. Today I just altered some step definitions and tried to run the tests and got the error below. I haven't changed anything in the cucumber support files. Any ideas?
grouperty $ cucumber
Using the default profile...
no such file to load -- /Users/davidtuite/wd/grouperty/features/config/environment(LoadError)
/Users/davidtuite/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/davidtuite/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/davidtuite/wd/grouperty/features/support/env.rb:12:in `block in <top (required)>'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/spork-0.9.0.rc9/lib/spork.rb:24:in `prefork'
/Users/davidtuite/wd/grouperty/features/support/env.rb:10:in `<top (required)>'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/lib/cucumber/rb_support/rb_language.rb:143:in `load'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/lib/cucumber/rb_support/rb_language.rb:143:in `load_code_file'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/lib/cucumber/runtime/support_code.rb:176:in `load_file'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/lib/cucumber/runtime/support_code.rb:78:in `block in load_files!'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/lib/cucumber/runtime/support_code.rb:77:in `each'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/lib/cucumber/runtime/support_code.rb:77:in `load_files!'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/lib/cucumber/runtime.rb:137:in `load_step_definitions'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/lib/cucumber/runtime.rb:39:in `run!'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/lib/cucumber/cli/main.rb:43:in `execute!'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/lib/cucumber/cli/main.rb:20:in `execute'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/gems/cucumber-1.0.0/bin/cucumber:14:in `<top (required)>'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/bin/cucumber:19:in `load'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head#grouperty/bin/cucumber:19:in `'
Here is the content of /features/support/env.rb. Note that most of it was generated by the spork gem (v0.9.0.rc9).
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'cucumber/rails'
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
# order to ease the transition to Capybara we set the default here. If you'd
# prefer to use XPath just remove this line and adjust any selectors in your
# steps to use the XPath syntax.
Capybara.default_selector = :css
end
Spork.each_run do
# By default, any exception happening in your Rails application will bubble up
# to Cucumber so that your scenario will fail. This is a different from how
# your application behaves in the production environment, where an error page will
# be rendered instead.
#
# Sometimes we want to override this default behaviour and allow Rails to rescue
# exceptions and display an error page (just like when the app is running in production).
# Typical scenarios where you want to do this is when you test your error pages.
# There are two ways to allow Rails to rescue exceptions:
#
# 1) Tag your scenario (or feature) with #allow-rescue
#
# 2) Set the value below to true. Beware that doing this globally is not
# recommended as it will mask a lot of errors for you!
#
ActionController::Base.allow_rescue = false
# Remove/comment out the lines below if your app doesn't have a database.
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
# See the DatabaseCleaner documentation for details. Example:
#
# Before('#no-txn,#selenium,#culerity,#celerity,#javascript') do
# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
# end
#
# Before('~#no-txn', '~#selenium', '~#culerity', '~#celerity', '~#javascript') do
# DatabaseCleaner.strategy = :transaction
# end
#
end
this line
require File.expand_path("../../config/environment", __FILE__)
requires
/Users/davidtuite/wd/grouperty/features/config/environment
which is not present there this causes error