Sha256: dd972abc78060fc9dc9e35eb8af88595a525630b482530d0935e7cef146e3aa4

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

describe ShopifyAPI::Mock do
  
  after(:all) do
    # reset things back to the way they were before these tests ran
    ShopifyAPI::Mock.enabled = false # disable and
    ShopifyAPI::Mock.enabled = true  # re-enable to ensure mocks reset
    ShopifyAPI::Mock.allow_internet = false
  end
  
  describe "#enabled=" do
    context "given true" do
      before { ShopifyAPI::Mock.enabled = true }
      it "should register a response for each fixtures * 2 for the count fixtures" do        
        ShopifyAPI::Mock::Response.all.count.should eq ShopifyAPI::Mock::Fixture.all.count * 2
      end
    end
    
    context "given false" do
      before { ShopifyAPI::Mock.enabled = false }
      it "should clear all registered responses" do
        ShopifyAPI::Mock::Response.all.should be_empty
      end
    end
  end

  describe "#reset" do
    context "while ShopifyAPI::Mock is disabled" do
      it "should raise DisabledError" do
        ShopifyAPI::Mock.enabled = false
        expect { ShopifyAPI::Mock.reset }.to raise_error ShopifyAPI::Mock::DisabledError
      end
    end
    
    context "while ShopifyAPI::Mock is enabled" do
      before { ShopifyAPI::Mock.enabled = true }
      
      it "should reset back to original responses" do
        ShopifyAPI::Mock::Response.clear
        ShopifyAPI::Mock::Response.all.count.should eq 0
        ShopifyAPI::Mock.reset
        ShopifyAPI::Mock::Response.all.count.should > 0
      end
    end
  end
  
  describe "#allow_internet=" do
    context "given true" do
      before { ShopifyAPI::Mock.allow_internet = true }
      it "should allow Internet access" do
        FakeWeb.allow_net_connect?.should eq true
      end
    end
    
    context "given false" do
      before { ShopifyAPI::Mock.allow_internet = false }
      it "should not allow Internet access" do
        FakeWeb.allow_net_connect?.should eq false
      end
    end
  end
  
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
shopify-mock-new-0.1 spec/mock_spec.rb
shopify-mock-0.1.2 spec/mock_spec.rb
shopify-mock-0.1.1 spec/mock_spec.rb