rspec - adding a helper module? - ruby-on-rails

I'm following this example here: http://erikonrails.snowedin.net/?p=230
I added:
lib/delayed_job_spec_helper.rb
Then in my rspec I have:
describe Thingy do
include DelayedJobSpecHelper
it "should have been worked on if I do something that queues jobs" do
thing = Thingy.new
thing.method_that_queues_jobs
work_off
thing.should be_worked_on
end
end
Problem is I get the error:
/Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing': uninitialized constant DelayedJobSpecHelper (NameError)
Ideas? thanks

Please check this discussion, it might be connected to your problem.
http://www.mail-archive.com/thinking-sphinx#googlegroups.com/msg05036.html

Related

Errors RSpec while testing API

just starting to learn RSpec and TDD, and can't figure out why it's don't work at all.
#spec/api/event_api_spec.rb
describe 'Messages API' do
it 'check response' do
get 'api.mydomain.dev/events'
json = JSON.parse(response.body)
# test for the 200 status-code
expect(response).to be_success
end
end
I have create my API on api.mydomain.dev and my folder structure looks like app/controllers/api/events_controller.rb
So when I tried to run bundle exec rspec it's shown that
NoMethodError:
undefined method `get' for #<RSpec::ExampleGroups::MessagesAPI:0x007fc34900cee0>
if I'm trying to make smth like Event.creat!(:name => 'My Event') in My Spec file #spec/api/event_api_spec.rb it says
NameError:
uninitialized constant Event
So i don't understand How require my app/controllers/api/events_controller.rb file to the Spec file to get instance of my Event Class to get it work.
With default controllers it's work fine, I only interesting in API setup, thx
"get" is a method available on controller specs, try with something like
describe 'Messages API', type: :controller do
to tell rspec you are testing something like a controller, or maybe just do
describe EventsController do
About the "uninitialized constant Event", try with this at the begning of spec/api/event_api_spec.rb
require 'rails_helper'
Hope this helps, but your post is a little confusing, is not clear if your api is online or what, you shouldn't test agains the online api, you should test locally, specs should never communicate with the real world unless it's really really necessary.

how to disable warning message with sidekiq in rspec

I'm fairly new to rails and testing. Documentation says to add this code to spec_helper.rb:
RSpec::Sidekiq.configure do |config|
config.warn_when_jobs_not_processed_by_sidekiq = false
end
but when I do, i get an error:
uninitialized constant RSpec::Sidekiq (NameError)
If you have rspec 3, then you should try to add following code to rails_helper.rb instead of spec_helper.rb

FactoryGirl error : rspec

I cannot run rpsec after merging my code from Github.
I keep getting FactoryGirl error :
uninitialized constant ControllerMacros::FactoryGirl
1) Question has a valid factory
Failure/Error: expect(FactoryGirl.build(:question)).to be_valid
NameError:
uninitialized constant FactoryGirl
# ./spec/models/question_spec.rb:14:in `block (2 levels) in '
Please help.
It appears that FactoryGirl may be missing some definitions. Try declaring the following in your spec_helper:
# spec/spec_helper.rb
require 'factory_girl'
FactoryGirl.find_definitions
If this is for a Rails project, you can avoid finding definitions manually by using factory_girl_rails, which will automatically load your definitions for you.

Rails Engine with RSpec and FactoryGirl

I followed a few tutorials and docs of FactoryGirl to use with RSpec. Currently I get one error when trying to use FactoryGirl.create:
describe "GenericRecipesController" do
describe "GET 'index'" do
it "displays list of generic recipes" do
generic_recipe = FactoryGirl.create(:generic_recipe)
visit '/recipe'
response.should be_success
end
end
end
And the error:
GenericRecipesController GET 'index' displays list of generic recipes
Failure/Error: generic_recipe = FactoryGirl.create(:generic_recipe)
NameError:
uninitialized constant GenericRecipe
# ./spec/integration/generic_recipes_spec.rb:8:in `block (3 levels) in <top (required)>'
The rest of code is there.
You can try this:
factory :generic_recipe, class: EdibleRecipe::GenericRecipe do
# ...
end
I think problem in a nesting model in module
Upd: delete file /spec/factories.rb, in file /spec/support/factories.rb make
factory :generic_recipe, class: EdibleRecipe::GenericRecipe do
When you will run tests, probably will see 'can not load table'. Make
rake db:migrate RAILS_ENV=test
and try again.
You don't seem to have a GenericRecipe model in your app. Factory Girl is looking for a Model called GenericReciper and can't find it.

Shoulda for Rspec, Rails, outputs there is an error but doesn't output the error itself

Well, I'm doing some testing right with Rails+Rspec+Shoulda.
When I do a test like the following:
context #user do
describe 'Validation' do
describe :name
it { should allow_value('something').for :name }
end
end
end
When it fails, Rspec just output:
1) Validation name Valid
Failure/Error: it { should allow_value(value).for :name }
Did not expect errors when name is set to "something", got error:
# ./spec/models/user_spec.rb:4:in `block (3 levels) in <top (required)>'
It even says got error: but it doesn't output it! I actually know there is a validation error there, but I want Rspec to tell me that, how I would know what is failing to validate then?
What am I doing wrong? Is that the expected behaviour? I have to overwrite the helpers?
I dug into the Shoulda code and I found that it doesn't show the errors when checking for positive assert. But them are loaded into the #errors variable. So I just monkey patched the one method that defines the output:
module Shoulda
module ActiveRecord
module Matchers
def failure_message
"Did not expect #{expectation}, got error: \n#{#expected_message ? #matched_error : #errors.join("\n ")}"
end
end
end
end
The original said:
"Did not expect #{expectation}, got error: #{#matched_error}"
I saved it to /lib/shoulda/activerecord/matchers.rb and loaded it with config.autoload_paths += Dir["#{config.root}/lib/**/"]
Hope this helps someone with the same issue ^^
Yup welcome to spec testing so you need to recreate the error in console if you want the error, rspec is not a debugger just a test suite.
I run into this a lot

Resources