mirage 1.3.6 → 2.0.0.alpha1

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.
Files changed (36) hide show
  1. data/Gemfile +7 -4
  2. data/VERSION +1 -1
  3. data/bin/mirage +2 -0
  4. data/features/client/clear.feature +38 -20
  5. data/features/client/peek.feature +11 -11
  6. data/features/client/save_and_revert.feature +14 -8
  7. data/features/client/set.feature +59 -13
  8. data/features/client/track.feature +5 -3
  9. data/features/server/clear.feature +59 -47
  10. data/features/server/logging.feature +2 -3
  11. data/features/server/peek.feature +12 -10
  12. data/features/server/prime.feature +15 -13
  13. data/features/server/response_templates.feature +9 -16
  14. data/features/server/save_and_revert.feature +11 -14
  15. data/features/server/set.feature +44 -17
  16. data/features/server/set_default_response.feature +19 -25
  17. data/features/server/set_with_a_delay.feature +3 -5
  18. data/features/server/set_with_a_pattern.feature +24 -29
  19. data/features/server/track_requests.feature +71 -0
  20. data/features/server/web_user_interface.feature +7 -8
  21. data/features/step_definitions/my_steps.rb +83 -28
  22. data/features/support/env.rb +0 -14
  23. data/lib/mirage.rb +3 -0
  24. data/lib/mirage/client.rb +48 -43
  25. data/lib/mirage/core.rb +65 -152
  26. data/lib/mirage/mock_response.rb +49 -0
  27. data/lib/mirage/mock_responses_collection.rb +109 -0
  28. data/lib/mirage/object.rb +5 -0
  29. data/lib/mirage/web.rb +37 -28
  30. data/lib/start_mirage.rb +27 -5
  31. data/lib/{view/mirage/index.xhtml → views/index.erb} +5 -5
  32. data/mirage.gemspec +7 -7
  33. metadata +57 -23
  34. data/features/client/get.feature +0 -46
  35. data/features/server/file_responses.feature +0 -8
  36. data/features/server/track.feature +0 -74
data/Gemfile CHANGED
@@ -1,15 +1,18 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
3
  gem 'rack', '~> 1.1.0'
4
- gem 'ramaze', '>= 2011.01.30'
5
- gem 'mechanize', '>= 1.0.0'
4
+ gem 'sinatra'
6
5
  gem 'childprocess', '~> 0.1'
7
6
 
8
7
  group :development do
9
- gem 'rake'
8
+ gem 'rake', '0.9.0'
10
9
  gem 'cucumber'
10
+ gem 'gherkin', '2.3.9'
11
11
  gem 'rspec'
12
12
  gem "jeweler", "~> 1.5.2"
13
13
  gem 'bundler'
14
+ gem 'sinatra-reloader'
15
+ gem 'mechanize', '>= 1.0.0'
16
+ gem 'gemcutter'
14
17
  end
15
18
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.6
1
+ 2.0.0.alpha1
data/bin/mirage CHANGED
@@ -32,6 +32,8 @@ end
32
32
 
33
33
  def stop_mirage
34
34
  mirage_process_ids.each { |process_id| windows? ? `taskkill /F /T /PID #{process_id}` : `kill -9 #{process_id}` }
35
+ wait_until{ mirage_process_ids.size == 0 }
36
+
35
37
  end
36
38
 
37
39
  if ARGV.include?('start')
@@ -7,36 +7,37 @@ Feature: The client can be used for clearing responses from Mirage
7
7
  require 'rspec'
8
8
  require 'mirage'
9
9
  """
10
- And I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
11
- | response | Hello |
12
-
13
- And I hit 'http://localhost:7001/mirage/get/greeting' with request body:
10
+
11
+ And I send PUT to 'http://localhost:7001/mirage/templates/greeting' with request entity
14
12
  """
15
- Hello there
13
+ Hello
16
14
  """
17
- And I hit 'http://localhost:7001/mirage/set/leaving' with parameters:
18
- | response | Goodbye |
19
-
20
- And I hit 'http://localhost:7001/mirage/get/greeting' with request body:
15
+ And I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
16
+ | message | hello there |
17
+
18
+ And I send PUT to 'http://localhost:7001/mirage/templates/leaving' with request entity
21
19
  """
