mirage 0.1.6 → 0.1.7

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.
@@ -1,5 +1,5 @@
1
1
  Feature: After a response has been served from Mirage, the content of the request that triggered it can be retrieved. This is useful
2
- for testing that the correct information was sent to the endpint that the MockServer is stubbing,
2
+ for testing that the correct information was sent to the endpoint.
3
3
 
4
4
  On setting a response, a unique id is returned which can be used to look up the last request made to get that response.
5
5
 
@@ -21,7 +21,7 @@ Feature: After a response has been served from Mirage, the content of the reques
21
21
  """
22
22
  Hello MockServer
23
23
  """
24
- When I hit 'http://localhost:7001/mirage/check/1'
24
+ When I hit 'http://localhost:7001/mirage/check_request/1'
25
25
  Then 'Hello MockServer' should be returned
26
26
 
27
27
 
@@ -29,12 +29,12 @@ Feature: After a response has been served from Mirage, the content of the reques
29
29
  Given I hit 'http://localhost:7001/mirage/get/greeting' with parameters:
30
30
  | surname | Davis |
31
31
  | firstname | Leon |
32
- When I hit 'http://localhost:7001/mirage/check/1'
32
+ When I hit 'http://localhost:7001/mirage/check_request/1'
33
33
  Then 'surname=Davis&firstname=Leon' should be returned
34
34
 
35
35
 
36
36
  Scenario: Querying a response that has not been served yet
37
- Given I hit 'http://localhost:7001/mirage/check/1'
37
+ Given I hit 'http://localhost:7001/mirage/check_request/1'
38
38
  Then a 404 should be returned
39
39
 
40
40
 
@@ -44,7 +44,7 @@ Feature: After a response has been served from Mirage, the content of the reques
44
44
  Hello
45
45
  """
46
46
  And I hit 'http://localhost:7001/mirage/peek/1'
47
- When I hit 'http://localhost:7001/mirage/check/1'
47
+ When I hit 'http://localhost:7001/mirage/check_request/1'
48
48
  Then 'Hello' should be returned
49
49
 
50
50
 
@@ -66,9 +66,9 @@ Feature: After a response has been served from Mirage, the content of the reques
66
66
  """
67
67
  My name is Leon
68
68
  """
69
- And I hit 'http://localhost:7001/mirage/check/1'
69
+ And I hit 'http://localhost:7001/mirage/check_request/1'
70
70
  Then 'My name is Joel' should be returned
71
- And I hit 'http://localhost:7001/mirage/check/3'
71
+ And I hit 'http://localhost:7001/mirage/check_request/3'
72
72
  Then 'My name is Leon' should be returned
73
73
 
74
74
 
@@ -16,5 +16,5 @@ Feature: Requests made to the Mirage Server can be tracked using the Mirage clie
16
16
  | name | leon |
17
17
  Then I run
18
18
  """
19
- Mirage::Client.new.check(1).should == 'name=leon'
19
+ Mirage::Client.new.check_request(1).should == 'name=leon'
20
20
  """
@@ -17,6 +17,22 @@ Feature: the Mirage client provides a method for getting responses
17
17
  Mirage::Client.new.get('greeting').should == 'hello'
18
18
  """
19
19
 
20
+ Scenario: getting a response with parameters
21
+ Given I run
22
+ """
23
+ Mirage::Client.new.get('greeting', :firstname => 'leon', :surname => 'davis').should == 'hello'
24
+ """
25
+ And I hit 'http://localhost:7001/mirage/check_request/1'
26
+ Then 'firstname=leon&surname=davis' should be returned
27
+
28
+ Scenario: getting a response with a request body
29
+ Given I run
30
+ """
31
+ Mirage::Client.new.get('greeting','<greetingRequest></greetingRequest>').should == 'hello'
32
+ """
33
+ And I hit 'http://localhost:7001/mirage/check_request/1'
34
+ Then '<greetingRequest></greetingRequest>' should be returned
35
+
20
36
  Scenario: getting a response that does not exist
