diff --git a/Gemfile b/Gemfile index ad4ced2..01eeac3 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,6 @@ gem 'rake' gem 'rack', '1.3' group :test do - gem 'rspec', '~>2' + gem 'rspec', '~>3' gem 'rack-test' end diff --git a/Gemfile.lock b/Gemfile.lock index d5de6f6..fd9e0a9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,19 +7,24 @@ PATH GEM remote: https://rubygems.org/ specs: - diff-lcs (1.1.3) + diff-lcs (1.2.5) rack (1.3.0) rack-test (0.6.0) rack (>= 1.0) rake (0.8.7) - rspec (2.10.0) - rspec-core (~> 2.10.0) - rspec-expectations (~> 2.10.0) - rspec-mocks (~> 2.10.0) - rspec-core (2.10.1) - rspec-expectations (2.10.0) - diff-lcs (~> 1.1.3) - rspec-mocks (2.10.1) + rspec (3.3.0) + rspec-core (~> 3.3.0) + rspec-expectations (~> 3.3.0) + rspec-mocks (~> 3.3.0) + rspec-core (3.3.2) + rspec-support (~> 3.3.0) + rspec-expectations (3.3.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-mocks (3.3.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-support (3.3.0) PLATFORMS ruby @@ -28,7 +33,7 @@ DEPENDENCIES rack (= 1.3) rack-test rake - rspec (~> 2) + rspec (~> 3) warden! BUNDLED WITH diff --git a/lib/warden/version.rb b/lib/warden/version.rb index 770981f..20deed1 100644 --- a/lib/warden/version.rb +++ b/lib/warden/version.rb @@ -1,4 +1,4 @@ # encoding: utf-8 module Warden - VERSION = "1.2.3".freeze + VERSION = "1.2.4".freeze end diff --git a/spec/warden/authenticated_data_store_spec.rb b/spec/warden/authenticated_data_store_spec.rb index 6adb865..eb5295b 100644 --- a/spec/warden/authenticated_data_store_spec.rb +++ b/spec/warden/authenticated_data_store_spec.rb @@ -16,16 +16,16 @@ app = lambda do |e| e['warden'].authenticate(:pass) e['warden'].authenticate(:pass, :scope => :foo) - e['warden'].should be_authenticated - e['warden'].should be_authenticated(:foo) + expect(e['warden']).to be_authenticated + expect(e['warden']).to be_authenticated(:foo) # Store the data for :default e['warden'].session[:key] = "value" valid_response end setup_rack(app).call(@env) - @env['rack.session']['warden.user.default.session'].should eq({:key => "value"}) - @env['rack.session']['warden.user.foo.session'].should be_nil + expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value") + expect(@env['rack.session']['warden.user.foo.session']).to be_nil end it "should store data for the foo user" do @@ -34,7 +34,7 @@ valid_response end setup_rack(app).call(@env) - @env['rack.session']['warden.user.foo.session'].should eq({:key => "value"}) + expect(@env['rack.session']['warden.user.foo.session']).to eq(key: "value") end it "should store the data separately" do @@ -44,8 +44,8 @@ valid_response end setup_rack(app).call(@env) - @env['rack.session']['warden.user.default.session'].should eq({:key => "value"}) - @env['rack.session']['warden.user.foo.session' ].should eq({:key => "another value"}) + expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value") + expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value") end it "should clear the foo scoped data when foo logs out" do @@ -56,8 +56,8 @@ valid_response end setup_rack(app).call(@env) - @env['rack.session']['warden.user.default.session'].should eq({:key => "value"}) - @env['rack.session']['warden.user.foo.session' ].should be_nil + expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value") + expect(@env['rack.session']['warden.user.foo.session' ]).to be_nil end it "should clear out the default data when :default logs out" do @@ -68,8 +68,8 @@ valid_response end setup_rack(app).call(@env) - @env['rack.session']['warden.user.default.session'].should be_nil - @env['rack.session']['warden.user.foo.session' ].should eq({:key => "another value"}) + expect(@env['rack.session']['warden.user.default.session']).to be_nil + expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value") end it "should clear out all data when a general logout is performed" do @@ -80,8 +80,8 @@ valid_response end setup_rack(app).call(@env) - @env['rack.session']['warden.user.default.session'].should be_nil - @env['rack.session']['warden.user.foo.session' ].should be_nil + expect(@env['rack.session']['warden.user.default.session']).to be_nil + expect(@env['rack.session']['warden.user.foo.session' ]).to be_nil end it "should logout multiple persons at once" do @@ -95,9 +95,9 @@ valid_response end setup_rack(app).call(@env) - @env['rack.session']['warden.user.default.session'].should be_nil - @env['rack.session']['warden.user.foo.session' ].should eq({:key => "another value"}) - @env['rack.session']['warden.user.bar.session' ].should be_nil + expect(@env['rack.session']['warden.user.default.session']).to be_nil + expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value") + expect(@env['rack.session']['warden.user.bar.session' ]).to be_nil end it "should not store data for a user who is not logged in" do @@ -107,8 +107,8 @@ valid_response end - lambda do + expect { setup_rack(app).call(@env) - end.should raise_error(Warden::NotAuthenticated) + }.to raise_error(Warden::NotAuthenticated) end end diff --git a/spec/warden/config_spec.rb b/spec/warden/config_spec.rb index 88792ad..64b378a 100644 --- a/spec/warden/config_spec.rb +++ b/spec/warden/config_spec.rb @@ -9,40 +9,40 @@ it "should behave like a hash" do @config[:foo] = :bar - @config[:foo].should be(:bar) + expect(@config[:foo]).to eq(:bar) end it "should provide hash accessors" do @config.failure_app = :foo - @config[:failure_app].should be(:foo) + expect(@config[:failure_app]).to eq(:foo) @config[:failure_app] = :bar - @config.failure_app.should be(:bar) + expect(@config.failure_app).to eq(:bar) end it "should allow to read and set default strategies" do @config.default_strategies :foo, :bar - @config.default_strategies.should eq([:foo, :bar]) + expect(@config.default_strategies).to eq([:foo, :bar]) end it "should allow to silence missing strategies" do @config.silence_missing_strategies! - @config.silence_missing_strategies?.should be_true + expect(@config.silence_missing_strategies?).to eq(true) end it "should set the default_scope" do - @config.default_scope.should be(:default) + expect(@config.default_scope).to eq(:default) @config.default_scope = :foo - @config.default_scope.should be(:foo) + expect(@config.default_scope).to eq(:foo) end it "should merge given options on initialization" do - Warden::Config.new(:foo => :bar)[:foo].should be(:bar) + expect(Warden::Config.new(:foo => :bar)[:foo]).to eq(:bar) end it "should setup defaults with the scope_defaults method" do c = Warden::Config.new c.scope_defaults :foo, :strategies => [:foo, :bar], :store => false - c.default_strategies(:scope => :foo).should eq([:foo, :bar]) - c.scope_defaults(:foo).should eq({:store => false}) + expect(c.default_strategies(:scope => :foo)).to eq([:foo, :bar]) + expect(c.scope_defaults(:foo)).to eq(store: false) end end diff --git a/spec/warden/errors_spec.rb b/spec/warden/errors_spec.rb index 4866cc0..b4485f1 100644 --- a/spec/warden/errors_spec.rb +++ b/spec/warden/errors_spec.rb @@ -8,40 +8,40 @@ end it "should report that it is empty on first creation" do - @errors.empty?.should be_true + expect(@errors).to be_empty end it "should continue to report that it is empty even after being checked" do @errors.on(:foo) - @errors.empty?.should be_true + expect(@errors).to be_empty end it "should add an error" do @errors.add(:login, "Login or password incorrect") - @errors[:login].should eq(["Login or password incorrect"]) + expect(@errors[:login]).to eq(["Login or password incorrect"]) end it "should allow many errors to be added to the same field" do @errors.add(:login, "bad 1") @errors.add(:login, "bad 2") - @errors.on(:login).should eq(["bad 1", "bad 2"]) + expect(@errors.on(:login)).to eq(["bad 1", "bad 2"]) end it "should give the full messages for an error" do @errors.add(:login, "login wrong") @errors.add(:password, "password wrong") ["password wrong", "login wrong"].each do |msg| - @errors.full_messages.should include(msg) + expect(@errors.full_messages).to include(msg) end end it "should return the error for a specific field / label" do @errors.add(:login, "wrong") - @errors.on(:login).should eq(["wrong"]) + expect(@errors.on(:login)).to eq(["wrong"]) end it "should return nil for a specific field if it's not been set" do - @errors.on(:not_there).should be_nil + expect(@errors.on(:not_there)).to be_nil end end diff --git a/spec/warden/hooks_spec.rb b/spec/warden/hooks_spec.rb index 0befd38..7c9c207 100644 --- a/spec/warden/hooks_spec.rb +++ b/spec/warden/hooks_spec.rb @@ -21,13 +21,13 @@ RAM.after_set_user do |user, auth, opts| "boo" end - RAM._after_set_user.should have(1).item + expect(RAM._after_set_user.length).to eq(1) end it "should allow me to add multiple after_set_user hooks" do RAM.after_set_user{|user, auth, opts| "foo"} RAM.after_set_user{|u,a| "bar"} - RAM._after_set_user.should have(2).items + expect(RAM._after_set_user.length).to eq(2) end it "should run each after_set_user hook after the user is set" do @@ -40,9 +40,9 @@ end env = env_with_params setup_rack(app).call(env) - env['warden'].user.should be_nil - env['warden.spec.hook.foo'].should eq("run foo") - env['warden.spec.hook.bar'].should eq("run bar") + expect(env['warden'].user).to be_nil + expect(env['warden.spec.hook.foo']).to eq("run foo") + expect(env['warden.spec.hook.bar']).to eq("run bar") end it "should not run the event specified with except" do @@ -76,22 +76,22 @@ end env = env_with_params setup_rack(app).call(env) - env['warden.spec.order'].should eq([1,2,3]) + expect(env['warden.spec.order']).to eq([1,2,3]) end context "after_authentication" do it "should be a wrapper to after_set_user behavior" do RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"} RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"} - RAM.after_authentication{|u,a,o| o[:event].should be(:authentication) } + RAM.after_authentication{|u,a,o| expect(o[:event]).to eq(:authentication) } app = lambda do |e| e['warden'].authenticate(:pass) valid_response end env = env_with_params setup_rack(app).call(env) - env['warden.spec.hook.baz'].should eq('run baz') - env['warden.spec.hook.paz'].should eq('run paz') + expect(env['warden.spec.hook.baz']).to eq('run baz') + expect(env['warden.spec.hook.paz']).to eq('run paz') end it "should not be invoked on default after_set_user scenario" do @@ -115,7 +115,7 @@ end env = env_with_params setup_rack(app).call(env) - env['warden.spec.order'].should eq([1,2,3]) + expect(env['warden.spec.order']).to eq([1,2,3]) end it "should allow me to log out a user in an after_set_user block" do @@ -127,7 +127,7 @@ end env = env_with_params setup_rack(app).call(env) - env['warden'].authenticated?.should be_false + expect(env['warden']).not_to be_authenticated end end @@ -135,13 +135,13 @@ it "should be a wrapper to after_set_user behavior" do RAM.after_fetch{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"} RAM.after_fetch{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"} - RAM.after_fetch{|u,a,o| o[:event].should be(:fetch) } + RAM.after_fetch{|u,a,o| expect(o[:event]).to eq(:fetch) } env = env_with_params setup_rack(lambda { |e| valid_response }).call(env) env['rack.session']['warden.user.default.key'] = "Foo" - env['warden'].user.should eq("Foo") - env['warden.spec.hook.baz'].should eq('run baz') - env['warden.spec.hook.paz'].should eq('run paz') + expect(env['warden'].user).to eq("Foo") + expect(env['warden.spec.hook.baz']).to eq('run baz') + expect(env['warden.spec.hook.paz']).to eq('run paz') end it "should not be invoked on default after_set_user scenario" do @@ -159,7 +159,7 @@ env = env_with_params setup_rack(lambda { |e| valid_response }).call(env) env['rack.session']['warden.user.default.key'] = nil - env['warden'].user.should be_nil + expect(env['warden'].user).to be_nil end it "should run filters in the given order" do @@ -174,7 +174,7 @@ end env = env_with_params setup_rack(app).call(env) - env['warden.spec.order'].should eq([1,2,3]) + expect(env['warden.spec.order']).to eq([1,2,3]) end end end @@ -195,7 +195,7 @@ env = env_with_params setup_rack(lambda { |e| valid_response }).call(env) env['rack.session']['warden.user.default.key'] = "Foo" - env['warden'].user.should eq("Foo") + expect(env['warden'].user).to eq("Foo") end it "should be called if fetched user is nil" do @@ -203,8 +203,8 @@ RAM.after_failed_fetch{|u,a,o| calls += 1 } env = env_with_params setup_rack(lambda { |e| valid_response }).call(env) - env['warden'].user.should be_nil - calls.should be(1) + expect(env['warden'].user).to be_nil + expect(calls).to eq(1) end end @@ -220,13 +220,13 @@ it "should allow me to add a before_failure hook" do RAM.before_failure{|env, opts| "foo"} - RAM._before_failure.should have(1).item + expect(RAM._before_failure.length).to eq(1) end it "should allow me to add multiple before_failure hooks" do RAM.before_failure{|env, opts| "foo"} RAM.before_failure{|env, opts| "bar"} - RAM._before_failure.should have(2).items + expect(RAM._before_failure.length).to eq(2) end it "should run each before_failure hooks before failing" do @@ -235,8 +235,8 @@ app = lambda{|e| e['warden'].authenticate!(:failz); valid_response} env = env_with_params setup_rack(app).call(env) - env['warden.spec.before_failure.foo'].should eq("foo") - env['warden.spec.before_failure.bar'].should eq("bar") + expect(env['warden.spec.before_failure.foo']).to eq("foo") + expect(env['warden.spec.before_failure.bar']).to eq("bar") end it "should run filters in the given order" do @@ -250,7 +250,7 @@ end env = env_with_params setup_rack(app).call(env) - env['warden.spec.order'].should eq([1,2,3]) + expect(env['warden.spec.order']).to eq([1,2,3]) end end @@ -266,13 +266,13 @@ it "should allow me to add an before_logout hook" do RAM.before_logout{|user, auth, scopes| "foo"} - RAM._before_logout.should have(1).item + expect(RAM._before_logout.length).to eq(1) end it "should allow me to add multiple after_authentication hooks" do RAM.before_logout{|u,a,o| "bar"} RAM.before_logout{|u,a,o| "baz"} - RAM._before_logout.should have(2).items + expect(RAM._before_logout.length).to eq(2) end it "should run each before_logout hook before logout is run" do @@ -282,8 +282,8 @@ env = env_with_params setup_rack(app).call(env) env['warden'].logout - env['warden.spec.hook.lorem'].should eq('run lorem') - env['warden.spec.hook.ipsum'].should eq('run ipsum') + expect(env['warden.spec.hook.lorem']).to eq('run lorem') + expect(env['warden.spec.hook.ipsum']).to eq('run ipsum') end it "should run before_logout hook for a specified scope" do @@ -301,12 +301,12 @@ setup_rack(app).call(env) env['warden'].logout(:scope1) - env['warden.spec.hook.a'].should eq([:scope1]) - env['warden.spec.hook.b'].should eq([]) + expect(env['warden.spec.hook.a']).to eq([:scope1]) + expect(env['warden.spec.hook.b']).to eq([]) env['warden'].logout(:scope2) - env['warden.spec.hook.a'].should eq([:scope1]) - env['warden.spec.hook.b'].should eq([:scope2]) + expect(env['warden.spec.hook.a']).to eq([:scope1]) + expect(env['warden.spec.hook.b']).to eq([:scope2]) end it "should run filters in the given order" do @@ -321,7 +321,7 @@ end env = env_with_params setup_rack(app).call(env) - env['warden.spec.order'].should eq([1,2,3]) + expect(env['warden.spec.order']).to eq([1,2,3]) end end @@ -339,13 +339,13 @@ it "should allow me to add an on_request hook" do RAM.on_request{|proxy| "foo"} - RAM._on_request.should have(1).item + expect(RAM._on_request.length).to eq(1) end it "should allow me to add multiple on_request hooks" do RAM.on_request{|proxy| "foo"} RAM.on_request{|proxy| "bar"} - RAM._on_request.should have(2).items + expect(RAM._on_request.length).to eq(2) end it "should run each on_request hooks when initializing" do @@ -354,8 +354,8 @@ app = lambda{|e| valid_response} env = env_with_params setup_rack(app).call(env) - env['warden.spec.on_request.foo'].should eq("foo") - env['warden.spec.on_request.bar'].should eq("bar") + expect(env['warden.spec.on_request.foo']).to eq("foo") + expect(env['warden.spec.on_request.bar']).to eq("bar") end it "should run filters in the given order" do @@ -367,7 +367,7 @@ end env = Rack::MockRequest.env_for("/", "warden.spec.order" => []) setup_rack(app).call(env) - env['warden.spec.order'].should eq([1,2,3]) + expect(env['warden.spec.order']).to eq([1,2,3]) end end end diff --git a/spec/warden/manager_spec.rb b/spec/warden/manager_spec.rb index 036bcc5..0a6f667 100644 --- a/spec/warden/manager_spec.rb +++ b/spec/warden/manager_spec.rb @@ -10,7 +10,7 @@ it "should insert a Proxy object into the rack env" do env = env_with_params setup_rack(success_app).call(env) - env["warden"].should be_an_instance_of(Warden::Proxy) + expect(env["warden"]).to be_an_instance_of(Warden::Proxy) end describe "thrown auth" do @@ -35,7 +35,7 @@ throw(:warden, :action => :unauthenticated) end result = setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app? - result.first.should be(401) + expect(result.first).to eq(401) end it "should use the failure message given to the failure method" do @@ -45,7 +45,7 @@ throw(:warden) end result = setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app? - result.last.should eq(["You Fail!"]) + expect(result.last).to eq(["You Fail!"]) end it "should set the message from the winning strategy in warden.options hash" do @@ -55,7 +55,7 @@ throw(:warden) end setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app? - env["warden.options"][:message].should eq("The Fails Strategy Has Failed You") + expect(env["warden.options"][:message]).to eq("The Fails Strategy Has Failed You") end it "should render the failure app when there's a failure" do @@ -66,7 +66,7 @@ [401, {"Content-Type" => "text/plain"}, ["Failure App"]] end result = setup_rack(app, :failure_app => fail_app).call(env_with_params) - result.last.should eq(["Failure App"]) + expect(result.last).to eq(["Failure App"]) end it "should call failure app if warden is thrown even after successful authentication" do @@ -76,8 +76,8 @@ throw(:warden) end result = setup_rack(app, :failure_app => @fail_app).call(env) - result.first.should be(401) - result.last.should eq(["You Fail!"]) + expect(result.first).to eq(401) + expect(result.last).to eq(["You Fail!"]) end it "should set the attempted url in warden.options hash" do @@ -87,8 +87,8 @@ throw(:warden) end result = setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app? - result.first.should be(401) - env["warden.options"][:attempted_path].should eq("/access/path") + expect(result.first).to eq(401) + expect(env["warden.options"][:attempted_path]).to eq("/access/path") end it "should catch a resubmitted request" do @@ -132,9 +132,9 @@ def call(env) end result = builder.to_app.call(env) - result[0].should be(401) - result[2].body.should eq(["Bad"]) - $throw_count.should be(2) + expect(result[0]).to eq(401) + expect(result[2].body).to eq(["Bad"]) + expect($throw_count).to eq(2) end it "should use the default scopes action when a bare throw is used" do @@ -154,8 +154,8 @@ def call(env) :configurator => lambda{ |c| c.scope_defaults(:default, :action => 'my_action', :strategies => [:password]) } ).call(env) - action.should eq("/my_action") - result.first.should be(401) + expect(action).to eq("/my_action") + expect(result.first).to eq(401) end end # failure end @@ -179,9 +179,9 @@ def authenticate! end end result = @app.call(env_with_params) - result[0].should be(302) - result[1]["Location"].should eq("/foo/bar?foo=bar") - result[2].should eq(["custom redirection message"]) + expect(result[0]).to be(302) + expect(result[1]["Location"]).to eq("/foo/bar?foo=bar") + expect(result[2]).to eq(["custom redirection message"]) end it "should redirect with a default message" do @@ -191,9 +191,9 @@ def authenticate! end end result = @app.call(env_with_params) - result[0].should be(302) - result[1]['Location'].should eq("/foo/bar?foo=bar") - result[2].should eq(["You are being redirected to /foo/bar?foo=bar"]) + expect(result[0]).to eq(302) + expect(result[1]['Location']).to eq("/foo/bar?foo=bar") + expect(result[2]).to eq(["You are being redirected to /foo/bar?foo=bar"]) end it "should redirect with a permanent redirect" do @@ -203,7 +203,7 @@ def authenticate! end end result = @app.call(env_with_params) - result[0].should be(301) + expect(result[0]).to eq(301) end it "should redirect with a content type" do @@ -213,9 +213,9 @@ def authenticate! end end result = @app.call(env_with_params) - result[0].should be(302) - result[1]["Location"].should eq("/foo/bar?foo=bar") - result[1]["Content-Type"].should eq("text/xml") + expect(result[0]).to eq(302) + expect(result[1]["Location"]).to eq("/foo/bar?foo=bar") + expect(result[1]["Content-Type"]).to eq("text/xml") end it "should redirect with a default content type" do @@ -225,9 +225,9 @@ def authenticate! end end result = @app.call(env_with_params) - result[0].should be(302) - result[1]["Location"].should eq("/foo/bar?foo=bar") - result[1]["Content-Type"].should eq("text/plain") + expect(result[0]).to eq(302) + expect(result[1]["Location"]).to eq("/foo/bar?foo=bar") + expect(result[1]["Content-Type"]).to eq("text/plain") end end @@ -240,9 +240,9 @@ def authenticate! end env = env_with_params result = @app.call(env) - result[0].should be(401) - result[2].should eq(["You Fail!"]) - env['PATH_INFO'].should eq("/unauthenticated") + expect(result[0]).to eq(401) + expect(result[2]).to eq(["You Fail!"]) + expect(env['PATH_INFO']).to eq("/unauthenticated") end it "should allow you to customize the response" do @@ -252,8 +252,8 @@ def authenticate! end env = env_with_params result = setup_rack(app).call(env) - result[0].should be(401) - result[2].should eq(["Fail From The App"]) + expect(result[0]).to eq(401) + expect(result[2]).to eq(["Fail From The App"]) end it "should allow you to customize the response without the explicit call to custom_failure! if not intercepting 401" do @@ -262,8 +262,8 @@ def authenticate! end env = env_with_params result = setup_rack(app, :intercept_401 => false).call(env) - result[0].should be(401) - result[2].should eq(["Fail From The App"]) + expect(result[0]).to eq(401) + expect(result[2]).to eq(["Fail From The App"]) end it "should render the failure application for a 401 if no custom_failure flag is set" do @@ -271,8 +271,8 @@ def authenticate! [401,{'Content-Type' => 'text/plain'},["Fail From The App"]] end result = setup_rack(app).call(env_with_params) - result[0].should be(401) - result[2].should eq(["You Fail!"]) + expect(result[0]).to eq(401) + expect(result[2]).to eq(["You Fail!"]) end end # failing @@ -285,9 +285,9 @@ def authenticate! end end result = @app.call(env_with_params) - result[0].should be(523) - result[1]["Custom-Header"].should eq("foo") - result[2].should eq(["Custom Stuff"]) + expect(result[0]).to be(523) + expect(result[1]["Custom-Header"]).to eq("foo") + expect(result[2]).to eq(["Custom Stuff"]) end end @@ -299,9 +299,9 @@ def authenticate! end end result = @app.call(env_with_params) - result.status.should be(201) - result.body.should eq(['body']) - result.header['Content-Type'].should eq('text/plain') + expect(result.status).to eq(201) + expect(result.body).to eq(['body']) + expect(result.header['Content-Type']).to eq('text/plain') end end @@ -314,8 +314,8 @@ def authenticate! end env = env_with_params result = @app.call(env) - result[0].should be(200) - result[2].should eq(["Foo Is A Winna"]) + expect(result[0]).to eq(200) + expect(result[2]).to eq(["Foo Is A Winna"]) end end end # integrated strategies @@ -323,9 +323,9 @@ def authenticate! it "should allow me to set a different default scope for warden" do Rack::Builder.new do use Warden::Manager, :default_scope => :default do |manager| - manager.default_scope.should be(:default) + expect(manager.default_scope).to eq(:default) manager.default_scope = :other - manager.default_scope.should be(:other) + expect(manager.default_scope).to eq(:other) end end end @@ -333,7 +333,7 @@ def authenticate! it "should allow me to access strategies through manager" do Rack::Builder.new do use Warden::Manager do |manager| - manager.strategies.should be(Warden::Strategies) + expect(manager.strategies).to eq(Warden::Strategies) end end end diff --git a/spec/warden/proxy_spec.rb b/spec/warden/proxy_spec.rb index 04c3697..caf8f8e 100644 --- a/spec/warden/proxy_spec.rb +++ b/spec/warden/proxy_spec.rb @@ -23,34 +23,34 @@ it "should not check the authentication if it is not checked" do app = setup_rack(@basic_app) - app.call(@env).first.should be(200) + expect(app.call(@env).first).to eq(200) end it "should check the authentication if it is explicitly checked" do app = setup_rack(@authd_app) - app.call(@env).first.should be(401) + expect(app.call(@env).first).to eq(401) end it "should not allow the request if incorrect conditions are supplied" do env = env_with_params("/", :foo => "bar") app = setup_rack(@authd_app) response = app.call(env) - response.first.should be(401) + expect(response.first).to eq(401) end it "should allow the request if the correct conditions are supplied" do env = env_with_params("/", :username => "fred", :password => "sekrit") app = setup_rack(@authd_app) resp = app.call(env) - resp.first.should be(200) + expect(resp.first).to eq(200) end it "should allow authentication in my application" do env = env_with_params('/', :username => "fred", :password => "sekrit") app = lambda do |_env| _env['warden'].authenticate - _env['warden'].should be_authenticated - _env['warden.spec.strategies'].should eq([:password]) + expect(_env['warden']).to be_authenticated + expect(_env['warden.spec.strategies']).to eq([:password]) valid_response end setup_rack(app).call(env) @@ -60,8 +60,8 @@ env = env_with_params("/", :foo => "bar") app = lambda do |_env| _env['warden'].authenticate(:failz) - _env['warden'].should_not be_authenticated - _env['warden.spec.strategies'].should eq([:failz]) + expect(_env['warden']).not_to be_authenticated + expect(_env['warden.spec.strategies']).to eq([:failz]) valid_response end setup_rack(app).call(env) @@ -71,15 +71,15 @@ app = lambda do |env| env['warden'].authenticate(:unknown) end - lambda { + expect { setup_rack(app).call(@env) - }.should raise_error(RuntimeError, "Invalid strategy unknown") + }.to raise_error(RuntimeError, "Invalid strategy unknown") end it "should raise error if the strategy failed" do app = lambda do |env| env['warden'].authenticate(:fail_with_user) - env['warden'].user.should be_nil + expect(env['warden'].user).to be_nil valid_response end setup_rack(app).call(@env) @@ -90,16 +90,16 @@ env['warden'].authenticate valid_response end - lambda { + expect { setup_rack(app, :silence_missing_strategies => true, :default_strategies => [:unknown]).call(@env) - }.should_not raise_error + }.not_to raise_error end it "should allow me to get access to the user at warden.user." do app = lambda do |env| env['warden'].authenticate(:pass) - env['warden'].should be_authenticated - env['warden.spec.strategies'].should eq([:pass]) + expect(env['warden']).to be_authenticated + expect(env['warden.spec.strategies']).to eq([:pass]) valid_response end setup_rack(app).call(@env) @@ -107,10 +107,10 @@ it "should run strategies when authenticate? is asked" do app = lambda do |env| - env['warden'].should_not be_authenticated + expect(env['warden']).not_to be_authenticated env['warden'].authenticate?(:pass) - env['warden'].should be_authenticated - env['warden.spec.strategies'].should eq([:pass]) + expect(env['warden']).to be_authenticated + expect(env['warden.spec.strategies']).to eq([:pass]) valid_response end setup_rack(app).call(@env) @@ -119,8 +119,8 @@ it "should properly send the scope to the strategy" do app = lambda do |env| env['warden'].authenticate(:pass, :scope => :failz) - env['warden'].should_not be_authenticated - env['warden.spec.strategies'].should eq([:pass]) + expect(env['warden']).not_to be_authenticated + expect(env['warden.spec.strategies']).to eq([:pass]) valid_response end setup_rack(app).call(@env) @@ -129,8 +129,8 @@ it "should try multiple authentication strategies" do app = lambda do |env| env['warden'].authenticate(:password,:pass) - env['warden'].should be_authenticated - env['warden.spec.strategies'].should eq([:password, :pass]) + expect(env['warden']).to be_authenticated + expect(env['warden.spec.strategies']).to eq([:password, :pass]) valid_response end setup_rack(app).call(@env) @@ -143,7 +143,7 @@ valid_response end setup_rack(app).call(@env) - @env['warden'].user.should eq("foo as a user") + expect(@env['warden'].user).to eq("foo as a user") end it "should look for an active user in the session with authenticate?" do @@ -153,7 +153,7 @@ valid_response end setup_rack(app).call(@env) - @env['warden'].user(:foo_scope).should eq("a foo user") + expect(@env['warden'].user(:foo_scope)).to eq("a foo user") end it "should look for an active user in the session with authenticate!" do @@ -163,7 +163,7 @@ valid_response end setup_rack(app).call(@env) - @env['warden'].user(:foo_scope).should eq("a foo user") + expect(@env['warden'].user(:foo_scope)).to eq("a foo user") end it "should throw an error when authenticate!" do @@ -178,23 +178,23 @@ app = lambda do |env| env['rack.session']['warden.user.foo.key'] = 'foo user' env['rack.session']['warden.user.bar.key'] = 'bar user' - env['warden'].should be_authenticated(:foo) - env['warden'].should be_authenticated(:bar) - env['warden'].should_not be_authenticated # default scope + expect(env['warden']).to be_authenticated(:foo) + expect(env['warden']).to be_authenticated(:bar) + expect(env['warden']).not_to be_authenticated # default scope valid_response end setup_rack(app).call(@env) - @env['warden'].user(:foo).should eq('foo user') - @env['warden'].user(:bar).should eq('bar user') - @env['warden'].user.should be_nil + expect(@env['warden'].user(:foo)).to eq('foo user') + expect(@env['warden'].user(:bar)).to eq('bar user') + expect(@env['warden'].user).to be_nil end it "should not authenticate other scopes just because the first is authenticated" do app = lambda do |env| env['warden'].authenticate(:pass, :scope => :foo) env['warden'].authenticate(:invalid, :scope => :bar) - env['warden'].should be_authenticated(:foo) - env['warden'].should_not be_authenticated(:bar) + expect(env['warden']).to be_authenticated(:foo) + expect(env['warden']).not_to be_authenticated(:bar) valid_response end setup_rack(app).call(@env) @@ -208,7 +208,7 @@ env["rack.session"]["counter"] += 1 if env["warden.on"] env["warden"].authenticate!(:pass) - env["warden"].should be_authenticated + expect(env["warden"]).to be_authenticated end valid_response end @@ -216,29 +216,29 @@ # Setup a rack app with Pool session. app = setup_rack(app, :session => Rack::Session::Pool).to_app response = app.call(@env) - @env["rack.session"]["counter"].should be(1) + expect(@env["rack.session"]["counter"]).to eq(1) # Ensure a cookie was given back cookie = response[1]["Set-Cookie"] - cookie.should_not be_nil + expect(cookie).not_to be_nil # Ensure a session id was given sid = cookie.match(SID_REGEXP)[1] - sid.should_not be_nil + expect(sid).not_to be_nil # Do another request, giving a cookie but turning on warden authentication env = env_with_params("/", {}, 'rack.session' => @env['rack.session'], "HTTP_COOKIE" => cookie, "warden.on" => true) response = app.call(env) - env["rack.session"]["counter"].should be(2) + expect(env["rack.session"]["counter"]).to be(2) # Regardless of rack version, a cookie should be sent back new_cookie = response[1]["Set-Cookie"] - new_cookie.should_not be_nil + expect(new_cookie).not_to be_nil # And the session id in this cookie should not be the same as the previous one new_sid = new_cookie.match(SID_REGEXP)[1] - new_sid.should_not be_nil - new_sid.should_not eq(sid) + expect(new_sid).not_to be_nil + expect(new_sid).not_to eq(sid) end it "should not renew session when user is fetch" do @@ -246,27 +246,27 @@ env["rack.session"]["counter"] ||= 0 env["rack.session"]["counter"] += 1 env["warden"].authenticate!(:pass) - env["warden"].should be_authenticated + expect(env["warden"]).to be_authenticated valid_response end # Setup a rack app with Pool session. app = setup_rack(app, :session => Rack::Session::Pool).to_app response = app.call(@env) - @env["rack.session"]["counter"].should be(1) + expect(@env["rack.session"]["counter"]).to eq(1) # Ensure a cookie was given back cookie = response[1]["Set-Cookie"] - cookie.should_not be_nil + expect(cookie).not_to be_nil # Ensure a session id was given sid = cookie.match(SID_REGEXP)[1] - sid.should_not be_nil + expect(sid).not_to be_nil # Do another request, passing the cookie. The user should be fetched from cookie. env = env_with_params("/", {}, "HTTP_COOKIE" => cookie) response = app.call(env) - env["rack.session"]["counter"].should be(2) + expect(env["rack.session"]["counter"]).to eq(2) # Depending on rack version, a cookie will be returned with the # same session id or no cookie is given back (becase it did not change). @@ -283,10 +283,10 @@ it "should run strategies just once for a given scope" do app = lambda do |env| env['warden'].authenticate(:password, :pass, :scope => :failz) - env['warden'].should_not be_authenticated(:failz) + expect(env['warden']).not_to be_authenticated(:failz) env['warden'].authenticate(:password, :pass, :scope => :failz) - env['warden'].should_not be_authenticated(:failz) - env['warden.spec.strategies'].should eq([:password, :pass]) + expect(env['warden']).not_to be_authenticated(:failz) + expect(env['warden.spec.strategies']).to eq([:password, :pass]) valid_response end setup_rack(app).call(@env) @@ -297,7 +297,7 @@ env['warden'].authenticate(:password, :pass, :scope => :failz) env['warden'].clear_strategies_cache!(:scope => :failz) env['warden'].authenticate(:password, :pass, :scope => :failz) - env['warden.spec.strategies'].should eq([:password, :pass, :password, :pass]) + expect(env['warden.spec.strategies']).to eq([:password, :pass, :password, :pass]) valid_response end setup_rack(app).call(@env) @@ -308,7 +308,7 @@ env['warden'].authenticate(:password, :pass, :scope => :failz) env['warden'].clear_strategies_cache!(:password, :scope => :failz) env['warden'].authenticate(:password, :pass, :scope => :failz) - env['warden.spec.strategies'].should eq([:password, :pass, :password]) + expect(env['warden.spec.strategies']).to eq([:password, :pass, :password]) valid_response end setup_rack(app).call(@env) @@ -317,10 +317,10 @@ it "should run the strategies several times for different scopes" do app = lambda do |env| env['warden'].authenticate(:password, :pass, :scope => :failz) - env['warden'].should_not be_authenticated(:failz) + expect(env['warden']).not_to be_authenticated(:failz) env['warden'].authenticate(:password, :pass) - env['warden'].should be_authenticated - env['warden.spec.strategies'].should eq([:password, :pass, :password, :pass]) + expect(env['warden']).to be_authenticated + expect(env['warden.spec.strategies']).to eq([:password, :pass, :password, :pass]) valid_response end setup_rack(app).call(@env) @@ -329,9 +329,9 @@ it "should not run strategies until cache is cleaned if latest winning strategy halted" do app = lambda do |env| env['warden'].authenticate(:failz) - env['warden'].should_not be_authenticated + expect(env['warden']).not_to be_authenticated env['warden'].authenticate(:pass) - env['warden'].winning_strategy.message.should eq("The Fails Strategy Has Failed You") + expect(env['warden'].winning_strategy.message).to eq("The Fails Strategy Has Failed You") valid_response end setup_rack(app).call(@env) @@ -341,9 +341,9 @@ session = Warden::SessionSerializer.new(@env) app = lambda do |env| env['warden'].authenticate(:single) - env['warden'].should be_authenticated - env['warden'].user.should eq("Valid User") - session.should_not be_stored(:default) + expect(env['warden']).to be_authenticated + expect(env['warden'].user).to eq("Valid User") + expect(session).not_to be_stored(:default) valid_response end setup_rack(app).call(@env) @@ -354,9 +354,9 @@ it "should store the user into the session" do app = lambda do |env| env['warden'].authenticate(:pass) - env['warden'].should be_authenticated - env['warden'].user.should eq("Valid User") - env['rack.session']["warden.user.default.key"].should eq("Valid User") + expect(env['warden']).to be_authenticated + expect(env['warden'].user).to eq("Valid User") + expect(env['rack.session']["warden.user.default.key"]).to eq("Valid User") valid_response end setup_rack(app).call(@env) @@ -365,9 +365,9 @@ it "should not store the user if the :store option is set to false" do app = lambda do |env| env['warden'].authenticate(:pass, :store => false) - env['warden'].should be_authenticated - env['warden'].user.should eq("Valid User") - env['rack.session']['warden.user.default.key'].should be_nil + expect(env['warden']).to be_authenticated + expect(env['warden'].user).to eq("Valid User") + expect(env['rack.session']['warden.user.default.key']).to be_nil valid_response end setup_rack(app).call(@env) @@ -377,8 +377,8 @@ app = lambda do |env| env['rack.session'] = nil env['warden'].authenticate(:pass, :store => false) - env['warden'].should be_authenticated - env['warden'].user.should eq("Valid User") + expect(env['warden']).to be_authenticated + expect(env['warden'].user).to eq("Valid User") valid_response end setup_rack(app).call(@env) @@ -386,7 +386,7 @@ it "should not run the callbacks when :run_callbacks is false" do app = lambda do |env| - env['warden'].manager.should_not_receive(:_run_callbacks) + expect(env['warden'].manager).not_to receive(:_run_callbacks) env['warden'].authenticate(:run_callbacks => false, :scope => :pass) valid_response end @@ -395,7 +395,7 @@ it "should run the callbacks when :run_callbacks is true" do app = lambda do |env| - env['warden'].manager.should_receive(:_run_callbacks).at_least(:once) + expect(env['warden'].manager).to receive(:_run_callbacks).at_least(:once) env['warden'].authenticate(:pass) valid_response end @@ -404,7 +404,7 @@ it "should run the callbacks by default" do app = lambda do |env| - env['warden'].manager.should_receive(:_run_callbacks).at_least(:once) + expect(env['warden'].manager).to receive(:_run_callbacks).at_least(:once) env['warden'].authenticate(:pass) valid_response end @@ -417,7 +417,7 @@ _app = lambda do |env| env['warden'].lock! env['warden'].authenticate(:pass) - env['warden'].user.should be_nil + expect(env['warden'].user).to be_nil valid_response end end @@ -426,7 +426,7 @@ _app = lambda do |env| env['warden'].authenticate(:pass) env['warden'].lock! - env['warden'].user.should be + expect(env['warden'].user).not_to be_nil valid_response end end @@ -440,7 +440,7 @@ it "should return nil when not logged in" do app = lambda do |env| - env['warden'].user.should be_nil + expect(env['warden'].user).to be_nil valid_response end setup_rack(app).call(@env) @@ -448,18 +448,18 @@ it "should not run strategies when not logged in" do app = lambda do |env| - env['warden'].user.should be_nil - env['warden.spec.strategies'].should be_nil + expect(env['warden'].user).to be_nil + expect(env['warden.spec.strategies']).to be_nil valid_response end setup_rack(app).call(@env) end it "should cache unfound user" do - Warden::SessionSerializer.any_instance.should_receive(:fetch).once + expect_any_instance_of(Warden::SessionSerializer).to receive(:fetch).once app = lambda do |env| - env['warden'].user.should be_nil - env['warden'].user.should be_nil + expect(env['warden'].user).to be_nil + expect(env['warden'].user).to be_nil valid_response end setup_rack(app).call(@env) @@ -473,17 +473,17 @@ it "should take the user from the session when logged in" do app = lambda do |env| - env['warden'].user.should eq("A Previous User") + expect(env['warden'].user).to eq("A Previous User") valid_response end setup_rack(app).call(@env) end it "should cache found user" do - Warden::SessionSerializer.any_instance.should_receive(:fetch).once.and_return "A Previous User" + expect_any_instance_of(Warden::SessionSerializer).to receive(:fetch).once.and_return "A Previous User" app = lambda do |env| - env['warden'].user.should eq("A Previous User") - env['warden'].user.should eq("A Previous User") + expect(env['warden'].user).to eq("A Previous User") + expect(env['warden'].user).to eq("A Previous User") valid_response end setup_rack(app).call(@env) @@ -495,13 +495,13 @@ valid_response end setup_rack(app).call(@env) - @env['warden.spec.strategies'].should_not include(:pass) + expect(@env['warden.spec.strategies']).not_to include(:pass) end describe "run callback option" do it "should not call run_callbacks when we pass a :run_callback => false" do app = lambda do |env| - env['warden'].manager.should_not_receive(:_run_callbacks) + expect(env['warden'].manager).not_to receive(:_run_callbacks) env['warden'].user(:run_callbacks => false) valid_response end @@ -510,7 +510,7 @@ it "should call run_callbacks when we pass a :run_callback => true" do app = lambda do |env| - env['warden'].manager.should_receive(:_run_callbacks).at_least(:once) + expect(env['warden'].manager).to receive(:_run_callbacks).at_least(:once) env['warden'].user(:run_callbacks => true) valid_response end @@ -519,7 +519,7 @@ it "should call run_callbacks by default" do app = lambda do |env| - env['warden'].manager.should_receive(:_run_callbacks).at_least(:once) + expect(env['warden'].manager).to receive(:_run_callbacks).at_least(:once) env['warden'].user valid_response end @@ -542,28 +542,28 @@ @app = setup_rack(@app) @env['warden.spec.which_logout'] = :foo @app.call(@env) - @env['rack.session']['warden.user.default.key'].should eq("default key") - @env['rack.session']['warden.user.foo.key'].should be_nil - @env['rack.session'][:foo].should eq("bar") + expect(@env['rack.session']['warden.user.default.key']).to eq("default key") + expect(@env['rack.session']['warden.user.foo.key']).to be_nil + expect(@env['rack.session'][:foo]).to eq("bar") end it "should logout only the scoped default user" do @app = setup_rack(@app) @env['warden.spec.which_logout'] = :default @app.call(@env) - @env['rack.session']['warden.user.default.key'].should be_nil - @env['rack.session']['warden.user.foo.key'].should eq("foo key") - @env['rack.session'][:foo].should eq("bar") + expect(@env['rack.session']['warden.user.default.key']).to be_nil + expect(@env['rack.session']['warden.user.foo.key']).to eq("foo key") + expect(@env['rack.session'][:foo]).to eq("bar") end it "should clear the session when no argument is given to logout" do - @env['rack.session'].should_not be_nil + expect(@env['rack.session']).not_to be_nil app = lambda do |e| e['warden'].logout valid_response end setup_rack(app).call(@env) - @env['rack.session'].should be_empty + expect(@env['rack.session']).to be_empty end it "should not raise exception if raw_session is nil" do @@ -574,22 +574,22 @@ end it "should clear the user when logging out" do - @env['rack.session'].should_not be_nil + expect(@env['rack.session']).not_to be_nil app = lambda do |e| - e['warden'].user.should_not be_nil + expect(e['warden'].user).not_to be_nil e['warden'].logout - e['warden'].should_not be_authenticated - e['warden'].user.should be_nil + expect(e['warden']).not_to be_authenticated + expect(e['warden'].user).to be_nil valid_response end setup_rack(app).call(@env) - @env['warden'].user.should be_nil + expect(@env['warden'].user).to be_nil end it "should clear the session data when logging out" do - @env['rack.session'].should_not be_nil + expect(@env['rack.session']).not_to be_nil app = lambda do |e| - e['warden'].user.should_not be_nil + expect(e['warden'].user).not_to be_nil e['warden'].session[:foo] = :bar e['warden'].logout valid_response @@ -598,10 +598,10 @@ end it "should clear out the session by calling reset_session! so that plugins can setup their own session clearing" do - @env['rack.session'].should_not be_nil + expect(@env['rack.session']).not_to be_nil app = lambda do |e| - e['warden'].user.should_not be_nil - e['warden'].should_receive(:reset_session!) + expect(e['warden'].user).not_to be_nil + expect(e['warden']).to receive(:reset_session!) e['warden'].logout valid_response end @@ -618,7 +618,7 @@ e['warden'].authenticate! :failz end result = setup_rack(app, :failure_app => failure).call(@env) - result.last.should eq(["The Fails Strategy Has Failed You"]) + expect(result.last).to eq(["The Fails Strategy Has Failed You"]) end it "should allow access to the success message" do @@ -630,7 +630,7 @@ success.call(e) end result = setup_rack(app).call(@env) - result.last.should eq(["The Success Strategy Has Accepted You"]) + expect(result.last).to eq(["The Success Strategy Has Accepted You"]) end it "should not die when accessing a message from a source where no authentication has occurred" do @@ -638,7 +638,7 @@ [200, {"Content-Type" => "text/plain"}, [e['warden'].message]] end result = setup_rack(app).call(@env) - result[2].should eq([nil]) + expect(result[2]).to eq([nil]) end end @@ -646,8 +646,8 @@ it "should return false for authenticated? when there are no valid? strategies" do @env['rack.session'] = {} app = lambda do |e| - e['warden'].authenticate(:invalid).should be_nil - e['warden'].should_not be_authenticated + expect(e['warden'].authenticate(:invalid)).to be_nil + expect(e['warden']).not_to be_authenticated end setup_rack(app).call(@env) end @@ -655,7 +655,7 @@ it "should return nil for authenticate when there are no valid strategies" do @env['rack.session'] = {} app = lambda do |e| - e['warden'].authenticate(:invalid).should be_nil + expect(e['warden'].authenticate(:invalid)).to be_nil end setup_rack(app).call(@env) end @@ -663,7 +663,7 @@ it "should return false for authenticate? when there are no valid strategies" do @env['rack.session'] = {} app = lambda do |e| - e['warden'].authenticate?(:invalid).should be_false + expect(e['warden'].authenticate?(:invalid)).to eq(false) end setup_rack(app).call(@env) end @@ -674,7 +674,7 @@ e['warden'].authenticate!(:invalid) end result = setup_rack(app).call(@env) - result.first.should be(401) + expect(result.first).to eq(401) end end @@ -687,7 +687,7 @@ it "should return true when authenticated in the session" do app = lambda do |e| - e['warden'].should be_authenticated + expect(e['warden']).to be_authenticated end setup_rack(app).call(@env) end @@ -699,7 +699,7 @@ end end setup_rack(app).call(@env) - $captures.should eq([:in_the_block]) + expect($captures).to eq([:in_the_block]) end it "should authenticate for a user in a different scope" do @@ -710,7 +710,7 @@ end end setup_rack(app).call(@env) - $captures.should eq([:in_the_foo_block]) + expect($captures).to eq([:in_the_foo_block]) end end @@ -722,7 +722,7 @@ it "should return false when authenticated in the session" do app = lambda do |e| - e['warden'].should_not be_authenticated + expect(e['warden']).not_to be_authenticated end setup_rack(app).call(@env) end @@ -736,7 +736,7 @@ valid_response end setup_rack(app).call(@env) - @env['warden'].user(:foo_scope).should be_nil + expect(@env['warden'].user(:foo_scope)).to be_nil ensure Warden::Manager.serialize_from_session { |k| k } end @@ -749,7 +749,7 @@ end end setup_rack(app).call(@env) - $captures.should eq([]) + expect($captures).to eq([]) end it "should not yield for a user in a different scope" do @@ -759,7 +759,7 @@ end end setup_rack(app).call(@env) - $captures.should eq([]) + expect($captures).to eq([]) end end end @@ -773,7 +773,7 @@ it "should return false when authenticated in the session" do app = lambda do |e| - e['warden'].should_not be_unauthenticated + expect(e['warden']).not_to be_unauthenticated end _result = setup_rack(app).call(@env) end @@ -785,7 +785,7 @@ end end setup_rack(app).call(@env) - $captures.should eq([]) + expect($captures).to eq([]) end it "should not yield to the block for a user in a different scope" do @@ -796,7 +796,7 @@ end end setup_rack(app).call(@env) - $captures.should eq([]) + expect($captures).to eq([]) end end @@ -808,7 +808,7 @@ it "should return false when unauthenticated in the session" do app = lambda do |e| - e['warden'].should be_unauthenticated + expect(e['warden']).to be_unauthenticated end setup_rack(app).call(@env) end @@ -820,7 +820,7 @@ end end setup_rack(app).call(@env) - $captures.should eq([:in_the_block]) + expect($captures).to eq([:in_the_block]) end it "should yield for a user in a different scope" do @@ -830,7 +830,7 @@ end end setup_rack(app).call(@env) - $captures.should eq([:in_the_bar_block]) + expect($captures).to eq([:in_the_bar_block]) end end end @@ -842,7 +842,7 @@ def def_app(&blk) it "should have a config attribute" do app = def_app do |e| - e['warden'].config.should be_a_kind_of(Hash) + expect(e['warden'].config).to be_a_kind_of(Hash) valid_response end app.call(@env) @@ -890,27 +890,27 @@ def wrap_app(app, &blk) it "should allow me to change the default strategies on the fly" do app = wrap_app(@app) do |e| - e['warden'].default_strategies.should eq([:password]) - e['warden'].config.default_strategies.should eq([:password]) + expect(e['warden'].default_strategies).to eq([:password]) + expect(e['warden'].config.default_strategies).to eq([:password]) e['warden'].default_strategies :one e['warden'].authenticate! Rack::Response.new("OK").finish end setup_rack(app).call(@env) - $captures.should eq([:one]) + expect($captures).to eq([:one]) end it "should allow me to append to the default strategies on the fly" do app = wrap_app(@app) do |e| e['warden'].default_strategies << :one - e['warden'].default_strategies.should eq([:password, :one]) + expect(e['warden'].default_strategies).to eq([:password, :one]) e['warden'].authenticate! Rack::Response.new("OK").finish end setup_rack(app).call(@env) - $captures.should eq([:one]) + expect($captures).to eq([:one]) end it "should allow me to set the default strategies on a per scope basis" do @@ -918,15 +918,15 @@ def wrap_app(app, &blk) w = e['warden'] w.default_strategies(:two, :one, :scope => :foo) w.default_strategies(:two, :scope => :default) - w.default_strategies(:scope => :foo).should eq([:two, :one]) + expect(w.default_strategies(:scope => :foo)).to eq([:two, :one]) w.authenticate(:scope => :foo) - $captures.should eq([:two, :one]) + expect($captures).to eq([:two, :one]) $captures.clear w.authenticate - $captures.should eq([:two]) + expect($captures).to eq([:two]) end setup_rack(app).call(@env) - $captures.should eq([:two]) + expect($captures).to eq([:two]) end it "should allow me to setup default strategies for each scope on the manager" do @@ -945,20 +945,20 @@ def wrap_app(app, &blk) end) end builder.to_app.call(@env) - $captures.should eq([:one, :two, :one, :complete]) + expect($captures).to eq([:one, :two, :one, :complete]) end it "should not change the master configurations strategies when I change them" do app = wrap_app(@app) do |e| e['warden'].default_strategies << :one - e['warden'].default_strategies.should eq([:password, :one]) - e['warden'].manager.config.default_strategies.should eq([:password]) + expect(e['warden'].default_strategies).to eq([:password, :one]) + expect(e['warden'].manager.config.default_strategies).to eq([:password]) e['warden'].authenticate! Rack::Response.new("OK").finish end setup_rack(app).call(@env) - $captures.should eq([:one]) + expect($captures).to eq([:one]) end describe "default scope options" do @@ -980,7 +980,7 @@ def wrap_app(app, &blk) env["rack.session"] = {} builder.to_app.call(env) request = Rack::Request.new(env) - request.path.should eq("/some_bad_action") + expect(request.path).to eq("/some_bad_action") end it "should allow me to set store, false on a given scope" do @@ -1009,17 +1009,17 @@ def wrap_app(app, &blk) end session = @env["rack.session"] = {} builder.to_app.call(@env) - $captures.should include(:complete) + expect($captures).to include(:complete) w = warden.first - w.user.should eq("User") - w.user(:foo).should eq("User") - w.user(:bar).should eq("User") - w.user(:baz).should eq("User") - session['warden.user.default.key'].should eq("User") - session['warden.user.foo.key'].should eq("User") - session.key?('warden.user.bar.key').should be_false - session['warden.user.bar.key'].should be_nil - session['warden.user.baz.key'].should eq("User") + expect(w.user).to eq("User") + expect(w.user(:foo)).to eq("User") + expect(w.user(:bar)).to eq("User") + expect(w.user(:baz)).to eq("User") + expect(session['warden.user.default.key']).to eq("User") + expect(session['warden.user.foo.key']).to eq("User") + expect(session.key?('warden.user.bar.key')).to eq(false) + expect(session['warden.user.bar.key']).to be_nil + expect(session['warden.user.baz.key']).to eq("User") end end @@ -1034,8 +1034,8 @@ def wrap_app(app, &blk) setup_rack(success_app).call(env) proxy = env["warden"] - proxy.env['PATH_INFO'].should match(@asset_regex) - proxy.should be_asset_request + expect(proxy.env['PATH_INFO']).to match(@asset_regex) + expect(proxy).to be_asset_request end it "should return false if PATH_INFO is not in asset list" do @@ -1043,8 +1043,8 @@ def wrap_app(app, &blk) setup_rack(success_app).call(env) proxy = env["warden"] - proxy.env['PATH_INFO'].should_not match(@asset_regex) - proxy.should_not be_asset_request + expect(proxy.env['PATH_INFO']).not_to match(@asset_regex) + expect(proxy).not_to be_asset_request end end end diff --git a/spec/warden/session_serializer_spec.rb b/spec/warden/session_serializer_spec.rb index 8f660c0..41e536d 100644 --- a/spec/warden/session_serializer_spec.rb +++ b/spec/warden/session_serializer_spec.rb @@ -10,44 +10,44 @@ it "should store data for the default scope" do @session.store("user", :default) - @env['rack.session'].should eq({ "warden.user.default.key"=>"user" }) + expect(@env['rack.session']).to eq({ "warden.user.default.key"=>"user" }) end it "should check if a data is stored or not" do - @session.should_not be_stored(:default) + expect(@session).not_to be_stored(:default) @session.store("user", :default) - @session.should be_stored(:default) + expect(@session).to be_stored(:default) end it "should load an user from store" do - @session.fetch(:default).should be_nil + expect(@session.fetch(:default)).to be_nil @session.store("user", :default) - @session.fetch(:default).should eq("user") + expect(@session.fetch(:default)).to eq("user") end it "should store data based on the scope" do @session.store("user", :default) - @session.fetch(:default).should eq("user") - @session.fetch(:another).should be_nil + expect(@session.fetch(:default)).to eq("user") + expect(@session.fetch(:another)).to be_nil end it "should delete data from store" do @session.store("user", :default) - @session.fetch(:default).should eq("user") + expect(@session.fetch(:default)).to eq("user") @session.delete(:default) - @session.fetch(:default).should be_nil + expect(@session.fetch(:default)).to be_nil end it "should delete information from store if user cannot be retrieved" do @session.store("user", :default) - @env['rack.session'].should have_key("warden.user.default.key") - @session.stub(:deserialize) { nil } + expect(@env['rack.session']).to have_key("warden.user.default.key") + allow(@session).to receive(:deserialize).and_return(nil) @session.fetch(:default) - @env['rack.session'].should_not have_key("warden.user.default.key") + expect(@env['rack.session']).not_to have_key("warden.user.default.key") end it "should support a nil session store" do @env['rack.session'] = nil - @session.fetch(:default).should be_nil + expect(@session.fetch(:default)).to be_nil end end diff --git a/spec/warden/strategies/base_spec.rb b/spec/warden/strategies/base_spec.rb index 5235f28..49c0a7a 100644 --- a/spec/warden/strategies/base_spec.rb +++ b/spec/warden/strategies/base_spec.rb @@ -17,7 +17,7 @@ def authenticate! end strategy = Warden::Strategies[:foo].new(env_with_params) strategy._run! - strategy.headers["foo"].should eq("bar") + expect(strategy.headers["foo"]).to eq("bar") end it "should allow us to clear the headers" do @@ -28,9 +28,9 @@ def authenticate! end strategy = Warden::Strategies[:foo].new(env_with_params) strategy._run! - strategy.headers["foo"].should eq("bar") + expect(strategy.headers["foo"]).to eq("bar") strategy.headers.clear - strategy.headers.should be_empty + expect(strategy.headers).to be_empty end end @@ -42,7 +42,7 @@ def authenticate! end strategy = RAS[:foobar].new(env_with_params) strategy._run! - strategy.user.should eq("foo") + expect(strategy.user).to eq("foo") end it "should be performed after run" do @@ -50,17 +50,17 @@ def authenticate! def authenticate!; end end strategy = RAS[:foobar].new(env_with_params) - strategy.should_not be_performed + expect(strategy).not_to be_performed strategy._run! - strategy.should be_performed + expect(strategy).to be_performed strategy.clear! - strategy.should_not be_performed + expect(strategy).not_to be_performed end it "should set the scope" do RAS.add(:foobar) do def authenticate! - self.scope.should be(:user) # TODO: Not being called at all. What's this? + expect(self.scope).to eq(:user) # TODO: Not being called at all. What's this? end end _strategy = RAS[:foobar].new(env_with_params, :user) @@ -74,7 +74,7 @@ def authenticate! end strategy = RAS[:foobar].new(env_with_params) strategy._run! - strategy.message.should eq("foo message") + expect(strategy.message).to eq("foo message") end it "should provide access to the errors" do @@ -87,7 +87,7 @@ def authenticate! env['warden'] = Warden::Proxy.new(env, Warden::Manager.new({})) strategy = RAS[:foobar].new(env) strategy._run! - strategy.errors.on(:foo).should eq(["foo has an error"]) + expect(strategy.errors.on(:foo)).to eq(["foo has an error"]) end describe "halting" do @@ -99,7 +99,7 @@ def authenticate! end str = RAS[:foobar].new(env_with_params) str._run! - str.should be_halted + expect(str).to be_halted end it "should not be halted if halt was not called" do @@ -110,7 +110,7 @@ def authenticate! end str = RAS[:foobar].new(env_with_params) str._run! - str.should_not be_halted + expect(str).not_to be_halted end end @@ -124,8 +124,8 @@ def authenticate! end str = RAS[:foobar].new(env_with_params) str._run! - str.should_not be_halted - str.user.should be_nil + expect(str).not_to be_halted + expect(str.user).to be_nil end end @@ -138,7 +138,7 @@ def authenticate! end str = RAS[:foobar].new(env_with_params) str._run! - str.user.should be_nil + expect(str.user).to be_nil end it "should mark the strategy as halted when redirecting" do @@ -149,7 +149,7 @@ def authenticate! end str = RAS[:foobar].new(env_with_params) str._run! - str.should be_halted + expect(str).to be_halted end it "should escape redirected url parameters" do @@ -160,7 +160,7 @@ def authenticate! end str = RAS[:foobar].new(env_with_params) str._run! - str.headers["Location"].should eq("/foo/bar?foo=bar") + expect(str.headers["Location"]).to eq("/foo/bar?foo=bar") end it "should allow you to set a message" do @@ -171,8 +171,8 @@ def authenticate! end str = RAS[:foobar].new(env_with_params) str._run! - str.headers["Location"].should eq("/foo/bar?foo=bar") - str.message.should eq("You are being redirected foo") + expect(str.headers["Location"]).to eq("/foo/bar?foo=bar") + expect(str.message).to eq("You are being redirected foo") end it "should set the action as :redirect" do @@ -183,7 +183,7 @@ def authenticate! end str = RAS[:foobar].new(env_with_params) str._run! - str.result.should be(:redirect) + expect(str.result).to be(:redirect) end end @@ -207,42 +207,42 @@ def authenticate! it "should allow you to fail hard" do @hard._run! - @hard.user.should be_nil + expect(@hard.user).to be_nil end it "should halt the strategies when failing hard" do @hard._run! - @hard.should be_halted + expect(@hard).to be_halted end it "should allow you to set a message when failing hard" do @hard._run! - @hard.message.should eq("You are not cool enough") + expect(@hard.message).to eq("You are not cool enough") end it "should set the action as :failure when failing hard" do @hard._run! - @hard.result.should be(:failure) + expect(@hard.result).to be(:failure) end it "should allow you to fail soft" do @soft._run! - @soft.user.should be_nil + expect(@soft.user).to be_nil end it "should not halt the strategies when failing soft" do @soft._run! - @soft.should_not be_halted + expect(@soft).not_to be_halted end it "should allow you to set a message when failing soft" do @soft._run! - @soft.message.should eq("You are too soft") + expect(@soft.message).to eq("You are too soft") end it "should set the action as :failure when failing soft" do @soft._run! - @soft.result.should be(:failure) + expect(@soft.result).to be(:failure) end end @@ -262,22 +262,22 @@ def authenticate! it "should be authenticated after success" do @str._run! - @str.user.should_not be_nil + expect(@str.user).not_to be_nil end it "should allow you to set a message when succeeding" do @str._run! - @str.message.should eq("Welcome to the club!") + expect(@str.message).to eq("Welcome to the club!") end it "should store the user" do @str._run! - @str.user.should eq("Foo User") + expect(@str.user).to eq("Foo User") end it "should set the action as :success" do @str._run! - @str.result.should be(:success) + expect(@str.result).to be(:success) end end @@ -293,20 +293,20 @@ def authenticate! end it "should allow me to set a custom rack response" do - @str.user.should be_nil + expect(@str.user).to be_nil end it "should halt the strategy" do - @str.should be_halted + expect(@str).to be_halted end it "should provide access to the custom rack response" do - @str.custom_response.should eq([521, {"foo" => "bar"}, ["BAD"]]) + expect(@str.custom_response).to eq([521, {"foo" => "bar"}, ["BAD"]]) end it "should set the action as :custom" do @str._run! - @str.result.should be(:custom) + expect(@str.result).to eq(:custom) end end diff --git a/spec/warden/strategies_spec.rb b/spec/warden/strategies_spec.rb index e1b9066..eb487b8 100644 --- a/spec/warden/strategies_spec.rb +++ b/spec/warden/strategies_spec.rb @@ -8,14 +8,14 @@ def authenticate! success("foo") end end - Warden::Strategies[:strategy1].ancestors.should include(Warden::Strategies::Base) + expect(Warden::Strategies[:strategy1].ancestors).to include(Warden::Strategies::Base) end it "should raise an error if I add a strategy via a block, that does not have an authenticate! method" do - lambda do + expect { Warden::Strategies.add(:strategy2) do end - end.should raise_error + }.to raise_error(NoMethodError) end it "should raise an error if I add a strategy that does not extend Warden::Strategies::Base" do @@ -33,25 +33,26 @@ def authenticate! def authenticate!; end end strategy = Warden::Strategies[:strategy3] - strategy.should_not be_nil - strategy.ancestors.should include(Warden::Strategies::Base) + expect(strategy).not_to be_nil + expect(strategy.ancestors).to include(Warden::Strategies::Base) end it "should allow me to add a strategy with the required methods" do class MyStrategy < Warden::Strategies::Base def authenticate!; end end - lambda do + + expect { Warden::Strategies.add(:strategy4, MyStrategy) - end.should_not raise_error + }.not_to raise_error end it "should not allow a strategy that does not have an authenticate! method" do class MyOtherStrategy end - lambda do + expect { Warden::Strategies.add(:strategy5, MyOtherStrategy) - end.should raise_error + }.to raise_error(NoMethodError) end it "should allow me to change a class when providing a block and class" do @@ -62,7 +63,7 @@ class MyStrategy < Warden::Strategies::Base def authenticate!; end end - Warden::Strategies[:foo].ancestors.should include(MyStrategy) + expect(Warden::Strategies[:foo].ancestors).to include(MyStrategy) end it "should allow me to update a previously given strategy" do @@ -77,7 +78,7 @@ def authenticate!; end include new_module end - Warden::Strategies[:strategy6].ancestors.should include(new_module) + expect(Warden::Strategies[:strategy6].ancestors).to include(new_module) end it "should allow me to clear the strategies" do @@ -86,8 +87,8 @@ def authenticate! :foo end end - Warden::Strategies[:foobar].should_not be_nil + expect(Warden::Strategies[:foobar]).not_to be_nil Warden::Strategies.clear! - Warden::Strategies[:foobar].should be_nil + expect(Warden::Strategies[:foobar]).to be_nil end end diff --git a/spec/warden/test/helpers_spec.rb b/spec/warden/test/helpers_spec.rb index 213a964..2905c3f 100644 --- a/spec/warden/test/helpers_spec.rb +++ b/spec/warden/test/helpers_spec.rb @@ -10,12 +10,12 @@ login_as user app = lambda{|e| $captures << :run - e['warden'].should be_authenticated - e['warden'].user.should eq("A User") + expect(e['warden']).to be_authenticated + expect(e['warden'].user).to eq("A User") valid_response } setup_rack(app).call(env_with_params) - $captures.should eq([:run]) + expect($captures).to eq([:run]) end it "should log me in as a user of a given scope" do @@ -24,11 +24,11 @@ app = lambda{|e| $captures << :run w = e['warden'] - w.should be_authenticated(:foo_scope) - w.user(:foo_scope).should eq({:some => "user"}) + expect(w).to be_authenticated(:foo_scope) + expect(w.user(:foo_scope)).to eq(some: "user") } setup_rack(app).call(env_with_params) - $captures.should eq([:run]) + expect($captures).to eq([:run]) end it "should login multiple users with different scopes" do @@ -39,13 +39,13 @@ app = lambda{|e| $captures << :run w = e['warden'] - w.user.should eq("A user") - w.user(:foo).should eq("A foo user") - w.should be_authenticated - w.should be_authenticated(:foo) + expect(w.user).to eq("A user") + expect(w.user(:foo)).to eq("A foo user") + expect(w).to be_authenticated + expect(w).to be_authenticated(:foo) } setup_rack(app).call(env_with_params) - $captures.should eq([:run]) + expect($captures).to eq([:run]) end it "should log out all users" do @@ -56,16 +56,16 @@ app = lambda{|e| $captures << :run w = e['warden'] - w.user.should eq("A user") - w.user(:foo).should eq("Foo") + expect(w.user).to eq("A user") + expect(w.user(:foo)).to eq("Foo") w.logout - w.user.should be_nil - w.user(:foo).should be_nil - w.should_not be_authenticated - w.should_not be_authenticated(:foo) + expect(w.user).to be_nil + expect(w.user(:foo)).to be_nil + expect(w).not_to be_authenticated + expect(w).not_to be_authenticated(:foo) } setup_rack(app).call(env_with_params) - $captures.should eq([:run]) + expect($captures).to eq([:run]) end it "should logout a specific user" do @@ -77,17 +77,17 @@ $captures << :run w = e['warden'] w.logout :foo - w.user.should eq("A User") - w.user(:foo).should be_nil - w.should_not be_authenticated(:foo) + expect(w.user).to eq("A User") + expect(w.user(:foo)).to be_nil + expect(w).not_to be_authenticated(:foo) } setup_rack(app).call(env_with_params) - $captures.should eq([:run]) + expect($captures).to eq([:run]) end describe "#asset_paths" do it "should default asset_paths to anything asset path regex" do - Warden.asset_paths.should eq([/^\/assets\//] ) + expect(Warden.asset_paths).to eq([/^\/assets\//] ) end end end diff --git a/spec/warden/test/test_mode_spec.rb b/spec/warden/test/test_mode_spec.rb index bd4c05e..2f3590c 100644 --- a/spec/warden/test/test_mode_spec.rb +++ b/spec/warden/test/test_mode_spec.rb @@ -15,9 +15,9 @@ Warden.test_reset! end - it{ Warden.should respond_to(:test_mode!) } - it{ Warden.should respond_to(:on_next_request) } - it{ Warden.should respond_to(:test_reset!) } + it{ expect(Warden).to respond_to(:test_mode!) } + it{ expect(Warden).to respond_to(:on_next_request) } + it{ expect(Warden).to respond_to(:test_reset!) } it "should execute the on_next_request block on the next request" do Warden.on_next_request do |warden| @@ -25,36 +25,35 @@ end setup_rack(@app).call(env_with_params) - $captures.should have(1).item - $captures.first.should be_an_instance_of(Warden::Proxy) + expect($captures.length).to eq(1) + expect($captures.first).to be_an_instance_of(Warden::Proxy) end it "should execute many on_next_request blocks on the next request" do Warden.on_next_request{|w| $captures << :first } Warden.on_next_request{|w| $captures << :second } setup_rack(@app).call(env_with_params) - $captures.should have(2).items - $captures.should eq([:first, :second]) + expect($captures).to eq([:first, :second]) end it "should not execute on_next_request blocks on subsequent requests" do app = setup_rack(@app) Warden.on_next_request{|w| $captures << :first } app.call(env_with_params) - $captures.should eq([:first]) + expect($captures).to eq([:first]) $captures.clear app.call(env_with_params) - $captures.should be_empty + expect($captures).to be_empty end it "should allow me to set new_on_next_request items to execute in the same test" do app = setup_rack(@app) Warden.on_next_request{|w| $captures << :first } app.call(env_with_params) - $captures.should eq([:first]) + expect($captures).to eq([:first]) Warden.on_next_request{|w| $captures << :second } app.call(env_with_params) - $captures.should eq([:first, :second]) + expect($captures).to eq([:first, :second]) end it "should remove the on_next_request items when test is reset" do @@ -62,7 +61,7 @@ Warden.on_next_request{|w| $captures << :first } Warden.test_reset! app.call(env_with_params) - $captures.should eq([]) + expect($captures).to eq([]) end context "asset requests" do @@ -70,7 +69,7 @@ app = setup_rack(@app) Warden.on_next_request{|w| $captures << :first } app.call(env_with_params("/assets/fun.gif")) - $captures.should eq([]) + expect($captures).to eq([]) end end end