22
- I'm going
20
+ Goodbye
23
21
  """
22
+ And I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
23
+ | message | I'm going |
24
24
 
25
+
25
26
  Scenario: Clearing everything
26
27
  When I run
27
28
  """
28
29
  Mirage::Client.new.clear
29
30
  """
30
- And I hit 'http://localhost:7001/mirage/get/greeting'
31
+ And I send GET to 'http://localhost:7001/mirage/responses/greeting'
31
32
  Then a 404 should be returned
32
33
 
33
- When I hit 'http://localhost:7001/mirage/check/1'
34
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
34
35
  Then a 404 should be returned
35
36
 
36
- And I hit 'http://localhost:7001/mirage/get/leaving'
37
+ And I send GET to 'http://localhost:7001/mirage/responses/leaving'
37
38
  Then a 404 should be returned
38
39
 
39
- When I hit 'http://localhost:7001/mirage/check/2'
40
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
40
41
  Then a 404 should be returned
41
42
 
42
43
 
@@ -45,29 +46,46 @@ Feature: The client can be used for clearing responses from Mirage
45
46
  """
46
47
  Mirage::Client.new.clear :requests
47
48
  """
48
- When I hit 'http://localhost:7001/mirage/check/1'
49
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
49
50
  Then a 404 should be returned
50
51
 
51
- When I hit 'http://localhost:7001/mirage/check/2'
52
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
52
53
  Then a 404 should be returned
54
+
55
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
56
+ Then a 200 should be returned
57
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
58
+ Then a 200 should be returned
59
+
53
60
 
54
61
  Scenario: Clearning a response
55
62
  Given I run
56
63
  """
57
- Mirage::Client.new.clear 1
64
+ Mirage::Client.new.clear 1
58
65
  """
59
- When I hit 'http://localhost:7001/mirage/get/greeting'
66
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
60
67
  Then a 404 should be returned
61
- When I hit 'http://localhost:7001/mirage/check/1'
68
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
62
69
  Then a 404 should be returned
70
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
71
+ Then a 200 should be returned
72
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
73
+ Then a 200 should be returned
74
+
63
75
 
64
76
  Scenario: Clearning a request
65
77
  Given I run
66
78
  """
67
79
  Mirage::Client.new.clear :request => 1
68
80
  """
69
- When I hit 'http://localhost:7001/mirage/check/1'
81
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
70
82
  Then a 404 should be returned
83
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
84
+ Then a 200 should be returned
85
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
86
+ Then a 200 should be returned
87
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
88
+ Then a 200 should be returned
71
89
 
72
90
 
73
91
 
@@ -8,17 +8,16 @@ Feature: the client can be used for peeking at responses hosted on Mirage.
8
8
  require 'mirage'
9
9
  """
10
10
 
11
- Scenario: peeking a response
12
- Given I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
13
- | response | Hello |
14
-
15
- When I run
16
- """
17
- Mirage::Client.new.peek(1).should == 'Hello'
18
- """
19
-
20
- When I hit 'http://localhost:7001/mirage/check/1'
21
- Then a 404 should be returned
11
+ # Scenario: peeking a response
12
+ # Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
13
+ #
14
+ # When I run
15
+ # """
16
+ # Mirage::Client.new.peek(1).should == 'Hello'
17
+ # """
18
+ #
19
+ # When I send GET to 'http://localhost:7001/mirage/requests/1'
20
+ # Then a 404 should be returned
22
21
 
23
22
  Scenario: getting a response that does not exist
24
23
  Given I run
@@ -27,6 +26,7 @@ Feature: the client can be used for peeking at responses hosted on Mirage.
27
26
  Mirage::Client.new.peek(2).should == 'this should not have happened'
28
27
  fail("Error should have been thrown")
29
28
  rescue Exception => e