21
37
  Given I run
22
38
  """
@@ -12,7 +12,7 @@ Feature: the Mirage client provides methods for setting responses and loading de
12
12
  Scenario: Setting a basic response
13
13
  Given I run
14
14
  """
15
- Mirage::Client.new.set('greeting',:response => 'hello')
15
+ Mirage::Client.new.set('greeting','hello')
16
16
  """
17
17
  When I hit 'http://localhost:7001/mirage/get/greeting'
18
18
  Then 'hello' should be returned
@@ -20,7 +20,7 @@ Feature: the Mirage client provides methods for setting responses and loading de
20
20
  Scenario: Setting a response with a pattern
21
21
  Given I run
22
22
  """
23
- Mirage::Client.new.set('greeting', :response => 'Hello Leon', :pattern => '.*?>leon</name>')
23
+ Mirage::Client.new.set('greeting', 'Hello Leon', :pattern => '.*?>leon</name>')
24
24
  """
25
25
  When I hit 'http://localhost:7001/mirage/get/greeting'
26
26
  Then a 404 should be returned
@@ -39,8 +39,8 @@ Feature: the Mirage client provides methods for setting responses and loading de
39
39
  When the file 'responses/default_greetings.rb' contains:
40
40
  """
41
41
  Mirage.prime do |mirage|
42
- mirage.set('greeting', :response => 'hello')
43
- mirage.set('leaving', :response => 'goodbye')
42
+ mirage.set('greeting', 'hello')
43
+ mirage.set('leaving', 'goodbye')
44
44
  end
45
45
  """
46
46
  And I run
@@ -73,19 +73,7 @@ Feature: the Mirage client provides methods for setting responses and loading de
73
73
  Scenario: Setting a file as a response
74
74
  Given I run
75
75
  """
76
- Mirage::Client.new.set('download', :file => File.open('features/resources/test.zip'))
76
+ Mirage::Client.new.set('download', File.open('features/resources/test.zip'))
77
77
  """
78
78
  When I hit 'http://localhost:7001/mirage/get/download'
79
79
  Then the response should be a file the same as 'features/resources/test.zip'
80
-
81
-
82
- Scenario: A response or file is not supplied
83
- Given I run
84
- """
85
- begin
86
- Mirage::Client.new.set('download',{})
87
- fail("Error should have been thrown")
88
- rescue Exception => e
89
- e.is_a?(Mirage::InternalServerException).should == true
90
- end
91
- """
@@ -12,10 +12,10 @@ Feature: The Mirage client can be used to snaphsot and rollback the Mirage serve
12
12
  | response | The default greeting |
13
13
 
14
14
 
15
- Scenario: Taking a snapshot and rolling it back
15
+ Scenario: saving and reverting
16
16
  Given I run
17
17
  """
18
- Mirage::Client.new.snapshot
18
+ Mirage::Client.new.save
19
19
  """
20
20
  And I hit 'http://localhost:7001/mirage/set/leaving' with parameters:
21
21
  | response | Goodye |
@@ -25,7 +25,7 @@ Feature: The Mirage client can be used to snaphsot and rollback the Mirage serve
25
25
 
26
26
  When I run
27
27
  """
