“Could not find a valid mapping for #” only on second and successive tests
Add this line to your routes.rb # Devise routes devise_for :users # Or the name of your custom model
Add this line to your routes.rb # Devise routes devise_for :users # Or the name of your custom model
You should not know where the method is called, just if the method is called.. You just know if the method is call: Before RSpec 3 it “should auto populate feed after user.add_friend” do FeedItem.should_receive(:populate_from_friend_to_user).with(@friend1, @user) @user.add_friend(@friend1) end In RSpec 3 the syntax is expect(Object).to receive(:method).with(params)
I found that it is now pretty easy to do this. There was a problem with rspec2 and devise, but is now solved. I guess you would need to update your gems. Then you can write require ‘spec_helper’ describe DoStuffController do include Devise::TestHelpers before (:each) do @user = Factory.create(:user) sign_in @user end describe “GET ‘index'” … Read more
should_receive(:method) works whether the visibility of :method is public or private.
There is a much better way described here: https://stackoverflow.com/a/24052647/362378 it “should do something specific for production” do allow(Rails).to receive(:env) { “production”.inquiry } #other assertions end This will provide all the functions like Rails.env.test? and also works if you just compare the strings like Rails.env == ‘production’
The problem is that self within the example group is different from self within a before hook, so it’s not the same instance variable even though it has the same name. I recommend you use let for cases like these: # support/shared_examples.rb shared_examples “a text field” do |field, fill, length| it “it should be long … Read more
You can use and_yield to make rspec call the block passed to the mock: MyClass.stub(:find_each).and_yield(one_mock).and_yield(two_mock)
You commented on my similar question a bit ago, and I found an answer that might help you as well. Upgrading to Devise 3.1.0 left some ‘cruft’ in a view that I hadn’t touched in a while. According to this blog post, you need to change your Devise mailer to use @token instead of the … Read more
If you configure RSpec to disable the should syntax, you can still use the old one-liner syntax, since that doesn’t involve should being added to every object: describe User do it { should be_valid } end We briefly discussed an alternate one-liner syntax, but decided against it since it wasn’t needed and we felt like … Read more
I usually add a helper like this: def without_transactional_fixtures(&block) self.use_transactional_fixtures = false before(:all) do DatabaseCleaner.strategy = :truncation end yield after(:all) do DatabaseCleaner.strategy = :transaction end end Which lets me turn off transactional fixtures for a specific block in the specs: describe “doing my thing” do without_transactional_fixtures do it “does something without transaction fixtures” do … … Read more