mirage 2.4.2 → 3.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.simplecov +6 -0
  2. data/Gemfile +11 -3
  3. data/Gemfile.lock +41 -14
  4. data/VERSION +1 -1
  5. data/features/client/clear.feature +41 -50
  6. data/features/client/configure.feature +2 -2
  7. data/features/client/put.feature +17 -6
  8. data/features/client/requests.feature +5 -9
  9. data/features/client/start.feature +19 -11
  10. data/features/client/stop.feature +10 -44
  11. data/features/server/commandline_interface/start.feature +2 -14
  12. data/features/server/commandline_interface/stop.feature +6 -4
  13. data/features/server/logging.feature +2 -2
  14. data/features/server/prime.feature +11 -66
  15. data/features/server/requests/delete.feature +34 -33
  16. data/features/server/requests/get.feature +21 -18
  17. data/features/server/save_and_revert.feature +24 -11
  18. data/features/server/templates/delete.feature +29 -32
  19. data/features/server/templates/get.feature +44 -25
  20. data/features/server/templates/put/put.feature +55 -78
  21. data/features/server/templates/put/put_with_substitutions.feature +12 -32
  22. data/features/server/templates/put/required_content.feature +118 -0
  23. data/features/step_definitions/my_steps.rb +51 -6
  24. data/features/support/env.rb +1 -1
  25. data/features/support/hooks.rb +2 -5
  26. data/{lib/mirage/client → features/support}/web.rb +14 -3
  27. data/lib/mirage/client.rb +5 -2
  28. data/lib/mirage/client/client.rb +22 -129
  29. data/lib/mirage/client/request.rb +25 -0
  30. data/lib/mirage/client/requests.rb +13 -0
  31. data/lib/mirage/client/runner.rb +4 -4
  32. data/lib/mirage/client/template.rb +108 -0
  33. data/lib/mirage/client/template_configuration.rb +22 -0
  34. data/lib/mirage/client/templates.rb +26 -0
  35. data/mirage.gemspec +42 -22
  36. data/mirage_server.rb +1 -135
  37. data/rakefile +22 -7
  38. data/server/app.rb +4 -0
  39. data/server/binary_data_checker.rb +15 -0
  40. data/server/helpers.rb +28 -0
  41. data/server/mock_response.rb +140 -58
  42. data/server/server.rb +167 -0
  43. data/spec/{cli_bridge_spec.rb → client/cli_bridge_spec.rb} +15 -11
  44. data/spec/client/client_spec.rb +139 -0
  45. data/spec/client/request_spec.rb +52 -0
  46. data/spec/client/requests_spec.rb +10 -0
  47. data/spec/{runner_spec.rb → client/runner_spec.rb} +3 -3
  48. data/spec/client/template_configuration_spec.rb +32 -0
  49. data/spec/client/template_spec.rb +241 -0
  50. data/spec/client/templates_spec.rb +79 -0
  51. data/spec/resources/binary.file +0 -0
  52. data/spec/server/binary_data_checker_spec.rb +22 -0
  53. data/spec/server/helpers_spec.rb +34 -0
  54. data/spec/server/mock_response_spec.rb +526 -0
  55. data/spec/server/server_spec.rb +132 -0
  56. data/spec/spec_helper.rb +61 -2
  57. data/test.html +12 -0
  58. data/test.rb +20 -17
  59. data/todo.lst +2 -0
  60. data/views/index.haml +22 -0
  61. data/views/response.haml +24 -0
  62. metadata +134 -49
  63. data/features/server/templates/put/put_as_default.feature +0 -42
  64. data/features/server/templates/put/put_with_delay.feature +0 -8
  65. data/features/server/templates/put/put_with_pattern.feature +0 -80
  66. data/lib/mirage/client/response.rb +0 -29
  67. data/spec/client_spec.rb +0 -38
  68. data/views/index.erb +0 -28