28
- Mirage::Client.new.rollback
28
+ Mirage::Client.new.revert
29
29
  """
30
30
  And I hit 'http://localhost:7001/mirage/get/leaving'
31
31
  Then a 404 should be returned
@@ -2,7 +2,7 @@ Feature: Mirage can also be used to host files.
2
2
 
3
3
  Scenario: A file is set as a response
4
4
  Given I hit 'http://localhost:7001/mirage/set/some/location/download' with parameters:
5
- | file | features/resources/test.zip |
5
+ | response | features/resources/test.zip |
6
6
 
7
7
  When I hit 'http://localhost:7001/mirage/get/some/location/download'
8
8
  Then the response should be a file the same as 'features/resources/test.zip'
@@ -12,7 +12,7 @@ Feature: If you want to see the content of a particular response without trigger
12
12
 
13
13
  Scenario: Peeking a file based response
14
14
  Given I hit 'http://localhost:7001/mirage/set/download' with parameters:
15
- | file | features/resources/test.zip |
15
+ | response | features/resources/test.zip |
16
16
  When I hit 'http://localhost:7001/mirage/peek/1'
17
17
  Then the response should be a file the same as 'features/resources/test.zip'
18
18
 
@@ -12,8 +12,8 @@ Feature: Mirage can be primed with a set of responses.
12
12
  Given the file 'responses/default_greetings.rb' contains:
13
13
  """
14
14
  Mirage.prime do |mirage|
15
- mirage.set('greeting', :response => 'hello')
16
- mirage.set('leaving', :response => 'goodbye')
15
+ mirage.set('greeting', 'hello')
16
+ mirage.set('leaving', 'goodbye')
17
17
  end
18
18
  """
19
19
  And I run 'mirage start'
@@ -27,7 +27,7 @@ Feature: Mirage can be primed with a set of responses.
27
27
  Given the file './custom_responses_location/default_greetings.rb' contains:
28
28
  """
29
29
  Mirage.prime do |mirage|
30
- mirage.set('greeting', :response => 'hello')
30
+ mirage.set('greeting', 'hello')
31
31
  end
32
32
  """
33
33
  And I run 'mirage start -d ./custom_responses_location'
@@ -39,7 +39,7 @@ Feature: Mirage can be primed with a set of responses.
39
39
  Given the file '/tmp/responses/default_greetings.rb' contains:
40
40
  """
41
41
  Mirage.prime do |mirage|
42
- mirage.set('greeting', :response => 'hello')
42
+ mirage.set('greeting', 'hello')
43
43
  end
44
44
  """
45
45
  And I run 'mirage start -d /tmp/responses'
@@ -52,7 +52,7 @@ Feature: Mirage can be primed with a set of responses.
52
52
  Given the file 'responses/default_greetings.rb' contains:
53
53
  """
54
54
  Mirage.prime do |mirage|
55
- mirage.set('greeting', :response => 'hello')
55
+ mirage.set('greeting', 'hello')
56
56
  end
