= ShopifyMock This gem is used for testing Shopify apps without having to actually connect to Shopify to develop the application. You can use this gem explicitely for testing, or you can also use it in your development environment to speed things up when fiddling around in the web browser, or in the console. == Installation Add the gem to your Gemfile in the appropriate group: gem 'shopify-mock', :group => [:development, :test] == Enabling / Disabling For non Rails apps, ShopifyMock is disabled by default, and real-world Internet access is allowed. In a Rails app, ShopifyMock is disabled except for in the :test environment. To enable / disable ShopifyMock manually, set ShopifyAPI::Mock.enabled to true or false: ShopifyAPI::Mock.enabled = true # or false And to completely disable access to the Internet altogether, or re-enable it: ShopifyAPI::Mock.allow_internet = false # or true to re-enable == Example After installing the gem in your Shopify app, load the rails console, and try this quick example: rails c :001 > ShopifyAPI::Mock.enabled = true :002 > order = ShopifyAPI::Session.temp("test", "randomtoken") { ShopifyAPI::Order.first } You'll notice that the order was not downloaded from Shopify, but based off of a ShopifyMock fixture found in lib/shopify-mock/fixtures/orders.json == Fixtures You have access to the ShopifyMock fixtures from within your app to help with testing. To access a fixture, use ShopifyAPI::Mock::Fixtures: ShopifyAPI::Mock::Fixtures.read(:orders) # => contents of orders.json You can also use your own fixtures if you'd like: ShopifyAPI::Mock::Fixtures.use :orders, order.to_json # => use custom content for :orders ShopifyAPI::Mock::Fixtures.use :orders, :default # => reset :orders to default fixture ShopifyAPI::Mock::Fixtures.reset # => reset all the fixtures back to their defaults Or, if you'd prefer you can point the entire fixture path to a different location: ShopifyAPI::Mock::Fixtures.path = File.join(Rails.root, 'spec', 'fixtures') All of the default fixtures are copied directly from the {Shopify API}[http://api.shopify.com]