data/.simplecov ADDED
@@ -0,0 +1,6 @@
1
+ SimpleCov.start do
2
+ command_name "spec:#{ENV['coverage']}"
3
+ add_filter "/spec/"
4
+ add_group "Server", "server"
5
+ add_group "Client", "lib"
6
+ end
data/Gemfile CHANGED
@@ -4,12 +4,20 @@ gem 'sinatra'
4
4
  gem 'childprocess'
5
5
  gem "waitforit"
6
6
  gem "thor"
7
+ gem "ptools"
8
+ gem "httparty"
9
+ gem "haml"
7
10
 
8
- group :development do
9
- gem "thin"
10
- gem 'rake'
11
+ group :test do
11
12
  gem 'cucumber'
12
13
  gem 'rspec'
14
+ gem 'rack-test'
15
+ gem 'simplecov'
16
+ gem 'hashie'
17
+ end
18
+
19
+ group :development do
20
+ gem 'rake'
13
21
  gem "jeweler"
14
22
  gem 'sinatra-contrib'
15
23
  gem 'mechanize'
data/Gemfile.lock CHANGED
@@ -12,7 +12,6 @@ GEM
12
12
  gherkin (~> 2.7.1)
13
13
  json (>= 1.4.6)
14
14
  term-ansicolor (>= 1.0.6)
15
- daemons (1.1.8)
16
15
  diff-lcs (1.1.3)
17
16
  domain_name (0.5.1)
18
17
  unf (~> 0.0.3)
@@ -28,6 +27,12 @@ GEM
28
27
  gherkin (2.7.2-x86-mingw32)
29
28
  json (>= 1.4.6)
30
29
  git (1.2.5)
30
+ haml (4.0.1)
31
+ tilt
32
+ hashie (2.0.3)
33
+ httparty (0.9.0)
34
+ multi_json (~> 1.0)
35
+ multi_xml
31
36
  jeweler (1.6.4)
32
37
  bundler (~> 1.0)
33
38
  git (>= 1.2.5)
@@ -43,26 +48,35 @@ GEM
43
48
  nokogiri (~> 1.4)
44
49
  ntlm-http (~> 0.1, >= 0.1.1)
45
50
  webrobots (~> 0.0, >= 0.0.9)
51
+ multi_json (1.3.6)
52
+ multi_xml (0.5.1)
46
53
  net-http-digest_auth (1.2)
47
54
  net-http-persistent (2.3.3)
48
55
  nokogiri (1.5.0)
49
56
  nokogiri (1.5.0-java)
50
57
  nokogiri (1.5.0-x86-mingw32)
51
58
  ntlm-http (0.1.1)
59
+ ptools (1.2.2)
60
+ ptools (1.2.2-x86-mingw32)
61
+ win32-file (>= 0.5.4)
52
62
  rack (1.4.0)
53
63
  rack-protection (1.2.0)
54
64
  rack
55
65
  rack-test (0.6.1)
56
66
  rack (>= 1.0)
57
67
  rake (0.9.2.2)
58
- rspec (2.8.0)
59
- rspec-core (~> 2.8.0)
60
- rspec-expectations (~> 2.8.0)
61
- rspec-mocks (~> 2.8.0)
62
- rspec-core (2.8.0)
63
- rspec-expectations (2.8.0)
64
- diff-lcs (~> 1.1.2)
65
- rspec-mocks (2.8.0)
68
+ rspec (2.11.0)
69
+ rspec-core (~> 2.11.0)
70
+ rspec-expectations (~> 2.11.0)
71
+ rspec-mocks (~> 2.11.0)
72
+ rspec-core (2.11.1)
73
+ rspec-expectations (2.11.3)
74
+ diff-lcs (~> 1.1.3)
75
+ rspec-mocks (2.11.3)
76
+ simplecov (0.6.4)
77
+ multi_json (~> 1.0)
78
+ simplecov-html (~> 0.5.3)
79
+ simplecov-html (0.5.3)
66
80
  sinatra (1.3.2)
67
81
  rack (~> 1.3, >= 1.3.6)
68
82
  rack-protection (~> 1.2)
@@ -75,10 +89,6 @@ GEM
75
89
  sinatra (~> 1.3.0)
76
90
  tilt (~> 1.3)
77
91
  term-ansicolor (1.0.7)
78
- thin (1.4.1)
79
- daemons (>= 1.0.9)
80
- eventmachine (>= 0.12.6)
81
- rack (>= 1.0.0)
82
92
  thor (0.15.4)
83
93
  tilt (1.3.3)
84
94
  unf (0.0.4)
@@ -88,6 +98,18 @@ GEM
88
98
  waitforit (0.0.1)
89
99
  webrobots (0.0.12)
90
100
  nokogiri (>= 1.4.4)
101
+ win32-api (1.4.8-x86-mingw32)
102
+ win32-file (0.6.8)
103
+ win32-api (>= 1.2.1)
104
+ win32-file-stat (>= 1.3.2)
105
+ windows-pr (>= 1.0.8)
106
+ win32-file-stat (1.3.6)
107
+ windows-pr (>= 1.0.0)
108
+ windows-api (0.4.2)
109
+ win32-api (>= 1.4.5)
110
+ windows-pr (1.2.2)
111
+ win32-api (>= 1.4.5)
112
+ windows-api (>= 0.3.0)
91
113
 
92
114
  PLATFORMS
93
115
  java
@@ -97,14 +119,19 @@ PLATFORMS
97
119
  DEPENDENCIES
98
120
  childprocess
99
121
  cucumber
122
+ haml
123
+ hashie
124
+ httparty
100
125
  jeweler
101
126
  jruby-openssl
102
127
  mechanize
103
128
  nokogiri
129
+ ptools
130
+ rack-test
104
131
  rake
105
132
  rspec
133
+ simplecov
106
134
  sinatra
107
135
  sinatra-contrib
108
- thin
109
136
  thor
110
137
  waitforit
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.4.2
1
+ 3.0.0.alpha.1
@@ -1,91 +1,82 @@
1
- Feature: The client can be used for clearing response templates from Mirage
1
+ Feature: The client can be used for clearing down Mirage.
2
+
3
+ As with the restful interface, clearing a template also clears any associated request data
2
4
 
3
5
  Background:
4
- Given the following gems are required to run the Mirage client test code:
6
+ Given the following require statements are needed:
5
7
  """
6
8
  require 'rubygems'
7
- require 'rspec'
8
9
  require 'mirage/client'
9
10
  """
10
11
 
11
- And I send PUT to 'http://localhost:7001/mirage/templates/greeting' with request entity
12
- """
13
- Hello
14
- """
12
+ And a template for 'greeting' has been set with a value of 'Hello'
13
+
15
14
  And I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
16
15
  | message | hello there |
16
+ And a template for 'leaving' has been set with a value of 'Goodbye'
17
17
 
18
- And I send PUT to 'http://localhost:7001/mirage/templates/leaving' with request entity
19
- """
20
- Goodbye
21
- """
22
18
  And I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
23
19
  | message | I'm going |
24
20
 
25
21
 
26
- Scenario: Clearing everything
27
- When I run
22
+ Scenario: Clearing a template
23
+ Given I run
28
24
  """
29
- Mirage::Client.new.clear
25
+ Mirage::Client.new.templates(1).delete
30
26
  """
31
- And I send GET to 'http://localhost:7001/mirage/responses/greeting'
27
+ When GET is sent to 'http://localhost:7001/mirage/responses/greeting'
32
28
  Then a 404 should be returned
33
-
34
- When I send GET to 'http://localhost:7001/mirage/requests/1'
29
+ When GET is sent to 'http://localhost:7001/mirage/requests/1'
35
30
  Then a 404 should be returned
36
31
 
