Je viens de mettre en œuvre OmniAuth (en utilisant Screencast http://asciicasts.com/episodes/235-omniauth-part-1 de Ryan Bates) et j'écris des tests Rspec pour la fonctionnalité et j'ai eu du mal à tester l'authentification # create action. Je ne sais pas comment tester celui-ci - en particulier comment remplacer la variable locale omniauth. Peu importe ce que j'essaie, je ne peux pas obtenir de tests pour travailler.Comment remplacer une variable locale dans un test de contrôleur rspec
Faire une coupe descendant de l'action, comment voulez-vous tester qu'un nouveau est appelé utilisateur par exemple
#cut down version of the authentifications controller code I am attempting to test
def create
omniauth = request.env["omniauth.auth"]
authentification = Authentification.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
....
user = User.new
....
end
#example test
it "should create a new user" do
subject.stub_chain(:request,:env) {{"omniauth.auth" => {'provider' =>1, 'uid' => 2}}}
User.should_receive(:new)
post :create
end
Ce joli petit refactor du auth_hash a bien fonctionné. –