harper 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,6 +27,33 @@ Feature: Mock an HTTP RPC web service
27
27
  And the application issues a "GET" request for "/service"
28
28
  Then the response code should be "503"
29
29
 
30
+ Scenario: Cycle through the bodies of a mock
31
+ Given the following response mock, known as "sequential":
32
+ """
33
+ {
34
+ "url": "/sequential",
35
+ "method": "GET",
36
+ "content-type": "text/plain",
37
+ "body": ["body 1", "body 2"]
38
+ }
39
+ """
40
+ When the application POSTs the mock "sequential" to "/h/mocks"
41
+ And the application issues a "GET" request for "/sequential"
42
+ Then the response body should be:
43
+ """
44
+ body 1
45
+ """
46
+ When the application issues a "GET" request for "/sequential"
47
+ Then the response body should be:
48
+ """
49
+ body 2
50
+ """
51
+ When the application issues a "GET" request for "/sequential"
52
+ Then the response body should be:
53
+ """
54
+ body 1
55
+ """
56
+
30
57
  Scenario Outline: All HTTP methods can be mocked
31
58
  Given a defined response mock with a "method" of "<METHOD>"
32
59
  When the application issues a "<METHOD>" request to the mock
data/lib/harper/app.rb CHANGED
@@ -84,7 +84,14 @@ module Harper
84
84
 
85
85
  logger.info("Serving mocked body for endpoint: '#{mock['url']}'")
86
86
 
87
- mock['body']
87
+ case mock['body']
88
+ when Array
89
+ next_body = mock['next'] || -1
90
+ mock['next'] = (next_body + 1) % mock['body'].length
91
+ mock['body'][mock['next']]
92
+ else
93
+ mock['body']
94
+ end
88
95
  else
89
96
  status "503"
90
97
  end
@@ -1,3 +1,3 @@
1
1
  module Harper
2
- Version = "0.1.1"
2
+ Version = "1.0.0"
3
3
  end
data/spec/harper_spec.rb CHANGED
@@ -150,6 +150,25 @@ describe Harper::App do
150
150
  end
151
151
  end
152
152
 
153
+ context "sequential mocks" do
154
+ let(:body) { ["b1", "b2"] }
155
+
156
+ before(:each) do
157
+ post '/h/mocks', mock_def
158
+ @created_mock = last_response.headers['location']
159
+ end
160
+
161
+ after(:each) { delete @created_mock }
162
+
163
+ it "should cycle through the available bodies" do
164
+ get url
165
+ last_response.body.should == "b1"
166
+ get url
167
+ last_response.body.should == "b2"
168
+ end
169
+
170
+ end
171
+
153
172
  context "controlling harper" do
154
173
 
155
174
  it "should exit, abruptly, on demand" do
@@ -158,6 +177,7 @@ describe Harper::App do
158
177
  Harper::App.server(host)
159
178
  put '/h/control', {:command => "quit"}.to_json
160
179
  end
180
+
161
181
  end
162
182
 
163
183
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
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: 2012-06-01 00:00:00.000000000 Z
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &70295163579840 !ruby/object:Gem::Requirement
16
+ requirement: &70133087544280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70295163579840
24
+ version_requirements: *70133087544280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &70295163578920 !ruby/object:Gem::Requirement
27
+ requirement: &70133087543880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70295163578920
35
+ version_requirements: *70133087543880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &70295163577780 !ruby/object:Gem::Requirement
38
+ requirement: &70133087543060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.4.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70295163577780
46
+ version_requirements: *70133087543060
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: trollop
49
- requirement: &70295163577000 !ruby/object:Gem::Requirement
49
+ requirement: &70133087542500 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70295163577000
57
+ version_requirements: *70133087542500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack-test
60
- requirement: &70295163576160 !ruby/object:Gem::Requirement
60
+ requirement: &70133087541880 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70295163576160
68
+ version_requirements: *70133087541880
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sham_rack
71
- requirement: &70295163575540 !ruby/object:Gem::Requirement
71
+ requirement: &70133087541260 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70295163575540
79
+ version_requirements: *70133087541260
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70295163574940 !ruby/object:Gem::Requirement
82
+ requirement: &70133087540700 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70295163574940
90
+ version_requirements: *70133087540700
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: cucumber
93
- requirement: &70295163574340 !ruby/object:Gem::Requirement
93
+ requirement: &70133087540100 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0.10'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70295163574340
101
+ version_requirements: *70133087540100
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: cucumber-sinatra
104
- requirement: &70295163573760 !ruby/object:Gem::Requirement
104
+ requirement: &70133087535840 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70295163573760
112
+ version_requirements: *70133087535840
113
113
  description: Dead simple mocking for HTTP services, a Sinatra app
114
114
  email:
115
115
  - giles.alexander@gmail.com