Rails::TestUnitReporter can't find the methods of MiniTest::Result tests - ruby-on-rails

Running rails test, Rails::TestUnitReporter is having trouble picking up the source location of MiniTest::Result tests. The structure of MiniTest::Result isn't what Rails::TestUnitReporter expects.
/usr/local/rvm/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb:71`:in `method': undefined method `test_It_calcualtes_late_fees_correctly' for class `Minitest::Result' (NameError)
Inserting a byebug call, I see:
[66, 75] in /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb
66: "%s#%s = %.2f s = %s" % [result.class, result.name, result.time, result.result_code]
67: end
68:
69: def format_rerun_snippet(result)
70: byebug if not Rails.env.production?
=> 71: location, line = result.method(result.name).source_location
72: "#{self.executable} #{relative_path_for(location)}:#{line}"
73: end
74:
75: def app_root
(byebug) results.first.source_location
["/home/xxx/code/prj/test/models/invoice_template_test.rb", 9]
My test:
4 class InvoiceTemplateTest < ActiveSupport::TestCase
5 test "the truth" do
6 assert true
7 end
8
9 test "It calcualtes late fees correctly" do
10 tests = {
11 fixed_fee: {
12 feePolicy: '10.0 $ > 50',
13 pastDue: 52.0,
[...]
25 },
26 decimal_fee: {
27 feePolicy: '0.1',
28 pastDue: 24.4,
29 expectedFee: 2.44,
30 },
31 }
32
33 tests.each {|scenario, parameters|
34 policy = parameters[:feePolicy]
35 it = InvoiceTemplate.new(late_fee: policy)
36
37 expected = parameters[:expectedFee]
38 actual = it.calculateLateFee(parameters[:pastDue])
39 msg = "For scenario #{scenario.to_s}, expected #{expected} and got #{actual}"
40 assert_in_delta(expected, actual, 0.001, msg)
41 }
42
43 end
44 end
If I comment out "It calcualtes late fees correctly", it runs "the truth" correctly:
$ rvm 2.3.1 do rails test
Running via Spring preloader in process 10308
Run options: --seed 37453
# Running:
.
Finished in 0.003080s, 324.6650 runs/s, 324.6650 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
$
It's not having trouble running the tests, it's having trouble reporting back cleanly from them. Inserting a test with assert false, I get same error:
9 test "the false" do
10 assert false
11 end
$ rvm 2.3.1 do rails test
Running via Spring preloader in process 16606
Run options: --seed 30320
# Running:
F
Failure:
InvoiceTemplateTest#test_the_false [/home/xxx/code/prj/test/models/invoice_template_test.rb:10]:
Expected false to be truthy.
[66, 75] in /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb
66: "%s#%s = %.2f s = %s" % [result.class, result.name, result.time, result.result_code]
67: end
68:
69: def format_rerun_snippet(result)
70: byebug if not Rails.env.production?
=> 71: location, line = result.method(result.name).source_location
72: "#{self.executable} #{relative_path_for(location)}:#{line}"
73: end
74:
75: def app_root
(byebug) c
/usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb:71:in `method': undefined method `test_the_false' for class `Minitest::Result' (NameError)
I don't think it's the double gems directory, it runs inside the same installation for the whole stack trace:
lusk 10:24:39 {t15209_railsUnitTest} ~/code/prj/test$ rvm 2.3.1 do rails test
Running via Spring preloader in process 11485
Run options: --seed 58861
# Running:
F
Failure:
InvoiceTemplateTest#test_It_calcualtes_late_fees_correctly [/home/xxx/code/prj/test/models/invoice_template_test.rb:40]:
For scenario minimum, expected 0.0 and got 10.0.
Expected |0.0 - 10.0| (10.0) to be <= 0.001.
[66, 75] in /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb
66: "%s#%s = %.2f s = %s" % [result.class, result.name, result.time, result.result_code]
67: end
68:
69: def format_rerun_snippet(result)
70: byebug if not Rails.env.production?
=> 71: location, line = result.method(result.name).source_location
72: "#{self.executable} #{relative_path_for(location)}:#{line}"
73: end
74:
75: def app_root
(byebug) c
/usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb:71:in `method': undefined method `test_It_calcualtes_late_fees_correctly' for class `Minitest::Result' (NameError)
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb:71:in `format_rerun_snippet'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb:23:in `record'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:803:in `block in record'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:802:in `each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:802:in `record'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:334:in `run_one_method'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:321:in `block (2 levels) in run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:320:in `each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:320:in `block in run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:360:in `on_signal'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:347:in `with_info_handler'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:319:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/line_filtering.rb:9:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:159:in `block in __run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:159:in `map'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:159:in `__run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:136:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:63:in `block in autorun'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
If I include rails_helper, I get more conflict, seemingly internal to rails:
$ rvmDo rails test
/usr/local/rvm/gems/ruby-2.3.1/gems/rails_helper-2.2.2/lib/rails_helper.rb:138:in `block in <class:Engine>': undefined method `install_helpers' for #<ActionDispatch::Routing::RouteSet:0x000000055c1b10>
Did you mean? instance_values (NoMethodError)
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:67:in `block in execute_hook'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:49:in `each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/application/finisher.rb:65:in `block in <module:Finisher>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/initializable.rb:30:in `instance_exec'
I suppose the double stacked gem installation could be at the fault of incompatibiilty between MiniTest::Result and Rails::TestUnitReporter. But before I re-install my entire rvm, rails and ruby installation, is there any gem I should try to upgrade with bundle update --conservative gem-name ?
Update: Futher looking into what version and which gem of the two I'm running:
(byebug) list=
[66, 75] in /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb
66: "%s#%s = %.2f s = %s" % [result.class, result.name, result.time, result.result_code]
67: end
68:
69: def format_rerun_snippet(result)
70: byebug if not Rails.env.production?
=> 71: location, line = result.method(result.name).source_location
72: "#{self.executable} #{relative_path_for(location)}:#{line}"
73: end
74:
75: def app_root
(byebug) Minitest::Result.singleton_methods.map{|m| Minitest::Result.method(m).source_location[0]}.uniq
["/usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb", "/usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/core_ext.rb"]
So they are both from inside /usr/local/rvm/gems/ruby-2.3.1/ . I'm going to see if there are knonwn incompatibiilties between railties-5.0.7 and minitest-5.11.3 and determine which one I should upgrade.

