shopify-mock 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -34,7 +34,7 @@ this quick example:
34
34
 
35
35
  rails c
36
36
  :001 > ShopifyAPI::Mock.enabled = true
37
- :002 > order = ShopifyAPI::Session("test", "randomtoken") { ShopifyAPI::Order.first }
37
+ :002 > order = ShopifyAPI::Session.temp("test", "randomtoken") { ShopifyAPI::Order.first }
38
38
 
39
39
  You'll notice that the order was not downloaded from Shopify, but based off of
40
40
  a ShopifyMock fixture found in lib/shopify-mock/fixtures/orders.json
@@ -5,6 +5,12 @@ module ShopifyAPI
5
5
 
6
6
  class << self
7
7
 
8
+ def all
9
+ Dir[File.join(ShopifyAPI::Mock::Fixtures.path, "**", "*.json")].map do |fixture|
10
+ File.basename(fixture, ".json").to_sym
11
+ end
12
+ end
13
+
8
14
  def read(name, ext = :json)
9
15
  fixture_name = "#{name.to_s}.#{ext.to_s}"
10
16
  fixture = File.join(self.path, fixture_name)
@@ -20,6 +26,7 @@ module ShopifyAPI
20
26
  else
21
27
  @cache[name] = content
22
28
  end
29
+ ShopifyAPI::Mock.reset
23
30
  end
24
31
 
25
32
  def path
@@ -28,11 +35,13 @@ module ShopifyAPI
28
35
 
29
36
  def path=(value)
30
37
  @path = value
38
+ ShopifyAPI::Mock.reset
31
39
  end
32
40
 
33
41
  def reset
34
42
  @cache = {}
35
43
  @path = nil
44
+ ShopifyAPI::Mock::Responses.register_all
36
45
  end
37
46
 
38
47
  end
@@ -0,0 +1,26 @@
1
+ module ShopifyAPI
2
+ module Mock
3
+ class Response
4
+ class << self
5
+ def register(method, resource, response)
6
+ FakeWeb.register_uri(
7
+ method, /#{SHOPIFY_MOCK_SHOP_BASE_URL}#{resource}/,
8
+ :body => response
9
+ )
10
+ end
11
+
12
+ def register_all
13
+ count_fixture = ShopifyAPI::Mock::Fixtures.read(:count)
14
+ ShopifyAPI::Mock::Fixtures.all.each do |fixture|
15
+ ShopifyAPI::Mock::Response.register(:get, "#{fixture.to_s}/count.json", count_fixture)
16
+ ShopifyAPI::Mock::Response.register(
17
+ :get, "#{fixture.to_s}.json",
18
+ ShopifyAPI::Mock::Fixtures.read(fixture)
19
+ )
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module ShopifyMock
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/shopify-mock.rb CHANGED
@@ -3,6 +3,7 @@ require 'fakeweb'
3
3
  require 'shopify-mock/version'
4
4
  require 'shopify-mock/urls'
5
5
  require 'shopify-mock/fixtures'
6
+ require 'shopify-mock/response'
6
7
 
7
8
  module ShopifyAPI
8
9
  module Mock
@@ -14,13 +15,19 @@ module ShopifyAPI
14
15
  def enabled=(value=false)
15
16
  return @enabled if value == @enabled
16
17
  if value
17
- load File.expand_path("../shopify-mock/responses.rb", __FILE__)
18
+ #load File.expand_path("../shopify-mock/responses.rb", __FILE__)
19
+ ShopifyAPI::Mock::Response.register_all
18
20
  else
19
21
  FakeWeb.clean_registry
20
22
  end
21
23
  @enabled = value
22
24
  end
23
25
 
26
+ def reset
27
+ ShopifyAPI::Mock.enabled = false
28
+ ShopifyAPI::Mock.enabled = true
29
+ end
30
+
24
31
  def allow_internet
25
32
  @allow_internet || true
26
33
  end
@@ -2,6 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe ShopifyAPI::Mock::Fixtures do
4
4
 
5
+ describe "#all" do
6
+ it "should return an array" do
7
+ ShopifyAPI::Mock::Fixtures.all.should be_kind_of Array
8
+ end
9
+ end
10
+
5
11
  context "when given a valid fixture name" do
6
12
  it "should return the contents of a fixture" do
7
13
  @json = read_fixture :test
@@ -26,7 +32,7 @@ describe ShopifyAPI::Mock::Fixtures do
26
32
  end
27
33
  end
28
34
  context "with :default for content" do
29
- it "should reset back to default texture" do
35
+ it "should reset back to default fixture" do
30
36
  ShopifyAPI::Mock::Fixtures.use :count, @json