29
+ puts e
30
30
  e.is_a?(Mirage::ResponseNotFound).should == true
31
31
  end
32
32
  """
@@ -8,8 +8,10 @@ Feature: The Mirage client can be used to snaphsot and rollback the Mirage serve
8
8
  require 'rspec'
9
9
  require 'mirage'
10
10
  """
11
- And I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
12
- | response | The default greeting |
11
+ And I send PUT to 'http://localhost:7001/mirage/templates/greeting' with request entity
12
+ """
13
+ The default greeting
14
+ """
13
15
 
14
16
 
15
17
  Scenario: saving and reverting
@@ -17,18 +19,22 @@ Feature: The Mirage client can be used to snaphsot and rollback the Mirage serve
17
19
  """
18
20
  Mirage::Client.new.save
19
21
  """
20
- And I hit 'http://localhost:7001/mirage/set/leaving' with parameters:
21
- | response | Goodye |
22
+ And I send PUT to 'http://localhost:7001/mirage/templates/leaving' with request entity
23
+ """
24
+ Goodbye
25
+ """
22
26
 
23
- And I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
24
- | response | Changed |
27
+ And I send PUT to 'http://localhost:7001/mirage/set/greeting' with request entity
28
+ """
29
+ Changed
30
+ """
25
31
 
26
32
  When I run
27
33
  """
28
34
  Mirage::Client.new.revert
29
35
  """
30
- And I hit 'http://localhost:7001/mirage/get/leaving'
36
+ And I send GET to 'http://localhost:7001/mirage/responses/leaving'
31
37
  Then a 404 should be returned
32
38
 
33
- When I hit 'http://localhost:7001/mirage/get/greeting'
39
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
34
40
  Then 'The default greeting' should be returned
@@ -10,25 +10,40 @@ Feature: the Mirage client provides methods for setting responses and loading de
10
10
  require 'rspec'
11
11
  require 'mirage'
12
12
  """
13
-
13
+
14
14
 
15
15
  Scenario: Setting a basic response
16
16
  Given I run
17
17
  """
18
18
  Mirage::Client.new.set('greeting','hello')
19
19
  """
20
- When I hit 'http://localhost:7001/mirage/get/greeting'
20
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
21
21
  Then 'hello' should be returned
22
-
22
+
23
+ Scenario: Setting the method that a response should be returned on
24
+ Given I run
25
+ """
26
+ Mirage::Client.new.set('greeting', 'Hello Leon') do |response|
27
+ response.method = 'POST'
28
+ end
29
+ """
30
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
31
+ Then a 404 should be returned
32
+ When I send POST to 'http://localhost:7001/mirage/responses/greeting'
33
+ Then 'Hello Leon' should be returned
34
+
23
35
 
24
36
  Scenario Outline: Setting a response with a pattern
25
37
  Given I run
26
38
  """
27
- Mirage::Client.new.set('greeting', 'Hello Leon', :pattern => <pattern>)
39
+ Mirage::Client.new.set('greeting', 'Hello Leon') do |response|
40
+ response.method = 'POST'
41
+ response.pattern = <pattern>
42
+ end
28
43
  """
29
- When I hit 'http://localhost:7001/mirage/get/greeting'
44
+ When I send POST to 'http://localhost:7001/mirage/responses/greeting'
30
45
  Then a 404 should be returned
31
- When I hit 'http://localhost:7001/mirage/get/greeting' with request body:
46
+ When I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
32
47
  """
33
48
  <greetingRequest>
34
49
  <name>leon</name>
@@ -36,10 +51,20 @@ Feature: the Mirage client provides methods for setting responses and loading de
36
51
  """
37
52
  Then 'Hello Leon' should be returned
38
53
  Examples:
39
- | pattern |
54
+ | pattern |
40
55
  | /.*?>leon<\\/name>/ |
41
56
  | 'leon' |
42
-
57
+
58
+
59
+ Scenario: Setting the content type
60
+ Given I run
61
+ """
62
+ Mirage::Client.new.set('greeting', '<xml></xml>') do |response|
63
+ response.content_type = 'text/xml'
64
+ end
65
+ """
66
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
67
+ And the response 'content-type' should be 'text/xml'
43
68
 
44
69
  Scenario: Priming Mirage
45
70
  Given Mirage is not running
@@ -56,12 +81,32 @@ Feature: the Mirage client provides methods for setting responses and loading de
56
81
  """
