mirage 3.0.0.alpha.11 → 3.0.0.alpha.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.lock +1 -1
  3. data/VERSION +1 -1
  4. data/features/.nav +19 -0
  5. data/features/client/clear.feature +15 -23
  6. data/features/client/configure.feature +24 -28
  7. data/features/client/preview_responses.feature +4 -4
  8. data/features/client/put.feature +49 -62
  9. data/features/client/requests.feature +1 -1
  10. data/features/client/running.feature +2 -2
  11. data/features/client/save_and_revert.feature +5 -8
  12. data/features/client/start.feature +3 -3
  13. data/features/client/stop.feature +8 -8
  14. data/features/commandline_interface/help.feature +17 -0
  15. data/features/commandline_interface/readme.md +1 -0
  16. data/features/{server/commandline_interface → commandline_interface}/start.feature +4 -4
  17. data/features/{server/commandline_interface → commandline_interface}/stop.feature +22 -24
  18. data/features/{server/logging.feature → logging.feature} +2 -2
  19. data/features/{server/prime.feature → prime.feature} +4 -3
  20. data/features/readme.md +7 -0
  21. data/features/requests/delete.feature +48 -0
  22. data/features/{server/requests → requests}/get.feature +6 -5
  23. data/features/{server/save_and_revert.feature → save_and_revert.feature} +5 -5
  24. data/features/step_definitions/my_steps.rb +47 -12
  25. data/features/support/command_line.rb +1 -1
  26. data/features/templates/delete.feature +45 -0
  27. data/features/{server/templates → templates}/get.feature +9 -5
  28. data/features/templates/put.feature +77 -0
  29. data/features/{server/templates/put → templates}/put_with_substitutions.feature +4 -3
  30. data/features/templates/readme.md +7 -0
  31. data/features/{server/templates/put → templates}/required_content.feature +27 -35
  32. data/features/{server/web_user_interface.feature → web_user_interface.feature} +8 -7
  33. data/lib/mirage/client/cli_bridge.rb +1 -1
  34. data/lib/mirage/client/client.rb +16 -3
  35. data/lib/mirage/client/error.rb +1 -1
  36. data/lib/mirage/client/runner.rb +1 -1
  37. data/lib/mirage/client/template.rb +4 -2
  38. data/lib/mirage/client/template/configuration.rb +10 -0
  39. data/lib/mirage/client/template/model/instance_methods.rb +3 -4
  40. data/lib/mirage/client/templates.rb +1 -1
  41. data/mirage.gemspec +21 -17
  42. data/mirage_server.rb +1 -1
  43. data/server/mock_response.rb +18 -17
  44. data/server/server.rb +15 -15
  45. data/spec/client/client_spec.rb +44 -10
  46. data/spec/client/template/model/common_methods_spec.rb +1 -1
  47. data/spec/client/template/model/instance_methods_spec.rb +2 -2
  48. data/spec/client/template_spec.rb +11 -4
  49. data/spec/client/templates_spec.rb +10 -4
  50. data/spec/server/server_spec.rb +23 -23
  51. data/test.rb +2 -19
  52. metadata +22 -18
  53. data/features/server/commandline_interface/help.feature +0 -16
  54. data/features/server/requests/delete.feature +0 -47
  55. data/features/server/templates/delete.feature +0 -44
  56. data/features/server/templates/put/put.feature +0 -62
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'sinatra'
4
4
  gem 'childprocess'
data/Gemfile.lock CHANGED
@@ -1,5 +1,5 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
4
  backports (2.3.0)
5
5
  bouncy-castle-java (1.5.0146.1)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0.alpha.11
1
+ 3.0.0.alpha.12
data/features/.nav ADDED
@@ -0,0 +1,19 @@
1
+ - commandline_interface (Commandline interface):
2
+ - help.feature
3
+ - start.feature
4
+ - stop.featre
5
+ - templates (Templates):
6
+ - put.feature
7
+ - required_content.feature
8
+ - put_with_substitutions.feature
9
+ - get.feature
10
+ - delete.feature
11
+ - requests:
12
+ - get.feature
13
+ - delete.feature
14
+ - requests:
15
+ - save_and_revert.feature (Snapshot)
16
+ - prime.feature
17
+ - logging.feature (Logs)
18
+ - web_user_interface.feature
19
+ - client (Ruby client):
@@ -11,11 +11,11 @@ Feature: The client can be used for clearing down Mirage.
11
11
 
