Note that there are some explanatory texts on larger screens.

plurals
  1. POrails omniauth error in rspec output
    primarykey
    data
    text
    <p>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. </p> <p>This test works correctly but sends an error message into the rspec output</p> <pre><code>$ 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 </code></pre> <p>or</p> <pre><code>$ 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 </code></pre> <p>Relevant test</p> <pre><code>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 </code></pre> <p>and the authentication_helper</p> <pre><code>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 </code></pre> <p>Is there something I can do to suppress the error message from the rspec output ?</p> <p><strong>Edit</strong></p> <p>I tried implementing the silence function described by @Shepmaster and that did not solve the issue. Then tried redirecting errors from the rspec command:</p> <pre><code>rspec -fd --tag inspect 2&gt; /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 </code></pre> <p>and redirecting stdout </p> <pre><code>rspec -fd --tag inspect &gt; /dev/null </code></pre> <p>no output!</p> <p>and finally using the output option </p> <pre><code>rspec -fd --tag inspect -o /tmp/rspec.out 2&gt; /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 </code></pre> <p><strong>ANSWER</strong> using the answer from @shepmaster </p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload