How to fake OpenID login in RSpec / Cucumber user story when using open_id_authentication plugin

I am trying to write a Cucumber script that requires that I have a registered user, which would usually be quite simple, but I only use OpenID authentication (minimizing the authentication plugin). However, after slipping through the guts of open_id_authentication, I'm not sure how I could achieve this in Cucumber.

+6
ruby-on-rails openid rspec cucumber
source share
4 answers

I figured out the way if you put it in your /support/env.rb functions:

ActionController::Base.class_eval do private def begin_open_id_authentication(identity_url, options = {}) yield OpenIdAuthentication::Result.new(:successful), identity_url, nil end end 

Then you can just do something like this in the appropriate step:

 Given /^I am logged in as "(.*)"$/ do |name| user = User.find_by_name(user) post '/session', :openid_url => user.identity_url # Some assertions just to make sure our hack in env.rb is still working response.should redirect_to('/') flash[:notice].should eql('Logged in successfully') end 

I just completely hide the auth public identifier for the cucumber functions, obviously, if I need instances where the login failed, I could do this based on the provided level_id.

+4
source share

Bort , a skileston rails app, has a full rspec benchmark and supports OpenID login so you can see and see what they do.

+2
source share

If you want to be able to disable answers, do the following:

In the functions /support/helpers.rb:

 ActionController::Base.class_eval do private def fake_openid_response(identity_url) [OpenIdAuthentication::Result.new(:successful), identity_url, nil] end def begin_open_id_authentication(identity_url, options = {}) yield fake_openid_response(identity_url) end end 

By moving the answer to a separate method, you can now drown out the answer at your own steps, if necessary. For example, if I wanted: a missing answer, and I had a GoogleLoginController, I could do the following with Mocha:

 GoogleLoginController.any_instance.stubs(:fake_openid_response) .returns([OpenIdAuthentication::Result.new(:missing), identity_url, nil]) 
+2
source share

The response to DEfusion works, except that I needed to normalize the id_name:

 ActionController::Base.class_eval do private def begin_open_id_authentication(identity_url, options = {}) yield OpenIdAuthentication::Result.new(:successful), self.normalize_identifier(identity_url), nil end end 

thanks

0
source share

All Articles