12
12
  And a template for 'greeting' has been set with a value of 'Hello'
13
13
 
14
- And I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
14
+ And I send GET to '/responses/greeting' with parameters:
15
15
  | message | hello there |
16
16
  And a template for 'leaving' has been set with a value of 'Goodbye'
17
17
 
18
- And I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
18
+ And I send GET to '/responses/greeting' with parameters:
19
19
  | message | I'm going |
20
20
 
21
21
 
@@ -24,14 +24,14 @@ Feature: The client can be used for clearing down Mirage.
24
24
  """
25
25
  Mirage::Client.new.templates(1).delete
26
26
  """
27
- When GET is sent to 'http://localhost:7001/mirage/responses/greeting'
27
+ When GET is sent to '/responses/greeting'
28
28
  Then a 404 should be returned
29
- When GET is sent to 'http://localhost:7001/mirage/requests/1'
29
+ When GET is sent to '/requests/1'
30
30
  Then a 404 should be returned
31
31
 
32
- When GET is sent to 'http://localhost:7001/mirage/responses/leaving'
32
+ When GET is sent to '/responses/leaving'
33
33
  Then a 200 should be returned
34
- When GET is sent to 'http://localhost:7001/mirage/requests/2'
34
+ When GET is sent to '/requests/2'
35
35
  Then a 200 should be returned
36
36
 
37
37
 
@@ -40,9 +40,9 @@ Feature: The client can be used for clearing down Mirage.
40
40
  """
41
41
  Mirage::Client.new.requests(1).delete
42
42
  """
43
- When GET is sent to 'http://localhost:7001/mirage/requests/1'
43
+ When GET is sent to '/requests/1'
44
44
  Then a 404 should be returned
45
- When GET is sent to 'http://localhost:7001/mirage/responses/greeting'
45
+ When GET is sent to '/responses/greeting'
46
46
  Then a 200 should be returned
47
47
 
48
48
 
@@ -51,16 +51,16 @@ Feature: The client can be used for clearing down Mirage.
51
51
  """
52
52
  Mirage::Client.new.templates.delete_all
53
53
  """
54
- And GET is sent to 'http://localhost:7001/mirage/responses/greeting'
54
+ And GET is sent to '/responses/greeting'
55
55
  Then a 404 should be returned
56
56
 
57
- When GET is sent to 'http://localhost:7001/mirage/requests/1'
57
+ When GET is sent to '/requests/1'
58
58
  Then a 404 should be returned
59
59
 
60
- And GET is sent to 'http://localhost:7001/mirage/responses/leaving'
60
+ And GET is sent to '/responses/leaving'
61
61
  Then a 404 should be returned
62
62
 
63
- When GET is sent to 'http://localhost:7001/mirage/requests/2'
63
+ When GET is sent to '/requests/2'
64
64
  Then a 404 should be returned
65
65
 
66
66
 
@@ -69,16 +69,8 @@ Feature: The client can be used for clearing down Mirage.
69
69
  """
70
70
  Mirage::Client.new.requests.delete_all
71
71
  """
72
- When GET is sent to 'http://localhost:7001/mirage/requests/1'
72
+ When GET is sent to '/requests/1'
73
73
  Then a 404 should be returned
74
74
 
75
- When GET is sent to 'http://localhost:7001/mirage/requests/2'
76
- Then a 404 should be returned
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
75
+ When GET is sent to '/requests/2'
76
+ Then a 404 should be returned
@@ -11,17 +11,17 @@ Feature: The client can be configured with default settings to keep your mocking
11
11
  Scenario: configuring the client on instance
12
12
  Given I run
13
13
  """
14
- client = Mirage::Client.new do |defaults|
15
- defaults.method = :post
16
- defaults.status = 202
17
- defaults.default = true
18
- defaults.delay = 2
19
- defaults.content_type = "text/xml"
14
+ client = Mirage::Client.new do
15
+ http_method :post
16
+ status 202
17
+ default true
18
+ delay 2
19
+ content_type "text/xml"
20
20
  end
21
21
 
22
22
  client.put('greeting','hello')
23
23
  """
24
- When POST is sent to 'http://localhost:7001/mirage/responses/greeting/for/someone'
24
+ When POST is sent to '/responses/greeting/for/someone'
25
25
  Then 'hello' should be returned
26
26
  And a 202 should be returned
27
27
  Then it should take at least '2' seconds
@@ -31,17 +31,17 @@ Feature: The client can be configured with default settings to keep your mocking
31
31
  Given I run
