Sha256: c83f2e899bbc1aa9becd715da9ef0a7cfc68aab5a5c37943ce4c12662484ed26

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe Restfulie::Client::StackNavigator do
  
  context "when navigating through the filter list" do
    
    class DoNothing
      def execute(stack, *args)
      end
    end
    
    class InvokeNext
      def execute(stack, *args)
        stack.continue(*args)
      end
    end
    
    it "should invoke the first one" do
      do_nothing = DoNothing.new
      DoNothing.should_receive(:new).and_return(do_nothing)
      parser = Restfulie::Client::StackNavigator.new([:type => DoNothing])
      def parser.dup
        self
      end
      
      args = [:req, :env]

      do_nothing.should_receive(:execute).with(parser, *args)
      parser.continue(*args)
    end

    it "should invoke first the most recent ones" do
      do_nothing = DoNothing.new
      DoNothing.should_receive(:new).and_return(do_nothing)
      parser = Restfulie::Client::StackNavigator.new([:type => InvokeNext, :type => DoNothing])
      def parser.dup
        self
      end
      
      args = [:req, :env]

      do_nothing.should_receive(:execute).with(parser, *args)
      parser.continue(*args)
    end
    
  end
  
  class Client
    def initialize(name)
      @name = name
    end
    attr_reader :name
  end

  class Owner
    def initialize(name = "adriano")
      @name = name
    end
    attr_reader :name
  end

  context "when instantiating filters" do
    it "should pass on the arg" do
      instantiator = Restfulie::Client::BasicInstantiator.new
      client = instantiator.new Client, "guilherme"
      client.name.should == "guilherme"
    end
    it "should be capable of instantiating with no args" do
      instantiator = Restfulie::Client::BasicInstantiator.new
      client = instantiator.new Owner, nil
      client.name.should == "adriano"
    end
  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
restfulie-nosqlite-1.0.4 spec/unit/client/stack_navigator.rb
restfulie-1.1.1 spec/unit/client/stack_navigator.rb
restfulie-1.1.0 spec/unit/client/stack_navigator.rb
restfulie-nosqlite-1.0.3 spec/unit/client/stack_navigator.rb
restfulie-1.0.3 spec/unit/client/stack_navigator.rb