I have a rails 4 application using devise / omniauth to allow login via facebook. The application seems to work, and the tests seem to work too. However I have one test which checks for the situation where the user goes to login via facebook, but decides not to grant permission.
This test works correctly but sends an error message into the rspec output
$ rspec -fd --tag inspect
Sign in with facebook
new user
E, [2013-10-20T21:25:24.232573 #17137] ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials encountered
does not grant permission
Finished in 0.21152 seconds
1 example, 0 failures
Randomised with seed 52495
or
$ rspec
....E, [2013-10-20T21:25:24.232573 #17137] ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials encountered.
............................................................
Finished in 0.95531 seconds
74 examples, 0 failures
Randomized with seed 2946
Relevant test
require 'spec_helper.rb'
feature "sign in with facebook" do
context "new user" do
scenario "does not grant permission", inspect: true do
dont_sign_in_with_facebook
expect(notice_area).to have_content "Could not authenticate you from Facebook because \"Invalid credentials\""
end
end
end
and the authentication_helper
module Features
module AuthenticationHelpers
def dont_sign_in_with_facebook
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
visit "/users/auth/facebook"
end
end
end
Is there something I can do to suppress the error message from the rspec output ?
Edit
I tried implementing the silence function described by @Shepmaster and that did not solve the issue. Then tried redirecting errors from the rspec command:
rspec -fd --tag inspect 2> /dev/null
Sign in with facebook
new user
E, [2013-10-20T21:25:24.232573 #17137] ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials encounterd
does not grant permission
Finished in 0.21152 seconds
1 example, 0 failures
Randomised with seed 65190
and redirecting stdout
rspec -fd --tag inspect > /dev/null
no output!
and finally using the output option
rspec -fd --tag inspect -o /tmp/rspec.out 2> /dev/null
cat /tmp/rspec.out
Sign in with facebook
new user
does not grant permission
Finished in 0.21152 seconds
1 example, 0 failures
Randomised with seed 65190
ANSWER using the answer from @shepmaster
module Features
module AuthenticationHelpers
def dont_sign_in_with_facebook
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
silence_omniauth {visit "/users/auth/facebook"}
end
end
end