57
57
  """
58
58
  And I run 'mirage start'
@@ -1,22 +1,22 @@
1
1
  Feature: Having set up the Mirage with a number of defaults, your tests may continue to change its state.
2
2
  Clearing and resetting all of your responses, potentially hundreds of times, can be time expensive.
3
3
 
4
- Mirage provides the ability to take a snapshot of its current state and to roll it back to that state.
4
+ Mirage provides the ability to save of its current state and to revert it back to that state.
5
5
 
6
6
  Background: The MockServer has been setup with some default responses
7
7
  Given I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
8
8
  | response | The default greeting |
9
9
 
10
10
 
11
- Scenario: Taking a snapshot and rolling it back
12
- Given I hit 'http://localhost:7001/mirage/snapshot'
11
+ Scenario: Saving Mirage and reverting it
12
+ Given I hit 'http://localhost:7001/mirage/save'
13
13
  And I hit 'http://localhost:7001/mirage/set/leaving' with parameters:
14
14
  | response | Goodye |
15
15
 
16
16
  And I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
17
17
  | response | Changed |
18
18
 
19
- And I hit 'http://localhost:7001/mirage/rollback'
19
+ And I hit 'http://localhost:7001/mirage/revert'
20
20
 
21
21
  When I hit 'http://localhost:7001/mirage/get/leaving'
22
22
  Then a 404 should be returned
@@ -94,8 +94,8 @@ When /^I (hit|get|post to) '(http:\/\/localhost:7001\/mirage\/(.*?))' with param
94
94
  parameters = {}
95
95
  table.raw.each do |row|
96
96
  parameter, value = row[0].to_sym, row[1]
97
- value = (parameter == :file ? File.open(value) : value)
98
- parameters[parameter.to_sym]=value
97
+ value = File.exists?(value) ? File.open(value) : value
98
+ parameters[parameter]=value
99
99
  end
100
100
 
101
101
  @response = hit_mirage(url, parameters)
@@ -22,7 +22,8 @@ module Web
22
22
 
23
23
  def hit_mirage(url, parameters={})
24
24
  start_time = Time.now
25
- response = (parameters.include?(:file) ? http_post(url, parameters) : http_get(url, parameters))
25
+ file = parameters.values.find{|value| value.is_a?(File)}
26
+ response = (file ? http_post(url, parameters) : http_get(url, parameters))
26
27
  @response_time = Time.now - start_time
27
28
  response
28
29
  end
@@ -20,15 +20,6 @@ Feature: Mirage's home page allows you to see what response are currently being
20
20
  When I click 'peek_response_1'
21
21
  Then I should see 'hello'
22
22
 
23
- Scenario: Using the home page to check if a request has been made
24
- Given I hit 'http://localhost:7001/mirage/get/greeting' with request body:
25
- """
26
- Yo!
27
- """
28
- Given I goto 'http://localhost:7001/mirage'
29
- When I click 'check_response_1'
30
- Then I should see 'Yo!'
31
-
32
23
  Scenario: Using the home page to check if a request has been made
33
24
  Given I hit 'http://localhost:7001/mirage/get/greeting' with request body:
34
25
  """
data/lib/mirage/client.rb CHANGED
@@ -40,20 +40,22 @@ module Mirage
40
40
  # Mirage::Client.new.get('greeting', :param1 => 'value1', param2=>'value2')
41
41
  #
42
42
  # Getting a response, passing a content in the body of the request
43
- # Mirage::Client.new.get('greeting', :body => 'content')
43
+ # Mirage::Client.new.get('greeting', 'content')
44
44
 
45
- def get endpoint, params={}
46
- response(http_get("#{@url}/get/#{endpoint}", params))
45
+ def get endpoint, body_or_params={}
46
+ body_or_params = {:body => body_or_params} if body_or_params.is_a?(String)
47
+ response(http_get("#{@url}/get/#{endpoint}", body_or_params))
47
48
  end
48
49
 
49
50
  # Set a text or file based response, to be hosted at a given end point optionally with a given pattern and delay
50
- # Client.set(endpoint, params) => unique id that can be used to call back to the server
51
+ # Client.set(endpoint, response, params) => unique id that can be used to call back to the server
51
52
  #
52
53
  # Examples:
53
- # Client.set('greeting', :response => 'hello':)
54
- # Client.set('greeting', :response => 'hello', :pattern => 'regex or plain text':)
55
- # Client.set('greeting', :response => 'hello', :delay => 5) # number of seconds
56
- def set endpoint, params
54
+ # Client.set('greeting', 'hello':)
55
+ # Client.set('greeting', 'hello', :pattern => 'regex or plain text':)
56
+ # Client.set('greeting', 'hello', :delay => 5) # number of seconds
57
+ def set endpoint, response, params={}
58
+ params[:response] = response
57
59
  response(http_post("#{@url}/set/#{endpoint}", params))
58
60
  end
59
61
 
@@ -93,21 +95,21 @@ module Mirage
93
95
  # request did not have any content in its body then what ever was in the request query string is returned instead
94
96
  #
95
97
  # Example:
96
- # Client.new.check(response_id) => Tracked request as a String
97
- def check response_id
98
- response(http_get("#{@url}/check/#{response_id}"))
98
+ # Client.new.check_request(response_id) => Tracked request as a String
99
+ def check_request response_id
100
+ response(http_get("#{@url}/check_request/#{response_id}"))
99
101
  end
