Reputation: 317
Here Im testing email confirmation fails. In dev mode everything works just ok. And I think that I've missed some configurations.
context 'with valid provider data' do
before { session["devise.provider_data"] = { provider: 'twitter', uid: '123456' } }
it "sends email confirmation" do
expect{ post :create, authorization: { email: "[email protected]" } }.to change(ActionMailer::Base.deliveries, :count).by(1)
end
end
And the error
Failure/Error: expect{ post :create, authorization: { email: "[email protected]" } }.to change(ActionMailer::Base.deliveries, :count).by(1)
expected #count to have changed by 1, but was changed by 0
Coul anybody help with this?
context 'with valid provider data' do
before { session["devise.provider_data"] = { provider: 'twitter', uid: '123456' } }
before(:each) do
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
after(:each) do
ActionMailer::Base.deliveries.clear
end
it "sends email confirmation" do
expect{ post :create, authorization: { email: "[email protected]" } }.to change(ActionMailer::Base.deliveries, :count).by(1)
end
end
Upvotes: 0
Views: 40
Reputation: 7779
You are missing some configuration. I usually do the setup in a before and after callback before tests that test email behaviour, such as:
before(:each) do
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
after(:each) do
ActionMailer::Base.deliveries.clear
end
If you want the above configuration to apply to all your test suite, you could include it in your spec/spec_helper.rb
file in the configure block:
RSpec.configure do |config|
....
config.before(:suite) do
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
config.after(:suite) do
ActionMailer::Base.deliveries.clear
end
end
Upvotes: 2