Facts:
- Running the entire set of specifications will result in 21 consistent errors out of 610 specifications.
- If I run any separate spec file (for example: messages_controller_spec.rb), they all go through.
- If I run any of the failed specifications separately, they will go through every time.
These errors are mostly ActionMailer crashes, but some are otherwise. One confusing aspect is that some of the specifications fail because the database had an extra row than expected, while others fail because there was one smaller row than expected. That is, if it is a cleaning or cache problem, it seems that it should be sequentially one or one more.
I am currently running Rails 4.1.1, Ruby 2.0.0p451, Rspec 2.14.8, Sidekiq via inline!
Gemfile (for test)
group :development, :test do
gem 'better_errors'
gem 'binding_of_caller'
gem 'faker'
gem 'guard-rspec'
gem 'pry'
gem 'rspec-rails'
gem 'spork-rails'
gem 'sqlite3'
gem 'thin'
end
group :test do
gem 'capybara'
gem 'capybara-email'
gem 'capybara-webkit'
gem 'database_cleaner'
gem 'fabrication'
gem 'launchy'
gem 'selenium-webdriver'
gem 'shoulda-matchers'
gem 'webmock'
gem 'vcr'
end
Please note that Ive checked about a dozen similar questions that did not help fix this. So, to clarify:
- I do not use ARGV
- I do not use before (: all) - I use before (: each).
- I tried to execute Rails.cache.clear before both: suite and: each specification.
- I have a database cleanup set to: truncate for the entire cleanup (slower but better results than: transaction - there were problems reloading the updated values using: transaction).
For convenience, some examples may help:
scheduler_spec.rb (indicating that the test fails when the entire package starts)
require 'spec_helper'
require 'rake'
require 'sidekiq/testing'
Sidekiq::Testing.inline!
describe "scheduler", :vcr do
describe ":wipe_abandoned_images" do
let!(:abandoned_old_image) { Fabricate(:image) }
let!(:abandoned_young_image) { Fabricate(:image) }
let!(:adopted_image) { Fabricate(:image) }
let(:run_cleaner) do
Rake::Task[:wipe_abandoned_images].reenable
Rake.application.invoke_task :wipe_abandoned_images
end
before do
abandoned_young_image.update_columns(listing_id: nil, updated_at: 6.days.ago)
abandoned_old_image.update_columns( listing_id: nil, updated_at: 9.days.ago)
Rake.application.rake_require 'tasks/scheduler'
Rake::Task.define_task(:environment)
end
context "for claimed images" do
it "leaves the image" do
adopted_image_id = adopted_image.id
run_cleaner
expect(Image.all.count ).to eq(2)
expect(Image.find(adopted_image_id) ).to be_present
end
end
end
end
, Sidekiq inline! .
forget_passwords_controller_spec.rb(, )
require 'spec_helper'
require 'sidekiq/testing'
Sidekiq::Testing.inline!
describe ForgotPasswordsController do
let!(:jen) { Fabricate(:user, email: 'jen@example.com') }
describe "POST create" do
context "with valid email provided" do
before { post :create, email: 'jen@example.com' }
after do
ActionMailer::Base.deliveries.clear
Sidekiq::Worker.clear_all
end
it 'sends the reset email to the users provided email' do
expect(ActionMailer::Base.deliveries.count).to eq(1)
end
end
end
end
, :
PassPasswordsController RubyTest SublimeText2
2014-08-28T03: 42: 43Z 32968 TID-ov5g65p44 INFO: Sidekiq redis options {}........... 0.95479 11 , 0 40226 [ 5.8s]
RubyTest SublimeText2
. ... .. ... ...Sweeping ... 2014-08-28T01: 49: 02Z 32426 TID-owjt9ggh8 INFO: Sidekiq redis {} ..Sweeping ... ..Sweeping ... ..
1,52 7 , 0 37996 [ 8.6 .]
rspec
$ rspec./spec/lib/tasks/scheduler_spec.rb
. ... .. ... ...Sweeping ... 2014-08-28T02: 14: 43Z 32456 TID-ouiui9g8c INFO: Sidekiq redis {} ..Sweeping ... ..Sweeping ... ..
1,32 7 , 0 19172
Rspec
, .
$ rspec
49,71 610 , 21 , 10
:
13) : wipe_abandoned_images 1 /: (Image.all.count).to eq (2)
expected: 2
got: 3
(compared using ==)
# ./spec/lib/tasks/scheduler_spec.rb:78:in `block (4 levels) in <top (required)>'
18) ForgotPasswordsController POST create reset , /: (ActionMailer:: Base.deliveries.count).to eq (1)
expected: 1
got: 0
(compared using ==)
# ./spec/controllers/forgot_passwords_controller_spec.rb:22:in `block (4 levels) in <top (required)>'
rspec ./spec/controllers/messages_controller_spec.rb:161
rspec ./spec/controllers/messages_controller_spec.rb:114
rspec ./spec/controllers/invitations_controller_spec.rb:30
rspec ./spec/controllers/invitations_controller_spec.rb:33
rspec ./spec/controllers/users_controller_spec.rb:161
rspec ./spec/controllers/users_controller_spec.rb:158
rspec ./spec/controllers/users_controller_spec.rb:164
rspec ./spec/controllers/users_controller_spec.rb:354
rspec ./spec/controllers/users_controller_spec.rb:348
rspec ./spec/controllers/users_controller_spec.rb:351
rspec ./spec/controllers/searches_controller_spec.rb:19
rspec ./spec/controllers/searches_controller_spec.rb:22
rspec ./spec/lib/tasks/scheduler_spec.rb:75
rspec ./spec/lib/tasks/scheduler_spec.rb:68
rspec ./spec/lib/tasks/scheduler_spec.rb:84
rspec ./spec/controllers/forgot_passwords_controller_spec.rb:24
rspec ./spec/controllers/forgot_passwords_controller_spec.rb:27
rspec ./spec/controllers/forgot_passwords_controller_spec.rb:21
rspec ./spec/controllers/reset_passwords_controller_spec.rb:70
rspec ./spec/controllers/reset_passwords_controller_spec.rb:67
rspec ./spec/controllers/reset_passwords_controller_spec.rb:73