31
37
  ShopifyAPI::Mock::Fixtures.read(:count).should eq @json
32
38
  ShopifyAPI::Mock::Fixtures.use :count, :default
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe :response do
4
+
5
+
6
+ describe "all registered responses" do
7
+ ShopifyAPI::Mock::Fixtures.all.each do |fixture|
8
+ describe "##{fixture}" do
9
+ describe "GET /#{fixture}.json" do
10
+ before do
11
+ @json = read_fixture fixture
12
+ @response = get fixture
13
+ end
14
+ it "should return #{fixture.to_s}.json fixture" do
15
+ @response.body.should eq @json
16
+ end
17
+ end
18
+
19
+ describe "GET /#{fixture}/count.json" do
20
+ before do
21
+ @json = read_fixture :count
22
+ @response = get [fixture, :count]
23
+ end
24
+ it "should return count json" do
25
+ @response.body.should eq @json
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fakeweb
16
- requirement: &12548880 !ruby/object:Gem::Requirement
16
+ requirement: &13655540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12548880
24
+ version_requirements: *13655540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &12540980 !ruby/object:Gem::Requirement
27
+ requirement: &13648580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.6.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *12540980
35
+ version_requirements: *13648580
36
36
  description: ! 'This gem is used for testing Shopify apps without having to actually
37
37
  connect to
38
38
 
@@ -86,15 +86,12 @@ files:
86
86
  - lib/shopify-mock/fixtures/transactions.json
87
87
  - lib/shopify-mock/fixtures/variants.json
88
88
  - lib/shopify-mock/fixtures/webhooks.json
89
- - lib/shopify-mock/responses.rb
90
- - lib/shopify-mock/responses/articles.rb
91
- - lib/shopify-mock/responses/orders.rb
89
+ - lib/shopify-mock/response.rb
92
90
  - lib/shopify-mock/urls.rb
93
91
  - lib/shopify-mock/version.rb
94
92
  - shopify-mock.gemspec
95
- - spec/mockify/fixtures_spec.rb
96
- - spec/mockify/responses/articles_spec.rb
97
- - spec/mockify/responses/orders_spec.rb
93
+ - spec/fixtures_spec.rb
94
+ - spec/response_spec.rb
98
95
  - spec/spec_helper.rb
99
96
  - spec/support/fixture_support.rb
100
97
  - spec/support/http_support.rb
@@ -1,5 +0,0 @@
1
- articles = ShopifyAPI::Mock::Fixtures.read(:articles)
2
- count = ShopifyAPI::Mock::Fixtures.read(:count)
3
-
4
- ShopifyAPI::Mock::Response.register(:get, "articles/count.json", count)
5
- ShopifyAPI::Mock::Response.register(:get, "articles.json", articles)
@@ -1,6 +0,0 @@
1
- orders = ShopifyAPI::Mock::Fixtures.read(:orders)
2
- count = ShopifyAPI::Mock::Fixtures.read(:count)
3
-
4
- ShopifyAPI::Mock::Response.register(:get, "orders/count.json", count)
5
- ShopifyAPI::Mock::Response.register(:get, "orders.json", orders)
6
-
@@ -1,17 +0,0 @@
1
- module ShopifyAPI
2
- module Mock
3
- class Response
4
- class << self
5
- def register(method, resource, response)
6
- FakeWeb.register_uri(
7
- method, /#{SHOPIFY_MOCK_SHOP_BASE_URL}#{resource}/,
8
- :body => response
9
- )
10
- end
11
- end
12
- end
13
- end
14
- end
15
-
16
- require 'shopify-mock/responses/orders'
17
- require 'shopify-mock/responses/articles'
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe :articles do
4
-
5
- describe "GET /articles.json" do
6
- before do
7
- @json = read_fixture :articles
8
- @response = get :articles
9
- end
10
- it "should return articles.json fixture" do
11
- @response.body.should eq @json
12
- end
13
- end
14
-
15
- describe "GET /articles/count.json" do
16
- before do
17
- @json = read_fixture :count
18
- @response = get [:articles, :count]
19
- end
20
- it "should return count json" do
21
- @response.body.should eq @json
22
- end
23
- end
24
-
25
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe :orders do
4
-
5
- describe "GET /orders.json" do
6
- before do
7
- @json = read_fixture :orders
8
- @response = get :orders
9
- end
10
- it "should return orders.json fixture" do
11
- @response.body.should eq @json
12
- end
13
- end
14
-
15
- describe "GET /orders/count.json" do
16
- before do
17
- @json = read_fixture :count
18
- @response = get [:orders, :count]
19
- end
20
- it "should return count json" do
21
- @response.body.should eq @json
22
- end
23
- end
24
-
25
- end