32
32
  """
33
33
  client = Mirage::Client.new
34
- client.configure do |defaults|
35
- defaults.method = :post
36
- defaults.status = 202
37
- defaults.default = true
38
- defaults.delay = 2
39
- defaults.content_type = "text/xml"
34
+ client.configure do
35
+ http_method :post
36
+ status 202
37
+ default false
38
+ delay 2
39
+ content_type "text/xml"
40
40
  end
41
41
 
42
42
  client.put('greeting','hello')
43
43
  """
44
- When POST is sent to 'http://localhost:7001/mirage/responses/greeting/for/someone'
44
+ When POST is sent to '/responses/greeting'
45
45
  Then 'hello' should be returned
46
46
  And a 202 should be returned
47
47
  Then it should take at least '2' seconds
@@ -51,24 +51,20 @@ Feature: The client can be configured with default settings to keep your mocking
51
51
  Given I run
52
52
  """
53
53
  client = Mirage::Client.new
54
- client.configure do |defaults|
55
- defaults.method = :post
56
- defaults.status = 202
57
- defaults.default = true
58
- defaults.delay = 2
59
- defaults.content_type = "text/xml"
54
+ client.configure do
55
+ http_method :post
56
+ status 202
57
+ default true
58
+ delay 2
59
+ content_type "text/xml"
60
60
  end
61
61
 
62
62
  client.reset
63
-
64
- client.configure do |defaults|
65
- defaults.method.should == nil
66
- defaults.status.should == nil
67
- defaults.default.should == nil
68
- defaults.delay.should == nil
69
- defaults.content_type.should == nil
70
- end
63
+ client.put('greeting','hello')
71
64
  """
65
+ When GET is sent to '/responses/greeting'
66
+ Then 'hello' should be returned
67
+
72
68
 
73
69
 
74
70
 
@@ -9,21 +9,21 @@ Feature: the client can be used for peeking at responses hosted on Mirage.
9
9
  """
10
10
 
11
11
  Scenario: peeking a response
12
- Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
12
+ Given a template for 'greeting' has been set with a value of 'Hello'
13
13
 
14
14
  When I run
15
15
  """
16
- Mirage::Client.new.response(1).should == 'Hello'
16
+ Mirage::Client.new.templates(1).body.should == 'Hello'
17
17
  """
18
18
 
19
- When I send GET to 'http://localhost:7001/mirage/requests/1'
19
+ When GET is sent to '/requests/1'
20
20
  Then a 404 should be returned
21
21
 
22
22
  Scenario: getting a response that does not exist
23
23
  Given I run
24
24
  """
25
25
  begin
26
- Mirage::Client.new.response(2).should == 'this should not have happened'
26
+ Mirage::Client.new.templates(2).should == 'this should not have happened'
27
27
  fail("Error should have been thrown")
28
28
  rescue Exception => e
29
29
  puts e
@@ -17,33 +17,33 @@ Feature: the Mirage client provides methods for setting responses and loading de
17
17
  """
18
18
  Mirage::Client.new.put('greeting','hello')
19
19
  """
20
- When I send GET to 'http://localhost:7001/mirage/responses/greeting'
20
+ When GET is sent to '/responses/greeting'
21
21
  Then 'hello' should be returned
22
22
 
23
23
  Scenario: Setting the method that a response should be returned on
24
24
  Given I run
25
25
  """
26
- Mirage::Client.new.put('greeting', 'Hello Leon') do |response|
27
- response.method = 'POST'
26
+ Mirage::Client.new.put('greeting', 'Hello Leon') do
27
+ http_method 'POST'
28
28
  end
29
29
  """
30
- When I send GET to 'http://localhost:7001/mirage/responses/greeting'
30
+ When GET is sent to '/responses/greeting'
31
31
  Then a 404 should be returned
32
- When I send POST to 'http://localhost:7001/mirage/responses/greeting'
32
+ When POST is sent to '/responses/greeting'
33
33
  Then 'Hello Leon' should be returned
34
34
 
35
35
 
36
36
  Scenario: Setting a response with required body content
37
37
  Given I run
38
38
  """
39
- Mirage::Client.new.put('greeting', 'Hello Leon') do |response|
40
- response.method = 'POST'
41
- response.add_body_content_requirement /leon/
39
+ Mirage::Client.new.put('greeting', 'Hello Leon') do
40
+ http_method 'POST'
41
+ required_body_content << /leon/
42
42
  end
43
43
  """