57
82
  Mirage::Client.new.prime
58
83
  """
59
- And I hit 'http://localhost:7001/mirage/get/greeting'
84
+ And I send GET to 'http://localhost:7001/mirage/responses/greeting'
60
85
  Then 'hello' should be returned
61
86
 
62
- When I hit 'http://localhost:7001/mirage/get/leaving'
87
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
63
88
  Then 'goodbye' should be returned
64
89
 
90
+ Scenario: A file is given to the client with substitution in it
91
+ Given the file 'response_file' contains:
92
+ """
93
+ Hello ${<firstname>(.*?)</firstname>} ${<surname>(.*?)</surname>}, how are you?
94
+ """
95
+ And I run
96
+ """
97
+ puts Dir.pwd
98
+ Mirage::Client.new.set('greeting', File.open('scratch/response_file')) do |response|
99
+ response.method = 'POST'
100
+ end
101
+ """
102
+ When I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
103
+ """
104
+ <grettingRequest>
105
+ <firstname>Leon</firstname>
106
+ <surname>Davis</surname>
107
+ </greetingRequest>
108
+ """
109
+ Then 'Hello Leon Davis, how are you?' should be returned
65
110
 
66
111
  Scenario: Priming Mirage when one of the response file has something bad in it
67
112
  Given the file 'responses/default_greetings.rb' contains:
@@ -77,12 +122,13 @@ Feature: the Mirage client provides methods for setting responses and loading de
77
122
  e.is_a?(Mirage::InternalServerException).should == true
78
123
  end
79
124
  """
80
-
125
+ #
126
+ #
81
127
 
82
128
  Scenario: Setting a file as a response
83
129
  Given I run
84
130
  """
85
131
  Mirage::Client.new.set('download', File.open('README.md'))
86
132
  """
87
- When I hit 'http://localhost:7001/mirage/get/download'
88
- Then the response should be a file the same as 'README.md'
133
+ When I send GET to 'http://localhost:7001/mirage/responses/download'
134
+ Then the response should be the same as the content of 'README.md'
@@ -9,10 +9,12 @@ Feature: Requests made to the Mirage Server can be tracked using the Mirage clie
9
9
  """
10
10
 
11
11
  Scenario: The MockServer returns a response
12
- Given I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
13
- | response | Hello |
12
+ Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with request entity
13
+ """
14
+ Hello
15
+ """
14
16
 
15
- When I hit 'http://localhost:7001/mirage/get/greeting' with parameters:
17
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
16
18
  | name | leon |
17
19
  Then I run
18
20
  """
@@ -8,74 +8,86 @@ Feature: Responses and requests can be cleared.
8
8
  ${mirage_url}/clear/request/response_id - Clear request for a particular response
9
9
 
10
10
 
11
-
12
11
  Background: The MockServer has already got a response for greeting and leaving on it.
13
- Given I post to 'http://localhost:7001/mirage/set/greeting' with parameters:
14
- | response | Hello |
15
-
16
- And I post to 'http://localhost:7001/mirage/set/leaving' with parameters:
17
- | response | Goodbye |
12
+ Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
13
+ And I send GET to 'http://localhost:7001/mirage/responses/greeting'
18
14
 
15
+ And I send PUT to 'http://localhost:7001/mirage/templates/leaving' with body 'Goodbye'
16
+ And I send GET to 'http://localhost:7001/mirage/responses/leaving'
19
17
 
20
18
 
21
19
  Scenario: Clearing all responses
22
- Given I hit 'http://localhost:7001/mirage/clear'
20
+ Given I send DELETE to 'http://localhost:7001/mirage/templates'
23
21
 