37
- And I send GET to 'http://localhost:7001/mirage/responses/leaving'
38
- Then a 404 should be returned
32
+ When GET is sent to 'http://localhost:7001/mirage/responses/leaving'
33
+ Then a 200 should be returned
34
+ When GET is sent to 'http://localhost:7001/mirage/requests/2'
35
+ Then a 200 should be returned
39
36
 
40
- When I send GET to 'http://localhost:7001/mirage/requests/2'
37
+
38
+ Scenario: Clearning a request
39
+ Given I run
40
+ """
41
+ Mirage::Client.new.requests(1).delete
42
+ """
43
+ When GET is sent to 'http://localhost:7001/mirage/requests/1'
41
44
  Then a 404 should be returned
45
+ When GET is sent to 'http://localhost:7001/mirage/responses/greeting'
46
+ Then a 200 should be returned
42
47
 
43
48
 
44
- Scenario: Clearing all requests
49
+ Scenario: Clearing everything
45
50
  When I run
46
51
  """
47
- Mirage::Client.new.clear :requests
52
+ Mirage::Client.new.templates.delete_all
48
53
  """
49
- When I send GET to 'http://localhost:7001/mirage/requests/1'
54
+ And GET is sent to 'http://localhost:7001/mirage/responses/greeting'
50
55
  Then a 404 should be returned
51
56
 
52
- When I send GET to 'http://localhost:7001/mirage/requests/2'
57
+ When GET is sent to 'http://localhost:7001/mirage/requests/1'
53
58
  Then a 404 should be returned
54
59
 
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
60
+ And GET is sent to 'http://localhost:7001/mirage/responses/leaving'
61
+ Then a 404 should be returned
59
62
 
63
+ When GET is sent to 'http://localhost:7001/mirage/requests/2'
64
+ Then a 404 should be returned
60
65
 
61
- Scenario: Clearning a response
62
- Given I run
66
+
67
+ Scenario: Clearing all request data
68
+ When I run
63
69
  """
64
- Mirage::Client.new.clear 1
70
+ Mirage::Client.new.requests.delete_all
65
71
  """
66
- When I send GET to 'http://localhost:7001/mirage/responses/greeting'
72
+ When GET is sent to 'http://localhost:7001/mirage/requests/1'
67
73
  Then a 404 should be returned
68
- When I send GET to 'http://localhost:7001/mirage/requests/1'
74
+
75
+ When GET is sent to 'http://localhost:7001/mirage/requests/2'
69
76
  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
77
 
75
78
 
76
- Scenario: Clearning a request
77
- Given I run
78
- """
79
- Mirage::Client.new.clear :request => 1
80
- """
81
- When I send GET to 'http://localhost:7001/mirage/requests/1'
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
79
+
89
80
 
90
81
 
91
82
 
@@ -21,7 +21,7 @@ Feature: The client can be configured with default settings to keep your mocking
21
21
 
22
22
  client.put('greeting','hello')
23
23
  """
24
- When I send POST to 'http://localhost:7001/mirage/responses/greeting/for/someone'
24
+ When POST is sent to 'http://localhost:7001/mirage/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
@@ -41,7 +41,7 @@ Feature: The client can be configured with default settings to keep your mocking
41
41
 
42
42
  client.put('greeting','hello')
43
43
  """
44
- When I send POST to 'http://localhost:7001/mirage/responses/greeting/for/someone'
44
+ When POST is sent to 'http://localhost:7001/mirage/responses/greeting/for/someone'
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
@@ -33,12 +33,12 @@ Feature: the Mirage client provides methods for setting responses and loading de
33
33
  Then 'Hello Leon' should be returned
34
34
 
35
35
 
36
- Scenario Outline: Setting a response with a pattern
36
+ Scenario: Setting a response with required body content
37
37
  Given I run
38
38
  """
39
39
  Mirage::Client.new.put('greeting', 'Hello Leon') do |response|
40
40
  response.method = 'POST'
41
- response.pattern = <pattern>
41
+ response.add_body_content_requirement /leon/
42
42
  end
43
43
  """
44
44
  When I send POST to 'http://localhost:7001/mirage/responses/greeting'
