hope somebody can help me with this. I did search but haven't found any working solution.
I've started writing test for an app. My integration tests run fine, but then I decided that since I'm not that much of TDD driven and since I don't have that much time right now to extensively test all layers of the app that I should use instead of integration tests system tests, because they allow me to test the full flow as if in a browser.
Rails 5.1.2
Gemfile
(tried different variations, just capybara, then with combinations of both the other two)
gem 'minitest-rails'
gem 'minitest-rails-capybara'
gem 'capybara'
test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
EMPTY_NEW_USER = {
email: '',
first_name: '',
last_name: '',
username: '',
password: ''
}
EXISTING_USER = {
email: '****',
first_name: 'John',
last_name: 'Doe',
username: '',
password: 'testingpass',
password_confirmation: 'testingpass'
}
# Add more helper methods to be used by all tests here...
end
application_system_test_case.rb
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end
register_logins.rb
require "application_system_test_case"
class RegisterLoginsTest < ApplicationSystemTestCase
test 'full login flow' do
visit root_url
assert_response :success
find('.email_link').click
end
end
error when running
rake test:system
LoadError: cannot load such file -- capybara/minitest
/Users/mnussbaumer/code/dvouch/test/application_system_test_case.rb:3:in `<top (required)>'
/Users/mnussbaumer/code/dvouch/test/system/register_logins_test.rb:1:in `<top (required)>'
Tasks: TOP => test:system
(See full trace by running task with --trace)
The full trace adds this:
LoadError: cannot load such file -- capybara/minitest
/Users/mnussbaumer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/Users/mnussbaumer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `block in require'
/Users/mnussbaumer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:258:in `load_dependency'
/Users/mnussbaumer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/Users/mnussbaumer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.1.2/lib/action_dispatch/system_test_case.rb:2:in `<top (required)>'
/Users/mnussbaumer/code/dvouch/test/application_system_test_case.rb:3:in `<top (required)>'
and goes on on active_support dependencies.
What I have tried:
Adding one, two and three to test_helper.rb:
require "capybara/rails"
require "minitest/rails"
require "minitest/rails/capybara"
I tried with gems:
group :development, :test do
gem 'minitest-rails'
gem 'minitest-capybara'
gem 'capybara'
end
then with 'minitest-rails-capybara'
Thanks
The file capybara/minitest was added to Capybara in version 2.13.0, which is the minimum version Rails requires for its system tests since Rails 5.1.0. Upgrade to the latest version of Capybara (2.14.4) and there should be no need for the minitest-capybara or minitest-rails gems. You will need to also add the 'selenium-webdriver' gem to your test group.
Additionally the assert_response :success line is't valid in Capybara tests because the HTTP response code from the browser Capybara is using isn't generally available.
Related
First i read other posts of users with similiar problems, but couldnt come along where my mistake is. I wanted to start a test with RSpec on the following file:
dashboard_view_spec.rb:
require 'rails_helper'
RSpec.feature "Dashboard", type: :feature do
before(:each) do
#current_user = User.create!(email: "xyz#xyz.com", password: "xyz123")
sign_in_with(#current_user.email,#current_user.password)
end
#NAV BAR RSPEC TEST
scenario 'Home bar nav link present' do
visit "/"
expect(page).to have_text('Home')
end
scenario 'How it work nav bar link present' do
visit "/"
expect(page).to have_text('How it work')
end
scenario 'Support nav bar link present' do
visit "/"
expect(page).to have_text('Support')
end
end
On rails_helper.rb on the top:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rake'
require 'spec_helper'
require 'rspec/rails'
require 'shoulda/matchers'
require 'capybara/rails'
require 'capybara/rspec'
require 'rspec/retry'
require 'devise'
Error message:
Failure/Error: require File.expand_path('../../config/environment', __FILE__)
NoMethodError:
undefined method `[]' for nil:NilClass
# ./config/initializers/devise.rb:258:in `block in <top (required)>'
# ./config/initializers/devise.rb:5:in `<top (required)>'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/views/dashboard_view_spec.rb:1:in `require'
# ./spec/views/dashboard_view_spec.rb:1:in `<top (required)>'
No examples found.
Randomized with seed 14549
Then the command i used on the terminal
bundle exec rspec spec/views/dashboard_view_spec.rb
After watching the documentation of testing with Devise i changed the code in dashboard_view_spec.rb and used to sign_in as a user and got the same error message.
Line 258 of devise.rb
config.omniauth :facebook, Rails.application.secrets.facebook[:key], Rails.application.secrets.facebook[:secret], scope: 'email', info_fields: 'email, name'
In the gemfile
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
gem 'rspec-rails', '~> 3.8'
gem 'factory_girl_rails'
gem 'faker'
gem 'database_cleaner'
end
and
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
The problem is that you're missing a variable that your devise initializer expects to find, but only missing it in the test environment. (not the development environment)
The stack trace that you provided and line 258 from config/initializers/devise.rb are all that are needed. First, let's look at the stack trace:
NoMethodError:
undefined method `[]' for nil:NilClass
# ./config/initializers/devise.rb:258:in `block in <top (required)>'
# ./config/initializers/devise.rb:5:in `<top (required)>'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/views/dashboard_view_spec.rb:1:in `require'
# ./spec/views/dashboard_view_spec.rb:1:in `<top (required)>'
Starting from the bottom up, we can see that the first line of your spec is what's causing the issue. If you follow the stack you'll see that it ends up in config/initializers/devise.rb:258 and is complaining that something making a [] method call isn't getting the expected object type in return, and is instead getting nil in return.
Looking at line 258 you find:
config.omniauth :facebook, Rails.application.secrets.facebook[:key], Rails.application.secrets.facebook[:secret], scope: 'email', info_fields: 'email, name'
So you can see that there are two times that [] is called:
Rails.application.secrets.facebook[:key]
Rails.application.secrets.facebook[:secret]
What is expected is that calling Rails.application.secrets.facebook will return an Enumerable object (like an array or a hash) but instead it is returning nil, and when it attempts to run nil[:key] or nil[:secret] it raises an exception because NilClass is not an Enumerable and does not have a [] method. You can test this yourself in the rails console:
nil[:secret]
=> NoMethodError: undefined method `[]' for nil:NilClass
The solution is to ensure that calling Rails.application.secrets.facebook returns the expected object type. The short answer is to edit config/secrets.yml to ensure that the values you require for the test environment are present.
I haven't worked with devise in a long time, but I assume that you can safely use the same values that you're using for the development environment for the test environment. You can read more about secrets() elsewhere, but the basic template for config/secrets.yml is as follows:
environment:
key: value
For example:
test:
my_secret_key: my_secret_value
It should be fairly straightforward to copy and paste the missing facebook secrets into the test environment. After making the change you can verify it worked:
$ RAILS_ENV=test rails console
Rails.application.secrets.facebook[:key]
=> <your key here>
If that worked, then run your spec with rspec and it should successfully get past line 1. (assuming there are no other bugs or missing secrets)
I had very similar errors. Here's how I solved
Run rspec --backtrace
This could produce a lot of console output. Scroll right to the top, and start reading from the top. It will tell you the file your problem started in, and the line it happened on. Go to that file (and that line), and figure out what's missing.
In my case, it was actually a missing variable in credentials.yml, but cases will vary. Like in the excellent answer by #anothermh, it's basically telling you something is missing, so you have to figure out what's missing and make sure you provide it.
Just got the same error, but when I ran bundle exec rake spec instead of bundle exec rspec it worked.
I'm using Rails 4.1 and Ruby 2.0.0. I'm trying to set up testing with minitest-rails and I'm running into this strange error. When I include:
require 'minitest/spec'
In my 'spec_helper' file it give me a NameError: uninitialized constant Minitest::VERSION error. When I comment out this line, everything seems to work fine. The odd thing is that 'minitest/autorun' is also in there and not causing any problems. Maybe you guys can shed some light on what's going on here.
spec_helper.rb:
ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'minitest/spec'
require 'minitest/autorun'
require 'minitest-rails'
require 'minitest-rails-capybara'
Rakefile:
require File.expand_path('../config/application', __FILE__)
Pinteresting::Application.load_tasks
namespace :test do
task :run do
ENV["RACK_ENV"] = "test"
$LOAD_PATH.unshift("lib", "spec")
if ARGV[1]
require_relative ARGV[1]
else
Dir.glob("./spec/**/*_spec.rb").each { |file| require file }
end
end
end
.spec:
require "spec_helper"
describe "Test" do
describe "When two is equal to two" do
it "asserts true" do
assert_equal(2, 2)
end
end
end
Stack trace:
nbp-93-202:pinteresting Frank$ rake test:run
rake aborted!
NameError: uninitialized constant Minitest::VERSION
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/unit.rb:22:in `<class:Unit>'
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/unit.rb:21:in `<module:Minitest>'
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/unit.rb:20:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/spec.rb:1:in `<top (required)>'
/Users/Frank/Desktop/pinteresting/spec/spec_helper.rb:4:in `<top (required)>'
/Users/Frank/Desktop/pinteresting/spec/diagnostic_spec.rb:1:in `<top (required)>'
/Users/Frank/Desktop/pinteresting/Rakefile:12:in `block (3 levels) in <top (required)>'
/Users/Frank/Desktop/pinteresting/Rakefile:12:in `each'
/Users/Frank/Desktop/pinteresting/Rakefile:12:in `block (2 levels) in <top (required)>'
Tasks: TOP => test:run
Interestingly, if try to run or require a file with just the two requires minitest/spec and minitest/autorun the interpreter raises a warning saying that you should require 'minitest/autorun' instead or add "gem 'minitest'" before require 'minitest/autorun', although it doesn't rise the NameErrorto me.
So switching the require statements around (in order to first require minitest/autorun) seems to do the trick. Requiring minitestin the first place seems to do the trick also.
I think you can resolve this warning by making your implementation simpler. In spec/spec_helper.rb:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/rails"
require "minitest/rails/capybara"
You are missing the require for rails/test_help. Did you remove that for a specific reason?
In Rakefile:
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks
Rails::TestTask.new("test:spec" => "test:prepare") do |t|
t.pattern = "spec/**/*_spec.rb"
end
Rake::Task["test:run"].enhance ["test:spec"]
And now run either $ rake test:spec to run all your specs, or $ rake test to run all your tests. The reason behind keeping the rake tasks under the test namespace is because this is what Spring keys on to use the running test environment. Spring uses the task namespace, not the directory name.
I have a blog I'm working on and I added some javascript to make the form for the blog pop up when you click on new post. Everything works fine. I got tests working with minitest and capybara and I installed the gem selenium-webdriver everything works fine when I test it locally. However, when I push up to Github and travis-ci takes in my info and runs my tests it gives me this error
unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)
I'm a little confused because I was getting that error locally until I updated to the gem selenium-webdriver to version 2.39.0. I just downloaded firefox so as far as I know everything is up to date. here is some of my files if that helps.
my test
feature "as a student I want a working blog so people can post" do
# this is line 10
scenario "User can make a post", :js => true do
dude_sign_up
dude_log_in
visit posts_path
click_on "New Post"
create_post
page.must_have_content "Post was successfully created"
end
# this is line 19
gemfile
group :development, :test do
gem 'sqlite3'
gem 'minitest-rails'
gem 'launchy'
gem 'coveralls', require: false
gem 'minitest-rails-capybara'
gem 'turn'
gem 'pry'
gem "selenium-webdriver", "~> 2.39.0"
end
.travis.yml file
language: ruby
rvm:
- "2.0.0"
env:
- DB=sqlite
script:
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rake db:test:prepare
- rake minitest:features
bundler_args: --binstubs=./bundler_stubs
test helper file
require 'simplecov'
SimpleCov.start 'rails'
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/rails"
require "minitest/rails/capybara"
require 'selenium-webdriver'
require 'coveralls'
Coveralls.wear!
# To add Capybara feature tests add `gem "minitest-rails-capybara"`
# to the test group in the Gemfile and uncomment the following:
# require "minitest/rails/capybara"
# Uncomment for awesome colorful output
# require "minitest/pride"
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
class ActionDispatch::IntegrationTest
include Rails.application.routes.url_helpers
#include Capybara::RSpecMatchers
include Capybara::DSL
end
Turn.config.format = :outline
def dude_sign_up
visit new_user_path
fill_in "Name", with: "thedude"
fill_in "Email", with: "thedude#cool.com"
fill_in "Password", with: 'password'
fill_in "Bio", with: "the bio"
fill_in "Password confirmation", with: 'password'
click_on "Submit"
end
def dude_log_in
visit new_session_path
fill_in "Email", with: "thedude#cool.com"
fill_in "Password", with: 'password'
click_on "Log In"
end
def create_post
fill_in "Title", with: "this is a test title"
fill_in "Content", with: "oh how this is some crazzzzy content"
click_on "Create Post"
end
travis full error
test_0002_User can make a post 1:00:23.767 ERROR
unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)
Exception `Selenium::WebDriver::Error::WebDriverError' at:
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/firefox/launcher.rb:79:in `connect_until_stable'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/firefox/launcher.rb:37:in `block in launch'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/common/driver.rb:31:in `new'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/common/driver.rb:31:in `for'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver.rb:67:in `for'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/capybara-2.1.0/lib/capybara/selenium/driver.rb:11:in `browser'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/capybara-2.1.0/lib/capybara/selenium/driver.rb:43:in `visit'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/capybara-2.1.0/lib/capybara/session.rb:193:in `visit'
/home/travis/.rvm/gems/ruby-2.0.0-p353/gems/capybara-2.1.0/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
test/test_helper.rb:35:in `dude_sign_up'
test/features/blog_system_works_test.rb:12:in `block (2 levels) in <top (required)>'
does anyone understand why this works locally but not with travis-ci?
hey Reck you pointed me in the right direction; however, I found that the problem was in my .travis.yml file
if you go to
http://karma-runner.github.io/0.8/plus/Travis-CI.html
they will tell you that to set up travis to use firefox you need to add
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
to your travis file.
after changing my .travis.yml file to
language: ruby
rvm:
- "2.0.0"
env:
- DB=sqlite
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
script:
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rake db:test:prepare
- rake minitest:features
bundler_args: --binstubs=./bundler_stubs
everything worked fine with travis
Try setting transactional_fixture to false in your rspec_spec.rb:
config.use_transactional_fixtures = false
There's quite a few solid tutorials out there, and I haven't had too much trouble getting this working in the past. But, after hours of trying, I must be missing something.
I've completed the standard installation instructions, and started up the spork server:
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!
Looking good.
Then, I hop over to a new tab and run my specs:
$ rspec spec
This command returns nothing after running for only a split second. So I jump back to the spork server to see what happened and get:
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!
Running tests with args ["--color", "spec"]...
Exception encountered: #<DRb::DRbConnError: druby://localhost:56736 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>>
backtrace:
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:736:in `rescue in block in open'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:730:in `block in open'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:729:in `each'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:729:in `open'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1191:in `initialize'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1171:in `new'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1171:in `open'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1087:in `block in method_missing'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1105:in `with_friend'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1086:in `method_missing'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1074:in `respond_to?'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0#scholastica/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:10:in `block in run'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0#scholastica/gems/spork-0.9.0.rc9/lib/spork/forker.rb:21:in `block in initialize'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0#scholastica/gems/spork-0.9.0.rc9/lib/spork/forker.rb:18:in `fork'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0#scholastica/gems/spork-0.9.0.rc9/lib/spork/forker.rb:18:in `initialize'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0#scholastica/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:9:in `new'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0#scholastica/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:9:in `run'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0#scholastica/gems/spork-0.9.0.rc9/lib/spork/server.rb:48:in `run'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1548:in `perform_without_block'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1508:in `perform'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1586:in `block (2 levels) in main_loop'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1582:in `loop'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1582:in `block in main_loop'
Done.
For some reason, drb is failing to connect? I've googled like crazy, but there just doesn't seem to be anything helpful out there.
Some possible clues
The port (in this case 56736) changes every time I attempt to run the suite
I get the same result on both ruby 1.9.2 and ruby 1.9.3
I'm using a mac (snow leopard) and firewalls are disabled
I've tried it on a totally different mac (also snow leopard) with the same result.
I'm using the latest version of cucumber, rspec, and spork.
I also setup cucumber spork and it failed the same way.
As you can see, I've been banging away at it for a while. My project uses a lot of gems and not having spork makes testing really, really terrible. Please help...
UPDATE
Here's my spec_helper:
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require "email_spec"
require 'webmock/rspec'
require 'vcr'
require 'database_cleaner'
include Devise::TestHelpers
include EmailSpec::Helpers
include EmailSpec::Matchers
# Stub all updates to search indexes
class Profile
def update_tank_indexes ; end
def delete_tank_indexes ; end
end
class Journal
def update_tank_indexes ; end
end
# Apparently rspec doesn't understand <tt>main_app</tt> so stub it out.
def main_app ; self ; end
# 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|
config.mock_with :rspec
# 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
config.extend VCR::RSpec::Macros
# Always clean the database after running describe/context blocks to ensure a
# consistent state. This is especially important when using the <tt>rspec-set</tt>
# method. This method creates setup object once -- and only once -- proir to
# running an entire describe/context block. In this way, it's similar to using
# <tt>before(:all)</tt> except that <tt>set</tt> is better because:
#
# * It automatically reloads the object before each example, making it much
# safer than before(:all) which can cause bugs if you're not careful.
# * It's lazily evaluated.
#
# You can read more at:
#
# * eggsonbread.com/2010/05/25/speed-up-your-specs-with-set/
# * github.com/pcreux/rspec-set
#
# Note: This is not part of default configuration. Be sure to retain this snippet
# when upgrading.
#
DatabaseCleaner.strategy = :truncation
config.before(:all) do
DatabaseCleaner.clean
end
config.after(:suite) do
DatabaseCleaner.clean
end
end
end
Spork.each_run do
# This code will be run each time you run your specs.
end
I opened a ticket for this issue, but nothing has come of it in the last 3.5 months: https://github.com/sporkrb/spork/issues/133
Update: I found the solution, and reported everything to that ticket. tl;dr: change your Gemfile entry for 'always_validate_ssl_certifitcates' to include :require => false.
Can you roll back to spork 0.8.5 and see if it works? I've just verified that working.
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