Related

Update crontab (Whenever gem)

By executing the whenever --update-crontab command, the following error returns:
/usr/lib/ruby/vendor_ruby/whenever/cron.rb:132:in `parse_as_string': Couldn't parse: 31557600 (ArgumentError)
from /usr/lib/ruby/vendor_ruby/whenever/cron.rb:112:in `parse_time'
from /usr/lib/ruby/vendor_ruby/whenever/cron.rb:50:in `time_in_cron_syntax'
from /usr/lib/ruby/vendor_ruby/whenever/cron.rb:42:in `output'
from /usr/lib/ruby/vendor_ruby/whenever/cron.rb:36:in `block (2 levels) in output'
from /usr/lib/ruby/vendor_ruby/whenever/cron.rb:35:in `each'
from /usr/lib/ruby/vendor_ruby/whenever/cron.rb:35:in `block in output'
from /usr/lib/ruby/vendor_ruby/whenever/cron.rb:34:in `each'
from /usr/lib/ruby/vendor_ruby/whenever/cron.rb:34:in `output'
from /usr/lib/ruby/vendor_ruby/whenever/job_list.rb:151:in `block (2 levels) in cron_jobs'
from /usr/lib/ruby/vendor_ruby/whenever/job_list.rb:147:in `each'
from /usr/lib/ruby/vendor_ruby/whenever/job_list.rb:147:in `block in cron_jobs'
from /usr/lib/ruby/vendor_ruby/whenever/job_list.rb:146:in `each'
from /usr/lib/ruby/vendor_ruby/whenever/job_list.rb:146:in `cron_jobs'
from /usr/lib/ruby/vendor_ruby/whenever/job_list.rb:65:in `generate_cron_output'
from /usr/lib/ruby/vendor_ruby/whenever.rb:10:in `cron'
from /usr/lib/ruby/vendor_ruby/whenever/command_line.rb:54:in `whenever_cron'
from /usr/lib/ruby/vendor_ruby/whenever/command_line.rb:106:in `updated_crontab'
from /usr/lib/ruby/vendor_ruby/whenever/command_line.rb:35:in `run'
from /usr/lib/ruby/vendor_ruby/whenever/command_line.rb:6:in `execute'
from /usr/bin/whenever:41:in `<main>'
My schedule.rb file:
every 1.year do
rake "maintenances:renew"
end
Any ideas?
If you're having problems with 1.year method, you can use the two following alternatives.
1 - Shortcuts
every :year do
rake "maintenances:renew"
end
2 - Expressions
every '0 0 1 12 *' do
rake "maintenances:renew"
end
If you want to learn more about these options, check the official documentation.
To test expressions, I recommend crontab.guru

Configuration of Rspec terminal output

I am a beginner with Rspec, and I found out my terminal output like this.
It's really in a mess and hard to understand test result.
Unlike the output in official tutorial.
Should I install some tools or modify some configuration?
Update
zombie.rb
class Zombie
attr_accessor :name
def initialize
#name = 'Error_Ash'
end
end
zombie_spec.rb
require "spec_helper"
require "zombie"
#give Class
describe Zombie do
# example
it "is named Class_Ash"
zombie = Zombie.new
zombie.name.should == "Ash"
end
error msg
Coda:rspec_pra Coda$ rspec spec/lib/zombie_spec.rb --format doc
/Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-support-3.4.1/lib/rspec/support.rb:87:in `block in <module:Support>': expected: "Ash" (RSpec::Expectations::ExpectationNotMetError)
got: "Error_Ash" (using ==)
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-support-3.4.1/lib/rspec/support.rb:96:in `call'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-support-3.4.1/lib/rspec/support.rb:96:in `notify_failure'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-expectations-3.4.0/lib/rspec/expectations/fail_with.rb:27:in `fail_with'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:71:in `fail_with_message'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:106:in `__delegate_operator'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:91:in `eval_match'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:51:in `block in use_custom_matcher_or_delegate'
from /Users/Coda/Desktop/code/ruby_pra/rspec_pra/spec/lib/zombie_spec.rb:11:in `block in <top (required)>'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:385:in `module_exec'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:385:in `subclass'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:255:in `block in define_example_group_method'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/dsl.rb:43:in `block in expose_example_group_alias'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/dsl.rb:82:in `block (2 levels) in expose_example_group_alias_globally'
from /Users/Coda/Desktop/code/ruby_pra/rspec_pra/spec/lib/zombie_spec.rb:6:in `<top (required)>'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `load'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `each'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `load_spec_files'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in `setup'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in `run'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/bin/rspec:22:in `load'
from /Users/Coda/.rvm/gems/ruby-2.1.3#rails416/bin/rspec:22:in `<main>'
Coda:rspec_pra Coda$
If there is nothing in your spec_helper that somehow overrides the --format switch (which I do not even know if it's possible) then this should give you readable tests that pass:
zombie.rb exactly as you posted,
zombie_spec
require "spec_helper"
require "zombie"
describe Zombie do
it "is named Ash" do
zombie = Zombie.new
expect(zombie.name).to eq "Ash"
end
end
and command rspec spec/lib/zombie_spec.rb -f d which is short for --format documentation
EDIT*: Oh sorry, the Error you posted is indeed an RSpec error... Its just not formated, as you said x.x
try the --tty flag maybe?
rspec spec/lib/zombie_spec.rb --tty -f d

uninitialized constant when running rspec test with concerns used in models

When I run rspec spec/models/football_match_spec.rb I get an uninitialized constant error:
/Users/jamessmith/project/app/models/football_match.rb:3:in `<class:FootballMatch>': uninitialized constant FootballMatch::Type1Fixture (NameError)
from /Users/jamessmith/project/app/models/football_match.rb:1:in `<top (required)>'
from /Users/jamessmith/project/spec/models/football_match_spec.rb:3:in `<top (required)>'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1226:in `load'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1224:in `each'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:97:in `setup'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:85:in `run'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:70:in `run'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/exe/rspec:4:in `<top (required)>'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/rspec:23:in `load' from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/rspec:23:in `<main>'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Type1Fixture concern:
module Type1Fixture
extend ActiveSupport::Concern
def competitors
[competitor_1, competitor_2]
end
def competitor_1_score
[fhhts || 0, shhts || 0, ethts || 0].reduce(:+)
end
def competitor_2_score
[fhats || 0, shats || 0, etats || 0].reduce(:+)
end
def name_with_scores
if [Fixture::IN_PROGRESS_STATUS, Fixture::COMPLETED_STATUS].include?(status)
"#{competitor_1.name} #{home_team_score} - #{away_team_score} #{competitor_2.name}"
else
"#{competitor_1.name} vs #{competitor_2.name}"
end
end
end
Edited FootballMatch model:
class FootballMatch < Fixture
include Mongoid::Document
include Type1Fixture
end
I've added app/models/concerns to the config.autoload_paths array in environments/test.rb.
This can be caused by not having the correct file name. For Type1Fixture, the file containing the class should be called app/models/concerns/type1_fixture.rb. Is this the case?

Sidekiq tries to run in test environment

I have a very strange issue: Sidekiq tries to establish connection to Redis in test environment.
I'm using sidekiq 3.2.2 with rspec-sidekiq 2.0.0.beta on rails 4.1.4 with ruby 2.1.2
Here is my test
require 'rails_helper'
describe FetchWorker::FetchWorker do
it 'runs in fetch queue' do
expect(subject).to be_processed_in :fetch
end
it 'not retry when it fails' do
expect(subject).to be_retryable false
end
it 'enqueues the new job' do
FactoryGirl.create(:history, running: false)
FetchWorker::FetchWorker.perform_async 'FetchWorker', true
expect(FetchWorker::FetchWorker).to have_enqueued_job('FetchWorker', true)
end # enqueue job
describe '#perform' do
let!(:settleddate) { (Time.now - 2.minutes).iso8601(10) }
let!(:lock_date) { (Time.now - 5.minutes).iso8601(10) }
context 'success' do
before do
FactoryGirl.create(:history, running: false, NEW_TRANSACTIONS: lock_date)
FactoryGirl.create(:abp_transaction, settleddate: settleddate, settledyn: 1, transactiontypeid: 1, accountid: 10966)
end
it 'perform worker' do
user = FactoryGirl.build_stubbed(:user, account_id: 10966)
worker = FetchWorker::FetchWorker.new
worker.perform
expect(user.transactions.count).to eq(1)
end # it perform worker
end # context success
context 'fail' do
it 'perform worker' do
FactoryGirl.create(:history, running: false, NEW_TRANSACTIONS: lock_date)
FactoryGirl.create(:abp_transaction, settleddate: settleddate, settledyn: 1, transactiontypeid: 1, accountid: 10966)
user = FactoryGirl.build_stubbed(:user, account_id: 10966)
worker = FetchWorker::FetchWorker.new
allow(worker).to receive(:process_transactions).and_raise('some error')
expect{ worker.perform }.to raise_error
end # it perform worker
end # context fail
end # describe perform
end # describe FetchWorker
If I try to run bundle exec rspec with working redis, I'm getting pretty nice output:
retgoat#ubuntu:/media/sf_offside/agent_system$ bundle exec rspec
[rspec-sidekiq] WARNING! Sidekiq will *NOT* process jobs in this environment. See https://github.com/philostler/rspec-sidekiq/wiki/FAQ-&-Troubleshooting
2014-08-22T11:35:52.377Z 5140 TID-4ehb4 INFO: Fetching transactions from 2014-08- 22T18:30:52.3447179170+07:00.
2014-08-22T11:35:52.394Z 5140 TID-4ehb4 INFO: Lock released.
2014-08-22T11:35:52.451Z 5140 TID-4ehb4 INFO: Fetching transactions from 2014-08- 22T18:30:52.4160675140+07:00.
Finished in 29.88 seconds (files took 17.24 seconds to load)
119 examples, 0 failures
Coverage report generated for RSpec to /media/sf_offside/agent_system/coverage. 872 / 873 LOC (99.89%) covered.
But if I try to run tests with stopped redis I'm getting this:
retgoat#ubuntu:/media/sf_offside/agent_system$ bundle exec rspec
Coverage report generated for RSpec to /media/sf_offside/agent_system/coverage. 377 / 855 LOC (44.09%) covered.
/home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis/client.rb:309:in `rescue in establish_connection': Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED) (Redis::CannotConnectError)
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis/client.rb:304:in `establish_connection'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis/client.rb:85:in `block in connect'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis/client.rb:266:in `with_reconnect'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis/client.rb:84:in `connect'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis/client.rb:326:in `ensure_connected'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis/client.rb:197:in `block in process'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis/client.rb:279:in `logging'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis/client.rb:196:in `process'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis/client.rb:102:in `call'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis.rb:784:in `block in get'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis.rb:37:in `block in synchronize'
from /home/retgoat/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis.rb:37:in `synchronize'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/redis-3.1.0/lib/redis.rb:783:in `get'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/sidetiq- 0.6.1/lib/sidetiq/schedulable.rb:65:in `get_schedulable_key'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/sidetiq-0.6.1/lib/sidetiq/schedulable.rb:45:in `recurrence'
from /media/sf_offside/agent_system/app/workers/fetch_worker.rb:6:in `<class:FetchWorker>'
from /media/sf_offside/agent_system/app/workers/fetch_worker.rb:2:in `<module:FetchWorker>'
from /media/sf_offside/agent_system/app/workers/fetch_worker.rb:1:in `<top (required)>'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:348:in `require_or_load'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:480:in `load_missing_constant'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:180:in `const_missing'
from /media/sf_offside/agent_system/spec/workers/fetch_worker_spec.rb:3:in `<top (required)>'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `block in load_spec_files'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `each'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load_spec_files'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:97:in `setup'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/rspec-core- 3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
from /home/retgoat/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
from /home/retgoat/.rvm/gems/ruby-2.1.2/bin/rspec:23:in `load'
from /home/retgoat/.rvm/gems/ruby-2.1.2/bin/rspec:23:in `<main>'
from /home/retgoat/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
from /home/retgoat/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
I just have no idea why it happens.
I'm also opened a new issue in sidekiq on Github https://github.com/mperham/sidekiq/issues/1907
Could you please help with that?
Many thanks.
UPDATE
As #infused mentioned there is a bug: https://github.com/tobiassvn/sidetiq/issues/103
Here is the workaround:
recurrence { minutely(5) } unless Rails.env.test?
Worked like a charm! :)
Many thanks
The problem is that you are using sidetiq which has a bug which causes it to try to connect when it shouldn't.

