Sha256: 10c5c4325985e480dc693e3eb2eccfda717f0b9eb3be6ebe892af9d1f555e06e

Contents?: true

Size: 1.87 KB

Versions: 26

Compression:

Stored size: 1.87 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe Warden::Test::WardenHelpers do
  before :all do
    Warden.test_mode!
  end

  before do
    $captures = []
    @app = lambda{|e| valid_response }
  end

  after do
    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 "should execute the on_next_request block on the next request" do
    Warden.on_next_request do |warden|
      $captures << warden
    end

    setup_rack(@app).call(env_with_params)
    $captures.should have(1).item
    $captures.first.should 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 == [: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 == [:first]
    $captures.clear
    app.call(env_with_params)
    $captures.should 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 == [:first]
    Warden.on_next_request{|w| $captures << :second }
    app.call(env_with_params)
    $captures.should == [:first, :second]
  end

  it "should remove the on_next_request items when test is reset" do
    app = setup_rack(@app)
    Warden.on_next_request{|w| $captures << :first }
    Warden.test_reset!
    app.call(env_with_params)
    $captures.should == []
  end
end

Version data entries

26 entries across 26 versions & 3 rubygems

Version Path
devise_sociable-0.1.0 vendor/bundle/gems/warden-1.0.6/spec/warden/test/test_mode_spec.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/warden-1.1.1/spec/warden/test/test_mode_spec.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/warden-1.1.1/spec/warden/test/test_mode_spec.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/warden-1.1.1/spec/warden/test/test_mode_spec.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/warden-1.1.1/spec/warden/test/test_mode_spec.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/warden-1.1.1/spec/warden/test/test_mode_spec.rb
warden-1.1.1 spec/warden/test/test_mode_spec.rb
warden-1.1.0 spec/warden/test/test_mode_spec.rb
warden-1.0.6 spec/warden/test/test_mode_spec.rb
warden-1.0.5 spec/warden/test/test_mode_spec.rb
warden-1.0.4 spec/warden/test/test_mode_spec.rb
warden-1.0.3 spec/warden/test/test_mode_spec.rb
warden-1.0.2 spec/warden/test/test_mode_spec.rb
warden-1.0.1 spec/warden/test/test_mode_spec.rb
warden-1.0.0 spec/warden/test/test_mode_spec.rb
warden-0.10.7 spec/warden/test/test_mode_spec.rb
warden-0.10.6 spec/warden/test/test_mode_spec.rb
warden-0.10.5 spec/warden/test/test_mode_spec.rb
warden-0.10.4 spec/warden/test/test_mode_spec.rb
warden-0.10.3 spec/warden/test/test_mode_spec.rb