44
- When I send POST to 'http://localhost:7001/mirage/responses/greeting'
44
+ When POST is sent to '/responses/greeting'
45
45
  Then a 404 should be returned
46
- When I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
46
+ When I send POST to '/responses/greeting' with request entity
47
47
  """
48
48
  <greetingRequest>
49
49
  <name>leon</name>
@@ -54,14 +54,14 @@ Feature: the Mirage client provides methods for setting responses and loading de
54
54
  Scenario: Setting a response with a request parameter requirement
55
55
  Given I run
56
56
  """
57
- Mirage::Client.new.put('greeting', 'Hello Leon') do |response|
58
- response.method = 'POST'
59
- response.add_request_parameter_requirement :name, /leon/
57
+ Mirage::Client.new.put('greeting', 'Hello Leon') do
58
+ http_method 'POST'
59
+ required_parameters[:name] = /leon/
60
60
  end
61
61
  """
62
- When I send POST to 'http://localhost:7001/mirage/responses/greeting'
62
+ When POST is sent to '/responses/greeting'
63
63
  Then a 404 should be returned
64
- When I send POST to 'http://localhost:7001/mirage/responses/greeting' with parameters:
64
+ When I send POST to '/responses/greeting' with parameters:
65
65
  | name | leon |
66
66
 
67
67
  Then 'Hello Leon' should be returned
@@ -69,59 +69,46 @@ Feature: the Mirage client provides methods for setting responses and loading de
69
69
  Scenario: setting a response as default
70
70
  Given I run
71
71
  """
72
- Mirage::Client.new.put('greeting', 'default greeting') do |response|
73
- response.default = true
72
+ Mirage.start.clear
73
+
74
+ Mirage::Client.new.put('greeting', 'default greeting') do
75
+ default true
74
76
  end
75
77
  """
76
- When I send GET to 'http://localhost:7001/mirage/responses/greeting/for/joel'
78
+ When GET is sent to '/responses/greeting/for/joel'
77
79
  Then 'default greeting' should be returned
78
80
 
79
81
 
80
82
  Scenario: Setting the content type
81
83
  Given I run
82
84
  """
83
- Mirage::Client.new.put('greeting', '<xml></xml>') do |response|
84
- response.content_type = 'text/xml'
85
+ Mirage::Client.new.put('greeting', '<xml></xml>') do
86
+ content_type 'text/xml'
85
87
  end
86
88
  """
87
- When I send GET to 'http://localhost:7001/mirage/responses/greeting'
89
+ When GET is sent to '/responses/greeting'
88
90
  And the response 'content-type' should be 'text/xml'
89
91
 
90
- Scenario: Priming Mirage
91
- Given Mirage is not running
92
- And I run 'mirage start'
93
-
94
- When the file 'responses/default_greetings.rb' contains:
95
- """
96
- prime do |mirage|
97
- mirage.put('greeting', 'hello')
98
- mirage.put('leaving', 'goodbye')
99
- end
100
- """
101
- And I run
102
- """
103
- Mirage::Client.new.prime
104
- """
105
- And I send GET to 'http://localhost:7001/mirage/responses/greeting'
106
- Then 'hello' should be returned
107
-
108
- When I send GET to 'http://localhost:7001/mirage/responses/leaving'
109
- Then 'goodbye' should be returned
110
-
111
- Scenario: Priming Mirage when one of the response file has something bad in it
112
- Given the file 'responses/default_greetings.rb' contains:
113
- """
114
- Something bad...
115
- """
116
- When I run
117
- """
118
- begin
119
- Mirage::Client.new.prime
120
- fail("Error should have been thrown")
121
- rescue Exception => e
122
- e.is_a?(Mirage::InternalServerException).should == true
123
- end
124
- """
92
+ # Scenario: Priming Mirage
93
+ # Given Mirage is not running
94
+ # And I run 'mirage start'
95
+ #
96
+ # When the file 'responses/default_greetings.rb' contains:
97
+ # """
98
+ # prime do |mirage|
99
+ # mirage.put('greeting', 'hello')
100
+ # mirage.put('leaving', 'goodbye')
101
+ # end
102
+ # """
103
+ # And I run
104
+ # """
105
+ # Mirage::Client.new.prime
106
+ # """
107
+ # And GET is sent to '/responses/greeting'
108
+ # Then 'hello' should be returned
109
+ #
110
+ # When GET is sent to '/responses/leaving'
111
+ # Then 'goodbye' should be returned
125
112
 
