Module: ShopifyAPI::Mock
- Defined in:
- lib/shopify-mock.rb,
lib/shopify-mock/errors.rb,
lib/shopify-mock/fixtures.rb,
lib/shopify-mock/response.rb
Overview
the main module for managing the Shopify mocks
Defined Under Namespace
Classes: DisabledError, Fixture, Response
Class Method Summary collapse
-
.allow_internet=(state = true) ⇒ Boolean
enables or disables access to the real Internet.
-
.allow_internet? ⇒ Boolean
gets the state of access to the real Internet.
-
.enabled=(value = false) ⇒ Boolean
enable or disable ShopifyAPI::Mock.
-
.enabled? ⇒ Boolean
get the enabled state of ShopifyAPI::Mock.
-
.register_fixed_responses ⇒ Array
private
registers all the fixed responses.
-
.reset ⇒ Boolean
resets the ShopifyAPI::Mocks back to their original state.
Class Method Details
.allow_internet=(state = true) ⇒ Boolean
enables or disables access to the real Internet
65 66 67 68 69 |
# File 'lib/shopify-mock.rb', line 65 def allow_internet=(state = true) return @allow_internet if @allow_internet == state @allow_internet = state FakeWeb.allow_net_connect = @allow_internet end |
.allow_internet? ⇒ Boolean
gets the state of access to the real Internet
56 57 58 |
# File 'lib/shopify-mock.rb', line 56 def allow_internet? @allow_internet || true end |
.enabled=(value = false) ⇒ Boolean
enable or disable ShopifyAPI::Mock
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/shopify-mock.rb', line 28 def enabled=(value=false) return @enabled if value == @enabled if value #load File.expand_path("../shopify-mock/responses.rb", __FILE__) ShopifyAPI::Mock.register_fixed_responses else ShopifyAPI::Mock::Response.clear end @enabled = value end |
.enabled? ⇒ Boolean
get the enabled state of ShopifyAPI::Mock
18 19 20 |
# File 'lib/shopify-mock.rb', line 18 def enabled? @enabled || false end |
.register_fixed_responses ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
registers all the fixed responses
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/shopify-mock.rb', line 74 def register_fixed_responses ShopifyAPI::Mock::Response.clear registered_responses = [] ShopifyAPI::Mock::Fixture.all.each do |fixture| # register the count fixture for this resource count_fixture = ShopifyAPI::Mock::Fixture.find(:count, fixture.ext.to_sym) registered_responses << ShopifyAPI::Mock::Response.new( :get, "#{fixture.name.to_s}/count.#{fixture.ext}", count_fixture.data ) # register the resource fixture registered_responses << ShopifyAPI::Mock::Response.new( :get, "#{fixture.name.to_s}.#{fixture.ext.to_s}", fixture.data ) end registered_responses end |
.reset ⇒ Boolean
resets the ShopifyAPI::Mocks back to their original state
45 46 47 48 49 |
# File 'lib/shopify-mock.rb', line 45 def reset raise ShopifyAPI::Mock::DisabledError, "cannot reset ShopifyAPI::Mock while it is disabled" \ unless ShopifyAPI::Mock.enabled? self.class.register_fixed_responses end |