@@ -50,10 +50,21 @@ Feature: the Mirage client provides methods for setting responses and loading de
50
50
  </greetingRequest>
51
51
  """
52
52
  Then 'Hello Leon' should be returned
53
- Examples:
54
- | pattern |
55
- | /.*?>leon<\\/name>/ |
56
- | 'leon' |
53
+
54
+ Scenario: Setting a response with a request parameter requirement
55
+ Given I run
56
+ """
57
+ Mirage::Client.new.put('greeting', 'Hello Leon') do |response|
58
+ response.method = 'POST'
59
+ response.add_request_parameter_requirement :name, /leon/
60
+ end
61
+ """
62
+ When I send POST to 'http://localhost:7001/mirage/responses/greeting'
63
+ Then a 404 should be returned
64
+ When I send POST to 'http://localhost:7001/mirage/responses/greeting' with parameters:
65
+ | name | leon |
66
+
67
+ Then 'Hello Leon' should be returned
57
68
 
58
69
  Scenario: setting a response as default
59
70
  Given I run
@@ -1,22 +1,18 @@
1
- Feature: Requests made to the Mirage Server can be tracked using the Mirage client
1
+ Feature: Requests made to the Mirage Server can be retrieved using the Mirage client
2
2
 
3
3
  Background:
4
- Given the following gems are required to run the Mirage client test code:
4
+ Given the following require statements are needed:
5
5
  """
6
6
  require 'rubygems'
7
- require 'rspec'
8
7
  require 'mirage/client'
9
8
  """
10
9
 
11
- Scenario: The MockServer returns a response
12
- Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with request entity
13
- """
14
- Hello
15
- """
10
+ Scenario: Retrieving request data
11
+ Given a template for 'greeting' has been set with a value of 'Hello'
16
12
 
17
13
  When I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
18
14
  | name | leon |
19
15
  Then I run
20
16
  """
21
- Mirage::Client.new.request(1).should == 'name=leon'
17
+ Mirage::Client.new.requests(1).parameters.should == {'name' => 'leon'}
22
18
  """
@@ -1,18 +1,19 @@
1
- Feature: The Mirage client provides a programmatic interface equivalent to the command line interface. This gives an
2
- easy method for bringing a local instance of Mirage in situ inside a test suite.
1
+ @command_line
2
+ Feature: The client API can be used to start Mirage.
3
+
4
+ Both the port and default templates directory can be specified
5
+
6
+ On starting Mirage a client is returned.
3
7
 
4
- The client can only be used to stop Mirage if it is was used to start the running instance.
5
8
 
6
9
  Background:
7
- Given the following gems are required to run the Mirage client test code:
10
+ Given the following require statements are needed:
8
11
  """
9
12
  require 'rubygems'
10
- require 'rspec'
11
13
  require 'mirage/client'
12
14
  """
13
15
 
14
-
15
- Scenario: Starting mirage with defaults
16
+ Scenario: Starting Mirage on the default port
16
17
  When I run
17
18
  """
18
19
  Mirage.start
@@ -21,16 +22,23 @@ Feature: The Mirage client provides a programmatic interface equivalent to the c
21
22
 
22
23
 
23
24
  Scenario: Starting Mirage on a custom port
24
- Given Mirage is not running
25
+ When I run
26
+ """
27
+ Mirage.start :port => 9001
28
+ """
29
+ Then mirage should be running on 'http://localhost:9001/mirage'
30
+
31
+
32
+ Scenario: Specifying a custom templates directory.
25
33
  And the file './custom_responses_location/default_greetings.rb' contains:
26
34
  """
27
35
  prime do |mirage|
28
- mirage.put('greeting', 'hello')
36
+ mirage.templates.put('greeting', 'hello')
29
37
  end
30
38
  """
31
39
  When I run
32
40
  """
33
- Mirage.start :port => 9001, :defaults => './custom_responses_location'
41
+ Mirage.start :defaults => './custom_responses_location'
34
42
  """