126
113
  Scenario: Setting a file as a response
127
114
  Given the file 'test_file.txt' contains:
@@ -130,24 +117,24 @@ Feature: the Mirage client provides methods for setting responses and loading de
130
117
  """
131
118
  And I run
132
119
  """
133
- Mirage::Client.new.put('download', File.open('test_file.txt'))
120
+ Mirage::Client.new.put('download', File.read('test_file.txt'))
134
121
  """
135
- When I send GET to 'http://localhost:7001/mirage/responses/download'
122
+ When GET is sent to '/responses/download'
136
123
  Then the response should be the same as the content of 'test_file.txt'
137
124
 
138
125
  Scenario: Setting a response status code
139
126
  Given I run
140
127
  """
141
- Mirage::Client.new.put('greeting', 'hello'){|response| response.status = 203}
128
+ Mirage::Client.new.put('greeting', 'hello'){status 203}
142
129
  """
143
- When I send GET to 'http://localhost:7001/mirage/responses/greeting'
130
+ When GET is sent to '/responses/greeting'
144
131
  Then a 203 should be returned
145
132
 
146
133
 
147
134
  Scenario: Setting a response with a delay
148
135
  Given I run
149
136
  """
150
- Mirage::Client.new.put('greeting', 'hello'){|response| response.delay = 2}
137
+ Mirage::Client.new.put('greeting', 'hello'){delay 2}
151
138
  """
152
- When I send GET to 'http://localhost:7001/mirage/responses/greeting'
139
+ When GET is sent to '/responses/greeting'
153
140
  Then it should take at least '2' seconds
@@ -10,7 +10,7 @@ Feature: Requests made to the Mirage Server can be retrieved using the Mirage cl
10
10
  Scenario: Retrieving request data
11
11
  Given a template for 'greeting' has been set with a value of 'Hello'
12
12
 
13
- When I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
13
+ When I send GET to '/responses/greeting' with parameters:
14
14
  | name | leon |
15
15
  Then I run
16
16
  """
@@ -36,7 +36,7 @@ Feature: Use the mirage client api to check if Mirage is running either on the l
36
36
  Given I run 'mirage start -p 9001'
37
37
  Then I run
38
38
  """
39
- Mirage.running? "http://localhost:9001/mirage"
39
+ Mirage.running? "http://localhost:9001"
40
40
  """
41
41
 
42
42
 
@@ -44,6 +44,6 @@ Feature: Use the mirage client api to check if Mirage is running either on the l
44
44
  Given I run 'mirage start -p 9001'
45
45
  Then I run
46
46
  """
47
- client = Mirage::Client.new "http://localhost:9001/mirage"
47
+ client = Mirage::Client.new "http://localhost:9001"
48
48
  client.running?.should == true
49
49
  """
@@ -8,10 +8,7 @@ Feature: The Mirage client can be used to snaphsot and rollback the Mirage serve
8
8
  require 'rspec'
9
9
  require 'mirage/client'
10
10
  """
11
- And I send PUT to 'http://localhost:7001/mirage/templates/greeting' with request entity
12
- """
13
- The default greeting
14
- """
11
+ And a template for 'greeting' has been set with a value of 'The default greeting'
15
12
 
16
13
 
17
14
  Scenario: saving and reverting
@@ -19,12 +16,12 @@ Feature: The Mirage client can be used to snaphsot and rollback the Mirage serve
19
16
  """
20
17
  Mirage::Client.new.save
21
18
  """
22
- And I send PUT to 'http://localhost:7001/mirage/templates/leaving' with request entity
19
+ And I send PUT to '/templates/leaving' with request entity
23
20
  """
24
21
  Goodbye
25
22
  """
26
23
 
27
- And I send PUT to 'http://localhost:7001/mirage/templates/greeting' with request entity
24
+ And I send PUT to '/templates/greeting' with request entity
28
25
  """
29
26
  Changed
30
27
  """
@@ -33,8 +30,8 @@ Feature: The Mirage client can be used to snaphsot and rollback the Mirage serve
33
30
  """
34
31
  Mirage::Client.new.revert
35
32
  """
36
- And I send GET to 'http://localhost:7001/mirage/responses/leaving'
33
+ And GET is sent to '/responses/leaving'
37
34
  Then a 404 should be returned
38
35
 
39
- When I send GET to 'http://localhost:7001/mirage/responses/greeting'
36
+ When GET is sent to '/responses/greeting'
40
37
  Then 'The default greeting' should be returned