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
Related
Whenever I'm trying to run rspec for whole project (there are over 1000 tests) after finishing all testcases I receive following error:
/home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:183:in `formatted_backtrace': undefined method `backtrace' for nil:NilClass (NoMethodError)
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:191:in `colorized_formatted_backtrace'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:276:in `formatted_message_and_backtrace'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:199:in `fully_formatted'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:122:in `block in fully_formatted_pending_examples'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:121:in `each'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:121:in `each_with_index'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:121:in `fully_formatted_pending_examples'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/formatters/base_text_formatter.rb:50:in `dump_pending'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:146:in `block in notify'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:145:in `each'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:145:in `notify'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:123:in `finish'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:64:in `report'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:108:in `run_specs'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:86:in `run'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:70:in `run'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:38:in `invoke'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/exe/rspec:4:in `<top (required)>'
from /home/borisano/.rbenv/versions/2.1.5/bin/rspec:23:in `load'
from /home/borisano/.rbenv/versions/2.1.5/bin/rspec:23:in `<main>'
When I run only limited number of test cases, say, one file or single folder, everything works fine.
Here's my .rspec file
--color
--require rails_helper
and spec_helper.rb
require "rack_session_access/capybara"
RSpec.configure do |config|
end
So nothing suspicious, as for me
Any ideas on how to fix that?
Add this to your .rspec file:
--require spec_helper
This guarantees that your spec_helper is required before each spec.
When I run any RSpec test that fails, I get many lines of messages that I don't really understand.
For instance, suppose I run:
expect(true).to be_false
Then my console gets cluttered with messages beginning with #
Failures:
1) Some test
Failure/Error: expect(true).to be_false
expected true to respond to `false?`
# ./spec/controllers/wing_relationships_controller_spec.rb:43:in `block (3 levels) in <top (required)>'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `block in load'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `block in load'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
# -e:1:in `<main>'
The error messages always vary, and sometimes they are extremely long.
When I run many tests, it gets hard to read the results. I would like to get rid of those. Any suggestions? I already turned off --warning in RSpec
It's better find out where the errors come from and fix the leaky specs rather the ignoring the errors.
If you are not interested in doing it for some reason then you can always use:
You use a simple trick if you really want to:
rspec 2>/dev/null
Got this answer from https://github.com/rspec/rspec-rails/issues/1237
To remove the gems from the output, it's one line of config:
RSpec.configure do |config|
config.backtrace_exclusion_patterns << %r{/gems/}
end
Or, if you want to only filter out particular gems from your backtraces:
RSpec.configure do |config|
config.filter_gems_from_backtrace "rack", "rack-test", "capybara"
end
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.
This seemed to be a flickering sort of a bug for a while,but now it's appearing consistently: when I run RSpec on a fairly simple ApplicationHelper spec, I get the following error:
% rspec --backtrace
1) ApplicationHelper renders Markdown from plain text
Failure/Error: expect(helper.md(plaintext)).to eq("<h1 id=\"header\">Header</h1>\n")
NameError:
undefined local variable or method `helper' for #<RSpec::ExampleGroups::ApplicationHelper_2:0x000001248d1218>
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-expectations-0f7b78587ab4/lib/rspec/matchers.rb:903:in `method_missing'
# ./spec/helpers/application_helper_spec.rb:4:in `block (2 levels) in <top (required)>'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:148:in `instance_exec'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:148:in `block in run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:208:in `call'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:208:in `block (2 levels) in <class:Procsy>'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-rails-480b173c9ad6/lib/rspec/rails/adapters.rb:67:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:292:in `instance_exec'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:292:in `instance_exec'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:208:in `call'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:208:in `block (2 levels) in <class:Procsy>'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/hooks.rb:432:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/hooks.rb:485:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:301:in `with_around_example_hooks'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:145:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example_group.rb:494:in `block in run_examples'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example_group.rb:490:in `map'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example_group.rb:490:in `run_examples'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example_group.rb:457:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:112:in `block (2 levels) in run_specs'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:112:in `map'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/reporter.rb:49:in `report'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:108:in `run_specs'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:86:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:70:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:38:in `invoke'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/exe/rspec:4:in `<top (required)>'
# /Users/danielsh/Dropbox/Project/Websites/Angular/bin/rspec:20:in `load'
# /Users/danielsh/Dropbox/Project/Websites/Angular/bin/rspec:20:in `<main>'
Here's the complete spec file (spec_helper is included as part of my .rspec file):
describe ApplicationHelper do
it 'renders Markdown from plain text' do
plaintext = '# Header'
expect(helper.md(plaintext)).to eq("<h1 id=\"header\">Header</h1>\n")
end
end
This was working up until recently, but I'm not certain what I could have done to break such a basic feature. I'm using edge versions of Rails and RSpec, but didn't see anything in their git repos to suggest that helper had been deprecated---and running rails g helper foo still generates a foo_helper_spec.rb file with instructions indicating that helper contains the helper itself. If anyone has any ideas, I'd be grateful for them!
I created a new Rails project with a fresh RSpec installation, and it led me to the problem. Apparently one of the recent betas introduced a configuration directive called config.infer_spec_type_from_file_location! that was missing from my slightly older spec_helper file; without it, RSpec wasn't guessing the spec type and mixing in the associated methods. Beware breaking changes!
add :type => :helper
so your code should look like
describe ApplicationHelper, type: :helper do
...
end
That's a weird error !! are you sure you required spec_helper in your spec ?
Anyway you could try without the helper method:
First you should first add to /spec/spec_helper.rb the following:
RSpec.configure do |config|
...
config.include ApplicationHelper
end
Then test without helper , so it will be:
describe ApplicationHelper do
it 'renders Markdown from plain text' do
plaintext = '# Header'
expect(md(plaintext)).to eq("<h1 id=\"header\">Header</h1>\n")
end
end
From the backtrace, it doesn't look like you're using the rspec-rails gem - just rspec-core and rspec-expectations.
rspec-rails is what provides the helper method to your helper specs. From inside a spec in my codebase:
(rdb:1) self.method(:helper).source_location
["/home/becky/.gem/ruby/2.0.0/gems/rspec-rails-2.14.1/lib/rspec/rails/example/helper_example_group.rb", 19]
I'm a newbie in ruby/rails, currently doing the railstutorial book as a part of a university course.
I'm using ubuntu 11.04, ruby 1.9.2p290, and Rails 3.0.9, watchr (0.7), rspec (2.6.0), rspec-formatter-webkit (2.1.3) and spork (0.9.0.rc).
On github I came across this gem, and I thought it would be very nice to use it.
So basically what I'm trying to achieve is
continuous automated testing with notifications if finished, and also to generate the nice html output out of it.
So what I tried is that I wrote this watchr script:
require 'nokogiri'
require 'open-uri'
watch("spec/.*/*_spec.rb") do |match|
run_spec match[0]
end
watch("app/(.*/.*).rb") do |match|
run_spec %{spec/#{match[1]}_spec.rb}
end
def run_spec(file)
unless File.exist?(file)
puts "#{file} does not exist"
return
end
puts "Running #{file}"
result = `rspec -r rspec/core/formatters/webkit -f RSpec::Core::Formatters::WebKit #{file}`
File.open('out.html', 'w') do |f|
f.puts result
end
notify(result)
puts "DONE"
end
def send_notify title, msg, img, pri='low', time=5000
`notify-send -i #{img} -u #{pri} -t #{time} '#{msg}'`
end
def notify(result)
output = result
doc = Nokogiri::HTML(result)
doc.xpath('//div[#id = "summary"]').each do |node|
output = node.text.split.join(" ")
end
folder = "~/Pictures/autotest/"
if output =~ /([123456789]|[\d]{2,})\sfailed/
send_notify "FAIL:", "#{output}", folder+"rails_fail.png", 'critical', 20000
elsif output =~ /[1-9]\d*\spending?/
send_notify "PENDING:", "#{output}", folder+"rails_pending.png", 'normal', 15000
else
send_notify "PASS:", "#{output}", folder+"rails_ok.png"
end
end
handling the notifications, and generating the output while testing.
If I run this with watchr, everything is nice and working, however the tests are taking a long time of course.
The problem comes in here: if I try to use spork, to speed the tests up, I get a bunch of errors, starting with a LoadError:
Exception encountered: #<LoadError: no such file to load -- rspec/core/formatters/webkit>
backtrace:
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `block in require'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `block in load_dependency'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in `new_constants_in'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `load_dependency'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:247:in `block in requires='
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:247:in `map'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:247:in `requires='
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration_options.rb:21:in `block in configure'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration_options.rb:20:in `each'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration_options.rb:20:in `configure'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:17:in `run'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/monkey/spork/test_framework/rspec.rb:5:in `run_tests'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/run_strategy/forking.rb:13:in `block in run'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/forker.rb:21:in `block in initialize'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/forker.rb:18:in `fork'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/forker.rb:18:in `initialize'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/run_strategy/forking.rb:9:in `new'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/run_strategy/forking.rb:9:in `run'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/server.rb:47:in `run'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1518:in `perform'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
which of course don't really say anything to me, being a total newbie.
Is there a way to overcome this (or of course produce result in any other way)?
Any help is greatly appreciated :)
You might have more luck running the RSpec runner directly rather than shelling out, e.g.,
require 'rspec/core'
require 'rspec/core/formatters/webkit'
# ...then in #run_spec
puts "Running #{file}"
File.open( 'out.html', 'w' ) do |f|
argv = [ '-f', 'RSpec::Core::Formatters::WebKit', file ]
RSpec::Core::Runner.run( argv, f )
end
notify(result)
puts "DONE"
The ActiveSupport monkey(freedom)-patched 'Kernel.require' seems to be the thing that's different in the three scenarios you mentioned.
If you figure out why ActiveSupport can't find the library, I'd be happy to try to work around it in the WebKit formatter.