35
- And I send GET to 'http://localhost:9001/mirage/responses/greeting'
43
+ And GET is sent to 'http://localhost:7001/mirage/responses/greeting'
36
44
  Then 'hello' should be returned
@@ -1,40 +1,32 @@
1
- Feature: The Mirage client provides a programmatic interface equivalent to the command line interface. This gives an
2
- easy method for bringing a local instance of Mirage in situ inside a test suite.
3
-
4
- The client can only be used to stop Mirage if it is was used to start the running instance.
1
+ @command_line
2
+ Feature:The client API can be used to stop instances of Mirage running on localhost.
5
3
 
6
4
  Background:
7
- Given the following gems are required to run the Mirage client test code:
5
+ Given the following require statements are needed:
8
6
  """
9
7
  require 'rubygems'
10
- require 'rspec'
11
8
  require 'mirage/client'
12
9
  """
13
10
 
14
-
15
11
  Scenario: Stopping Mirage
16
- Given Mirage is not running
12
+ Given Mirage is running
17
13
  When I run
18
14
  """
19
- Mirage.start
20
- Mirage.stop :port => 7001
15
+ Mirage.stop
21
16
  """
22
17
  Then Connection should be refused to 'http://localhost:7001/mirage'
23
18
 
19
+
24
20
  Scenario: Stopping Mirage on custom port
25
- Given Mirage is not running
26
- And I run 'mirage start -p 7001'
27
21
  And I run 'mirage start -p 9001'
28
22
  When I run
29
23
  """
30
24
  Mirage.stop :port => 9001
31
25
  """
32
- Then mirage should be running on 'http://localhost:7001/mirage'
33
26
  Then mirage should not be running on 'http://localhost:9001/mirage'
34
27
 
35
28
  Scenario: Stopping multiple instances of Mirage
36
- Given Mirage is not running
37
- And I run 'mirage start -p 7001'
29
+ Given I run 'mirage start -p 7001'
38
30
  And I run 'mirage start -p 9001'
39
31
  And I run 'mirage start -p 10001'
40
32
  When I run
@@ -45,9 +37,9 @@ Feature: The Mirage client provides a programmatic interface equivalent to the c
45
37
  Then mirage should not be running on 'http://localhost:9001/mirage'
46
38
  Then mirage should not be running on 'http://localhost:10001/mirage'
47
39
 
40
+
48
41
  Scenario: Stopping all instances of Mirage
49
- Given Mirage is not running
50
- And I run 'mirage start -p 7001'
42
+ Given I run 'mirage start -p 7001'
51
43
  And I run 'mirage start -p 9001'
52
44
  And I run 'mirage start -p 10001'
53
45
  When I run
@@ -56,30 +48,4 @@ Feature: The Mirage client provides a programmatic interface equivalent to the c
56
48
  """
57
49
  Then mirage should not be running on 'http://localhost:7001/mirage'
58
50
  Then mirage should not be running on 'http://localhost:9001/mirage'
59
- Then mirage should not be running on 'http://localhost:10001/mirage'
60
-
61
-
62
-
63
- Scenario: Using client to stop mirage
64
- Given Mirage is not running
65
- And I run 'mirage start -p 7001'
66
- And I run 'mirage start -p 9001'
67
- When I run
68
- """
69
- begin
70
- Mirage.stop
71
- raise "should have errored"
72
- rescue Mirage::ClientError => ce
73
- end
74
- """
75
- Then mirage should be running on 'http://localhost:7001/mirage'
76
- And mirage should be running on 'http://localhost:9001/mirage'
77
-
78
- Scenario: Stopping Mirage without specifying the port when more than one instance of Mirage is running
79
- Given Mirage is not running
80
- When I run
81
- """
82
- client = Mirage.start
83
- client.stop
84
- """
85
- Then Connection should be refused to 'http://localhost:7001/mirage'
51
+ Then mirage should not be running on 'http://localhost:10001/mirage'