100
102
 
101
- # Snapshot the state of the Mirage server so that it can be rolled back to that exact state at a later time.
102
- def snapshot
103
- http_post("#{@url}/snapshot").code == 200
103
+ # Save the state of the Mirage server so that it can be reverted back to that exact state at a later time.
104
+ def save
105
+ http_post("#{@url}/save").code == 200
104
106
  end
105
107
 
106
108
 
107
- # Roll the state of Mirage back to that stored in the snapshot
109
+ # Revert the state of Mirage back to the state that was last saved
108
110
  # If there is no snapshot to rollback to, nothing happens
109
- def rollback
110
- http_post("#{@url}/rollback").code == 200
111
+ def revert
112
+ http_post("#{@url}/revert").code == 200
111
113
  end
112
114
 
113
115
 
data/lib/mirage/core.rb CHANGED
@@ -93,7 +93,7 @@ module Mirage
93
93
  name = args.join('/')
94
94
  is_default = request['default'] == 'true'
95
95
 
96
- response = MockResponse.new(name, (request[:file]||response_value), pattern, delay.to_f, is_default)
96
+ response = MockResponse.new(name, response_value, pattern, delay.to_f, is_default)
97
97
 
98
98
  stored_responses = RESPONSES[name]||={}
99
99
 
@@ -147,15 +147,15 @@ module Mirage
147
147
  end
148
148
  end
149
149
 
150
- def check id
150
+ def check_request id
151
151
  REQUESTS[id.to_i] || respond("Nothing stored for: #{id}", 404)
152
152
  end
153
153
 
154
- def snapshot
154
+ def save
155
155
  SNAPSHOT.clear and SNAPSHOT.replace(RESPONSES.deep_clone)
156
156
  end
157
157
 
158
- def rollback
158
+ def revert
159
159
  RESPONSES.clear and RESPONSES.replace(SNAPSHOT.deep_clone)
160
160
  end
161
161
 
@@ -15,7 +15,7 @@
15
15
  <?r unless @responses.empty? ?>
16
16
  <table border="1" width='100%'>
17
17
  <?r @responses.each do |key, response| ?>
18
- <tr><td><a id='peek_response_#{response.response_id}' href="/mirage/peek/#{response.response_id}">#{key}</a></td><td><a id='check_response_#{response.response_id}' href="/mirage/check/#{response.response_id}">check</a></td></tr>
18
+ <tr><td><a id='peek_response_#{response.response_id}' href="/mirage/peek/#{response.response_id}">#{key}</a></td><td><a id='check_response_#{response.response_id}' href="/mirage/check_request/#{response.response_id}">check</a></td></tr>
19
19
  <?r end ?>
20
20
  </table>
21
21
  <?r end ?>
data/mirage.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mirage'
3
- s.version = '0.1.6'
3
+ s.version = '0.1.7'
4
4
  s.authors = ["Leon Davis"]
5
5
  s.homepage = 'https://github.com/lashd/mirage'
6
6
  s.description = 'Mirage aids testing of your applications by hosting mock responses so that your applications do not have to talk to real endpoints. Its accessible via HTTP and has a RESTful interface.'
@@ -14,7 +14,9 @@ Thanks you for installing mirage-#{s.version}.
14
14
 
15
15
  Run Mirage with:
16
16
 
17
- mirage start
17
+ mirage start
18
+
19
+ For more information go to: https://github.com/lashd/mirage/wiki
18
20
  ===============================================================================
19
21
  }
20
22
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mirage
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.6
5
+ version: 0.1.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Leon Davis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-27 00:00:00 +00:00
13
+ date: 2011-03-28 00:00:00 +01:00
14
14
  default_executable: mirage
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -101,7 +101,6 @@ extra_rdoc_files: []
101
101
  files:
102
102
  - .rvmrc
103
103
  - Gemfile
