shopify-mock 0.1.1 → 0.1.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/lib/shopify-mock.rb +1 -1
- data/lib/shopify-mock/{fixtures.rb → fixture.rb} +12 -12
- data/lib/shopify-mock/fixtures/json/application_charges.json +13 -0
- data/lib/shopify-mock/fixtures/json/recurring_application_charges.json +18 -0
- data/lib/shopify-mock/fixtures/xml/application_charges.xml +12 -0
- data/lib/shopify-mock/fixtures/xml/recurring_application_charges.xml +17 -0
- data/lib/shopify-mock/response.rb +2 -2
- data/shopify-mock.gemspec +1 -1
- data/spec/fixture_spec.rb +70 -0
- data/spec/response_spec.rb +13 -11
- metadata +14 -10
- data/spec/fixtures_spec.rb +0 -59
data/lib/shopify-mock.rb
CHANGED
@@ -3,8 +3,8 @@ module ShopifyAPI
|
|
3
3
|
|
4
4
|
# provides easy access to fixtures
|
5
5
|
class Fixture
|
6
|
-
|
7
|
-
|
6
|
+
@@path = nil
|
7
|
+
@@cache = {}
|
8
8
|
|
9
9
|
# creates a new instance of ShopifyAPI::Mock::Fixture
|
10
10
|
# @param [String] file_name The location of the file to load into the fixture
|
@@ -18,7 +18,7 @@ module ShopifyAPI
|
|
18
18
|
# gets the content of the fixture
|
19
19
|
# @return [String] the contents of the file, or @data if it was overwritten
|
20
20
|
# @example Create a fixture and read its contents
|
21
|
-
# fixture = ShopifyAPI::Fixture
|
21
|
+
# fixture = ShopifyAPI::Fixture.new "./orders.xml"
|
22
22
|
# data = fixture.data # => the contents of "./orders.xml"
|
23
23
|
# @api public
|
24
24
|
def data
|
@@ -28,7 +28,7 @@ module ShopifyAPI
|
|
28
28
|
# gets the name of the fixture
|
29
29
|
# @return [Symbol] the the file name without the extension
|
30
30
|
# @example Load a fixture and get its name
|
31
|
-
# fixture = ShopifyAPI::Fixture
|
31
|
+
# fixture = ShopifyAPI::Fixture.new "./orders.xml"
|
32
32
|
# name = fixture.name # => :orders
|
33
33
|
# @api public
|
34
34
|
def name
|
@@ -39,7 +39,7 @@ module ShopifyAPI
|
|
39
39
|
# @param [String] value The new value to use, or set to nil to reset to default
|
40
40
|
# @return The new contents of the fixture
|
41
41
|
# @example Override a the contents of a fixture
|
42
|
-
# fixture = ShopifyAPI::Fixture
|
42
|
+
# fixture = ShopifyAPI::Fixture.new "./orders.xml"
|
43
43
|
# data = fixture.data # => the contents of "./orders.xml"
|
44
44
|
# fixture.data = "hello world"
|
45
45
|
# data = fixture.data # => "hello world"
|
@@ -54,7 +54,7 @@ module ShopifyAPI
|
|
54
54
|
# gets the extension of the fixture
|
55
55
|
# @return [Symbol] The extension
|
56
56
|
# @example Create a new fixture and get its extension
|
57
|
-
# fixture = ShopifyAPI::Fixture
|
57
|
+
# fixture = ShopifyAPI::Fixture.new "./orders.xml"
|
58
58
|
# ext = fixture.ext # => :xml
|
59
59
|
# @api public
|
60
60
|
def ext
|
@@ -77,7 +77,7 @@ module ShopifyAPI
|
|
77
77
|
# map files to fixtures
|
78
78
|
files.map do |file_name|
|
79
79
|
fixture_name = File.basename(file_name)
|
80
|
-
|
80
|
+
@@cache[fixture_name] ||= Fixture.new(file_name)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -94,7 +94,7 @@ module ShopifyAPI
|
|
94
94
|
fixture_name = "#{name.to_s}.#{ext.to_s}"
|
95
95
|
file_name = File.join(self.path, ext.to_s, fixture_name)
|
96
96
|
return nil unless File.exists? file_name
|
97
|
-
|
97
|
+
@@cache[fixture_name] ||= Fixture.new(file_name)
|
98
98
|
end
|
99
99
|
|
100
100
|
# gets the current path to the fixtures
|
@@ -103,7 +103,7 @@ module ShopifyAPI
|
|
103
103
|
# fixture_path = ShopifyAPI::Mock::Fixture.path
|
104
104
|
# @api public
|
105
105
|
def path
|
106
|
-
|
106
|
+
@@path ||= File.expand_path("../fixtures/", __FILE__)
|
107
107
|
end
|
108
108
|
|
109
109
|
# sets the current fixtures path
|
@@ -113,9 +113,9 @@ module ShopifyAPI
|
|
113
113
|
# ShopifyAPI::Mock::Fixture.path = File.join(Rails.root, "spec", "fixtures", "shopify")
|
114
114
|
# @api public
|
115
115
|
def path=(value)
|
116
|
-
return
|
117
|
-
|
118
|
-
|
116
|
+
return @@path if @@path == value
|
117
|
+
@@path = value
|
118
|
+
@@cache = {}
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"application_charge": {
|
3
|
+
"price": "100.00",
|
4
|
+
"name": "Super Duper Expensive action",
|
5
|
+
"created_at": "2011-09-06T11:46:15-04:00",
|
6
|
+
"return_url": "http://super-duper.shopifyapps.com?charge_id=1007331646",
|
7
|
+
"updated_at": "2011-09-06T11:46:15-04:00",
|
8
|
+
"confirmation_url": "http://apple.myshopify.com/admin/subscriptions/confirm_application_charge/1007331646?signature=BAhpBD6pCjw%3D--ce8f74151dcf7c56ebbf2a15f7a2694533b46fd4",
|
9
|
+
"id": 1007331646,
|
10
|
+
"test": null,
|
11
|
+
"status": "pending"
|
12
|
+
}
|
13
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"recurring_application_charge": {
|
3
|
+
"price": "10.00",
|
4
|
+
"name": "Super Duper Plan",
|
5
|
+
"created_at": "2011-09-06T11:50:32-04:00",
|
6
|
+
"trial_days": 0,
|
7
|
+
"return_url": "http://super-duper.shopifyapps.com?charge_id=654381199",
|
8
|
+
"activated_on": null,
|
9
|
+
"updated_at": "2011-09-06T11:50:32-04:00",
|
10
|
+
"confirmation_url": "http://apple.myshopify.com/admin/subscriptions/confirm_recurring_application_charge/654381199?signature=BAhpBI8QASc%3D--2281aa5a8b56409b646a99312fdf3066c3e03b3e",
|
11
|
+
"id": 654381199,
|
12
|
+
"cancelled_on": null,
|
13
|
+
"trial_ends_on": null,
|
14
|
+
"billing_on": null,
|
15
|
+
"test": true,
|
16
|
+
"status": "pending"
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<application-charge>
|
3
|
+
<price type="decimal">100.0</price>
|
4
|
+
<name>Super Duper Expensive action</name>
|
5
|
+
<created-at type="datetime">2011-09-06T11:52:12-04:00</created-at>
|
6
|
+
<return-url>http://super-duper.shopifyapps.com</return-url>
|
7
|
+
<updated-at type="datetime">2011-09-06T11:52:12-04:00</updated-at>
|
8
|
+
<id type="integer">1007331651</id>
|
9
|
+
<test type="boolean" nil="true"></test>
|
10
|
+
<status>pending</status>
|
11
|
+
<confirmation-url>http://apple.myshopify.com/admin/subscriptions/confirm_application_charge/1007331651?signature=BAhpBEOpCjw%3D--373db9ba20ab12e32af89ebcd7274f9c461b16b2</confirmation-url>
|
12
|
+
</application-charge>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<recurring-application-charge>
|
3
|
+
<price type="decimal">10.0</price>
|
4
|
+
<name>Super Duper Plan</name>
|
5
|
+
<created-at type="datetime">2011-09-06T11:59:27-04:00</created-at>
|
6
|
+
<trial-days type="integer">0</trial-days>
|
7
|
+
<return-url>http://super-duper.shopifyapps.com</return-url>
|
8
|
+
<activated-on type="date" nil="true"></activated-on>
|
9
|
+
<updated-at type="datetime">2011-09-06T11:59:27-04:00</updated-at>
|
10
|
+
<id type="integer">654381205</id>
|
11
|
+
<cancelled-on type="date" nil="true"></cancelled-on>
|
12
|
+
<trial-ends-on type="date" nil="true"></trial-ends-on>
|
13
|
+
<billing-on type="date" nil="true"></billing-on>
|
14
|
+
<test type="boolean">true</test>
|
15
|
+
<status>pending</status>
|
16
|
+
<confirmation-url>http://apple.myshopify.com/admin/subscriptions/confirm_recurring_application_charge/654381205?signature=BAhpBJUQASc%3D--53e16e6658a181c4448475252e1282f3b01354eb</confirmation-url>
|
17
|
+
</recurring-application-charge>
|
@@ -7,8 +7,8 @@ module ShopifyAPI
|
|
7
7
|
# @param [String] resource The path to the resource.
|
8
8
|
# @param [String] response The response to provide when that URL is called
|
9
9
|
# @return [FakeWeb] The FakeWeb object for the mocked response
|
10
|
-
# @example Registering a response to the path "/orders
|
11
|
-
# ShopifyAPI::Mock::Response.
|
10
|
+
# @example Registering a response to the path "/orders/count.xml" with the response "hello world"
|
11
|
+
# ShopifyAPI::Mock::Response.new :get, "orders/count.xml", "hello world"
|
12
12
|
# @api public
|
13
13
|
def initialize(method, resource, response)
|
14
14
|
@@responses += FakeWeb.register_uri(
|
data/shopify-mock.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "shopify-mock"
|
6
|
-
s.version = "0.1.
|
6
|
+
s.version = "0.1.2"
|
7
7
|
s.authors = ["Travis Haynes"]
|
8
8
|
s.email = ["travis.j.haynes@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/travishaynes/shopify-mock"
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ShopifyAPI::Mock::Fixture do
|
4
|
+
|
5
|
+
describe "#new" do
|
6
|
+
context "with invalid file name" do
|
7
|
+
it "should raise IOError" do
|
8
|
+
expect {ShopifyAPI::Mock::Fixture.new("invalid-file") }.should raise_error, IOError
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with valid file name" do
|
13
|
+
before do
|
14
|
+
@file_name = File.expand_path("../../lib/shopify-mock/fixtures/json/orders.json", __FILE__)
|
15
|
+
@fixture = ShopifyAPI::Mock::Fixture.new(@file_name)
|
16
|
+
end
|
17
|
+
specify { @fixture.should be_a ShopifyAPI::Mock::Fixture }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "class methods" do
|
22
|
+
describe "#all" do
|
23
|
+
before { @all = ShopifyAPI::Mock::Fixture.all }
|
24
|
+
specify { @all.should be_kind_of Array }
|
25
|
+
specify { @all.length.should > 0 }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#find" do
|
29
|
+
context "with a valid fixture name" do
|
30
|
+
before { @result = ShopifyAPI::Mock::Fixture.find :orders, :json }
|
31
|
+
specify { @result.should be_kind_of ShopifyAPI::Mock::Fixture }
|
32
|
+
end
|
33
|
+
context "with an invalid fixture name" do
|
34
|
+
before { @result = ShopifyAPI::Mock::Fixture.find :brown_chicken_brown_cow, :xml }
|
35
|
+
specify { @result.should be_nil }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "instance methods" do
|
41
|
+
before(:all) do
|
42
|
+
@fixture = ShopifyAPI::Mock::Fixture.find :orders, :json
|
43
|
+
@original_data = @fixture.data
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#name" do
|
47
|
+
specify { @fixture.name.should be_a Symbol }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#ext" do
|
51
|
+
specify { @fixture.ext.should be_a Symbol }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#data" do
|
55
|
+
specify { @fixture.data.should_not be_empty }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#data=" do
|
59
|
+
it "should override the original content" do
|
60
|
+
@fixture.data.should eq @original_data
|
61
|
+
@fixture.data = 'new'
|
62
|
+
@fixture.data.should eq 'new'
|
63
|
+
end
|
64
|
+
it "should reset to original content when set to nil" do
|
65
|
+
@fixture.data = nil
|
66
|
+
@fixture.data.should eq @original_data
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/response_spec.rb
CHANGED
@@ -13,17 +13,19 @@ describe :response do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe "
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
describe "class methods" do
|
17
|
+
describe "#all" do
|
18
|
+
subject { ShopifyAPI::Mock::Response.all }
|
19
|
+
it { should be_kind_of Array }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#clear" do
|
23
|
+
it "should clear the responses" do
|
24
|
+
ShopifyAPI::Mock::Response.new(:get, "/orders.json", @fixture)
|
25
|
+
ShopifyAPI::Mock::Response.all.count.should > 0
|
26
|
+
ShopifyAPI::Mock::Response.clear
|
27
|
+
ShopifyAPI::Mock::Response.all.count.should eq 0
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fakeweb
|
16
|
-
requirement: &
|
16
|
+
requirement: &23532560 !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: *
|
24
|
+
version_requirements: *23532560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &23532060 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.6.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *23532060
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &23531580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 0.8.7
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *23531580
|
47
47
|
description: ! 'This gem is used for testing Shopify apps without having to actually
|
48
48
|
connect to
|
49
49
|
|
@@ -69,7 +69,8 @@ files:
|
|
69
69
|
- Rakefile
|
70
70
|
- lib/shopify-mock.rb
|
71
71
|
- lib/shopify-mock/errors.rb
|
72
|
-
- lib/shopify-mock/
|
72
|
+
- lib/shopify-mock/fixture.rb
|
73
|
+
- lib/shopify-mock/fixtures/json/application_charges.json
|
73
74
|
- lib/shopify-mock/fixtures/json/articles.json
|
74
75
|
- lib/shopify-mock/fixtures/json/assets.json
|
75
76
|
- lib/shopify-mock/fixtures/json/blogs.json
|
@@ -89,6 +90,7 @@ files:
|
|
89
90
|
- lib/shopify-mock/fixtures/json/product_search_engines.json
|
90
91
|
- lib/shopify-mock/fixtures/json/products.json
|
91
92
|
- lib/shopify-mock/fixtures/json/provinces.json
|
93
|
+
- lib/shopify-mock/fixtures/json/recurring_application_charges.json
|
92
94
|
- lib/shopify-mock/fixtures/json/redirects.json
|
93
95
|
- lib/shopify-mock/fixtures/json/script_tags.json
|
94
96
|
- lib/shopify-mock/fixtures/json/shop.json
|
@@ -98,6 +100,7 @@ files:
|
|
98
100
|
- lib/shopify-mock/fixtures/json/transactions.json
|
99
101
|
- lib/shopify-mock/fixtures/json/variants.json
|
100
102
|
- lib/shopify-mock/fixtures/json/webhooks.json
|
103
|
+
- lib/shopify-mock/fixtures/xml/application_charges.xml
|
101
104
|
- lib/shopify-mock/fixtures/xml/articles.xml
|
102
105
|
- lib/shopify-mock/fixtures/xml/assets.xml
|
103
106
|
- lib/shopify-mock/fixtures/xml/blogs.xml
|
@@ -117,6 +120,7 @@ files:
|
|
117
120
|
- lib/shopify-mock/fixtures/xml/product_search_engines.xml
|
118
121
|
- lib/shopify-mock/fixtures/xml/products.xml
|
119
122
|
- lib/shopify-mock/fixtures/xml/provinces.xml
|
123
|
+
- lib/shopify-mock/fixtures/xml/recurring_application_charges.xml
|
120
124
|
- lib/shopify-mock/fixtures/xml/redirects.xml
|
121
125
|
- lib/shopify-mock/fixtures/xml/script_tags.xml
|
122
126
|
- lib/shopify-mock/fixtures/xml/shop.xml
|
@@ -130,7 +134,7 @@ files:
|
|
130
134
|
- lib/shopify-mock/urls.rb
|
131
135
|
- shopify-mock.gemspec
|
132
136
|
- spec/errors_spec.rb
|
133
|
-
- spec/
|
137
|
+
- spec/fixture_spec.rb
|
134
138
|
- spec/mock_spec.rb
|
135
139
|
- spec/response_spec.rb
|
136
140
|
- spec/spec_helper.rb
|
data/spec/fixtures_spec.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ShopifyAPI::Mock::Fixture do
|
4
|
-
|
5
|
-
describe "#new" do
|
6
|
-
context "with invalid file name" do
|
7
|
-
it "should raise IOError" do
|
8
|
-
expect {ShopifyAPI::Mock::Fixture.new("invalid-file") }.should raise_error, IOError
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context "with valid file name" do
|
13
|
-
before do
|
14
|
-
@file_name = File.expand_path("../../lib/shopify-mock/fixtures/json/orders.json", __FILE__)
|
15
|
-
@fixture = ShopifyAPI::Mock::Fixture.new(@file_name)
|
16
|
-
end
|
17
|
-
specify { @fixture.should be_a ShopifyAPI::Mock::Fixture }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#all" do
|
22
|
-
before { @all = ShopifyAPI::Mock::Fixture.all }
|
23
|
-
specify { @all.should be_kind_of Array }
|
24
|
-
specify { @all.length.should > 0 }
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#find" do
|
28
|
-
context "with a valid fixture name" do
|
29
|
-
before { @result = ShopifyAPI::Mock::Fixture.find :orders, :json }
|
30
|
-
specify { @result.should be_kind_of ShopifyAPI::Mock::Fixture }
|
31
|
-
end
|
32
|
-
context "with an invalid fixture name" do
|
33
|
-
before { @result = ShopifyAPI::Mock::Fixture.find :brown_chicken_brown_cow, :xml }
|
34
|
-
specify { @result.should be_nil }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#data" do
|
39
|
-
before { @fixture = ShopifyAPI::Mock::Fixture.find :orders, :json }
|
40
|
-
specify { @fixture.data.should_not be_empty }
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "#data=" do
|
44
|
-
before(:all) do
|
45
|
-
@fixture = ShopifyAPI::Mock::Fixture.find :orders, :json
|
46
|
-
@original_data = @fixture.data
|
47
|
-
end
|
48
|
-
it "should override the original content" do
|
49
|
-
@fixture.data.should eq @original_data
|
50
|
-
@fixture.data = 'new'
|
51
|
-
@fixture.data.should eq 'new'
|
52
|
-
end
|
53
|
-
it "should reset to original content when set to nil" do
|
54
|
-
@fixture.data = nil
|
55
|
-
@fixture.data.should eq @original_data
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|