Sha256: 90d54e5730cb9920a47d91edab5ce2f9d03cd3053aa09694902568cc6cf06c34

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require "spec_helper"

describe ShippingEasy::Resources::Base do

  class GenericResource < ShippingEasy::Resources::Base; end

  describe ".command" do
    before { GenericResource.command(:create, method: :post) }

    it "defines a method on the class" do
      GenericResource.should respond_to(:create)
    end

    it "extracts options to send to a request" do

    end

    context "when a block is provided" do
      it "uses it as the value for the path" do
        GenericResource.command(:create, method: :post) do |args|
          "/this/is/the/path"
        end
        GenericResource.should_receive(:execute_request!).with({:relative_path=>"/this/is/the/path", :http_method=>:get})
        GenericResource.create
      end

      context "and an argument is passed in" do
        it "interpolates it" do
          GenericResource.command(:create, method: :post) do |args|
            "/this/is/the/#{args.delete(:name)}"
          end
          GenericResource.should_receive(:execute_request!).with({:relative_path=>"/this/is/the/ABC123", :http_method=>:get})
          GenericResource.create(name: "ABC123")
        end
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shipping_easy-0.2.2 spec/resources/base_spec.rb
shipping_easy-0.2.1 spec/resources/base_spec.rb
shipping_easy-0.2.0 spec/resources/base_spec.rb