24
- When I hit 'http://localhost:7001/mirage/get/greeting'
22
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
23
+ Then a 404 should be returned
24
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
25
+ Then a 404 should be returned
26
+ When I send GET to 'http://localhost:7001/mirage/templates/1'
25
27
  Then a 404 should be returned
26
28
 
27
- When I hit 'http://localhost:7001/mirage/get/leaving'
29
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
30
+ Then a 404 should be returned
31
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
32
+ Then a 404 should be returned
33
+ When I send GET to 'http://localhost:7001/mirage/templates/2'
28
34
  Then a 404 should be returned
29
35
 
30
36
 
31
37
  Scenario: Clearing a particular response
32
- Given I hit 'http://localhost:7001/mirage/clear/1'
38
+ Given I send DELETE to 'http://localhost:7001/mirage/templates/1'
33
39
 
34
- When I hit 'http://localhost:7001/mirage/get/greeting'
40
+ When I send GET to 'http://localhost:7001/mirage/templates/1'
35
41
  Then a 404 should be returned
36
-
37
- When I hit 'http://localhost:7001/mirage/check/1'
42
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
43
+ Then a 404 should be returned
44
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
38
45
  Then a 404 should be returned
39
46
 
40
- When I hit 'http://localhost:7001/mirage/get/leaving'
41
- Then 'Goodbye' should be returned
47
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
48
+ Then a 200 should be returned
49
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
50
+ Then a 200 should be returned
51
+ When I send GET to 'http://localhost:7001/mirage/templates/2'
52
+ Then a 200 should be returned
53
+
42
54
 
43
55
 
44
56
  Scenario: Clearing all requests
45
- Given I hit 'http://localhost:7001/mirage/get/greeting' with request body:
46
- """
47
- Say 'Hello' to me
48
- """
49
- And I hit 'http://localhost:7001/mirage/get/leaving' with request body:
50
- """
51
- Say 'Goodbye' to me
52
- """
53
- And I hit 'http://localhost:7001/mirage/clear'
54
-
55
- When I hit 'http://localhost:7001/mirage/check/1'
56
- Then a 404 should be returned
57
+ And I send DELETE to 'http://localhost:7001/mirage/requests'
57
58
 
58
- When I hit 'http://localhost:7001/mirage/check/2'
59
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
59
60
  Then a 404 should be returned
61
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
62
+ Then a 200 should be returned
63
+ When I send GET to 'http://localhost:7001/mirage/templates/1'
64
+ Then a 200 should be returned
65
+
60
66
 
67
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
68
+ Then a 404 should be returned
69
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
70
+ Then a 200 should be returned
71
+ When I send GET to 'http://localhost:7001/mirage/templates/2'
72
+ Then a 200 should be returned
73
+
61
74
 
62
- Scenario: Clearing a stored request request for a prticular response
63
- Given I hit 'http://localhost:7001/mirage/get/leaving' with request body:
64
- """
65
- See you later
66
- """
67
-
68
- When I hit 'http://localhost:7001/mirage/clear/request/2'
69
- Then I hit 'http://localhost:7001/mirage/check/2'
70
- And a 404 should be returned
71
-
72
-
73
- Scenario: Querying a response that has been cleared
74
- Given I hit 'http://localhost:7001/mirage/get/greeting' with request body:
75
- """
76
- greet me :)
77
- """
78
- And I hit 'http://localhost:7001/mirage/clear/1'
79
75
 
80
- When I hit 'http://localhost:7001/mirage/check/1'
81
- Then a 404 should be returned
76
+ Scenario: Clearing a stored request for a prticular response
77
+ And I send DELETE to 'http://localhost:7001/mirage/requests/1'
78
+
79
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
80
+ Then a 404 should be returned
81
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
82
+ Then a 200 should be returned
83
+ When I send GET to 'http://localhost:7001/mirage/templates/1'
84
+ Then a 200 should be returned
85
+
86
+
87
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
88
+ Then a 200 should be returned
89
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
90
+ Then a 200 should be returned
91
+ When I send GET to 'http://localhost:7001/mirage/templates/2'
92
+ Then a 200 should be returned
93
+