104
- - Gemfile.lock
105
104
  - README.md
106
105
  - bin/mirage
107
106
  - features/checking_for_requests.feature
@@ -121,10 +120,10 @@ files:
121
120
  - features/priming.feature
122
121
  - features/resources/test.zip
123
122
  - features/response_templates.feature
123
+ - features/save.feature
124
124
  - features/setting_responses.feature
125
125
  - features/setting_responses_with_a_delay.feature
126
126
  - features/setting_responses_with_pattern_matching.feature
127
- - features/snapshotting.feature
128
127
  - features/step_definitions/my_steps.rb
129
128
  - features/support/env.rb
130
129
  - features/web_user_interface.feature
@@ -145,9 +144,10 @@ licenses: []
145
144
 
146
145
  post_install_message: "\n\
147
146
  ===============================================================================\n\
148
- Thanks you for installing mirage-0.1.6. \n\n\
147
+ Thanks you for installing mirage-0.1.7. \n\n\
149
148
  Run Mirage with:\n\n\
150
- mirage start\n\
149
+ mirage start \n\n\
150
+ For more information go to: https://github.com/lashd/mirage/wiki\n\
151
151
  ===============================================================================\n"
152
152
  rdoc_options: []
153
153
 
@@ -171,7 +171,7 @@ rubyforge_project:
171
171
  rubygems_version: 1.6.1
172
172
  signing_key:
173
173
  specification_version: 3
174
- summary: mirage-0.1.6
174
+ summary: mirage-0.1.7
175
175
  test_files:
176
176
  - features/checking_for_requests.feature
177
177
  - features/clearing_requests_and_responses.feature
@@ -190,10 +190,10 @@ test_files:
190
190
  - features/priming.feature
191
191
  - features/resources/test.zip
192
192
  - features/response_templates.feature
193
+ - features/save.feature
193
194
  - features/setting_responses.feature
194
195
  - features/setting_responses_with_a_delay.feature
195
196
  - features/setting_responses_with_pattern_matching.feature
196
- - features/snapshotting.feature
197
197
  - features/step_definitions/my_steps.rb
198
198
  - features/support/env.rb
199
199
  - features/web_user_interface.feature
data/Gemfile.lock DELETED
@@ -1,50 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- mirage (0.1.6)
5
- mechanize (>= 1.0.0)
6
- rack (~> 1.1.0)
7
- ramaze (>= 2011.01.30)
8
-
9
- GEM
10
- remote: http://rubygems.org/
11
- specs:
12
- builder (3.0.0)
13
- cucumber (0.10.2)
14
- builder (>= 2.1.2)
15
- diff-lcs (>= 1.1.2)
16
- gherkin (>= 2.3.5)
17
- json (>= 1.4.6)
18
- term-ansicolor (>= 1.0.5)
19
- diff-lcs (1.1.2)
20
- gherkin (2.3.5)
21
- json (>= 1.4.6)
22
- innate (2011.01)
23
- rack (>= 1.1.0)
24
- json (1.5.1)
25
- mechanize (1.0.0)
26
- nokogiri (>= 1.2.1)
27
- nokogiri (1.4.4)
28
- rack (1.1.2)
29
- rake (0.8.7)
30
- ramaze (2011.01.30)
31
- innate (>= 2010.03)
32
- rspec (2.5.0)
33
- rspec-core (~> 2.5.0)
34
- rspec-expectations (~> 2.5.0)
35
- rspec-mocks (~> 2.5.0)
36
- rspec-core (2.5.1)
37
- rspec-expectations (2.5.0)
38
- diff-lcs (~> 1.1.2)
39
- rspec-mocks (2.5.0)
40
- term-ansicolor (1.0.5)
41
-
42
- PLATFORMS
43
- ruby
44
-
45
- DEPENDENCIES
46
- bundler
47
- cucumber
48
- mirage!
49
- rake
50
- rspec