ActiveRecord::RecordNotSaved - Rails 3 seeding data

I am using rails 3.2.13 and ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-linux] in CentOS 5.6. When I try to seed the data I got the following error.
** Execute Samp:seed:record_status
Creating RecordStatus: Active
rake aborted!
ActiveRecord::RecordNotSaved
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/persistence.rb:105:in `save!'
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/validations.rb:56:in `save!'
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/transactions.rb:264:in `block in save!'
/opt/Samp/lib/tasks/seed/record_status.rake:19:in `block (4 levels) in <top (required)>'
/opt/Samp/lib/tasks/seed/record_status.rake:16:in `each'
/opt/Samp/lib/tasks/seed/record_status.rake:16:in `block (3 levels) in <top (required)>'
record_status.rake
16: record_statuses.each do |rs|
17: unless RecordStatus.find_by_seed_name(rs[:name])
18: puts "Creating RecordStatus: #{rs[:name]}"
19: RecordStatus.create!(:name => rs[:name],
20: :seed_name => rs[:name],
21: :description => rs[:description])
22: end
23: end
EDIT-1
*RecordStatus.rb*
class RecordStatus < ActiveRecord::Base
acts_as_enumerated
ACTIVE = 1
DISABLED = 2
DELETED = 3
validates_uniqueness_of :id , :name
end
It appears like you must have duplicate names in your seed data. To find out for sure, change your call to create! to something like:
rs = RecordStatus.new(...)
unless rs.save
raise "Couldn't save #{rs.inspect}: #{rs.errors.full_messages.to_sentence}"
end
Rails 3 doesn't support create/alter/destroy instances for enumerations by nature. If we wants to create any enumerations just add Model.enumeration_model_updates_permitted = true in record_status.rake file. REF : Enumerations_mixin

Resources