mirage-on-thin 3.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-gemset +1 -0
  3. data/.ruby-version +1 -0
  4. data/.simplecov +6 -0
  5. data/.travis.yml +3 -0
  6. data/Gemfile +29 -0
  7. data/Gemfile.lock +151 -0
  8. data/HISTORY +22 -0
  9. data/README.md +156 -0
  10. data/Rakefile +10 -0
  11. data/VERSION +1 -0
  12. data/bin/mirage +14 -0
  13. data/features/.nav +29 -0
  14. data/features/client/clear.feature +78 -0
  15. data/features/client/configure.feature +72 -0
  16. data/features/client/model.feature +95 -0
  17. data/features/client/preview_responses.feature +33 -0
  18. data/features/client/prime.feature +32 -0
  19. data/features/client/put.feature +111 -0
  20. data/features/client/readme.md +3 -0
  21. data/features/client/requests.feature +20 -0
  22. data/features/client/running.feature +51 -0
  23. data/features/client/save_and_revert.feature +39 -0
  24. data/features/client/start.feature +46 -0
  25. data/features/client/stop.feature +53 -0
  26. data/features/commandline_interface/help.feature +17 -0
  27. data/features/commandline_interface/readme.md +1 -0
  28. data/features/commandline_interface/start.feature +18 -0
  29. data/features/commandline_interface/stop.feature +42 -0
  30. data/features/logging.feature +6 -0
  31. data/features/prime.feature +35 -0
  32. data/features/readme.md +7 -0
  33. data/features/requests/delete.feature +48 -0
  34. data/features/requests/get.feature +36 -0
  35. data/features/save_and_revert.feature +35 -0
  36. data/features/step_definitions/my_steps.rb +98 -0
  37. data/features/step_definitions/observation_steps.rb +103 -0
  38. data/features/support/command_line.rb +33 -0
  39. data/features/support/env.rb +22 -0
  40. data/features/support/hooks.rb +26 -0
  41. data/features/support/mirage.rb +12 -0
  42. data/features/support/web.rb +20 -0
  43. data/features/templates/delete.feature +45 -0
  44. data/features/templates/get.feature +54 -0
  45. data/features/templates/path_wildcards.feature +10 -0
  46. data/features/templates/preview.feature +18 -0
  47. data/features/templates/put.feature +77 -0
  48. data/features/templates/put_with_substitutions.feature +22 -0
  49. data/features/templates/readme.md +4 -0
  50. data/features/templates/required_content.feature +113 -0
  51. data/features/web_user_interface.feature +44 -0
  52. data/full_build.sh +100 -0
  53. data/lib/mirage/client.rb +10 -0
  54. data/lib/mirage/client/cli_bridge.rb +30 -0
  55. data/lib/mirage/client/client.rb +73 -0
  56. data/lib/mirage/client/error.rb +22 -0
  57. data/lib/mirage/client/helpers/method_builder.rb +19 -0
  58. data/lib/mirage/client/request.rb +26 -0
  59. data/lib/mirage/client/requests.rb +13 -0
  60. data/lib/mirage/client/runner.rb +103 -0
  61. data/lib/mirage/client/template.rb +56 -0
  62. data/lib/mirage/client/template/configuration.rb +44 -0
  63. data/lib/mirage/client/template/model.rb +48 -0
  64. data/lib/mirage/client/template/model/common_methods.rb +24 -0
  65. data/lib/mirage/client/template/model/instance_methods.rb +95 -0
  66. data/lib/mirage/client/templates.rb +50 -0
  67. data/mirage-on-thin.gemspec +175 -0
  68. data/mirage_server.rb +35 -0
  69. data/server/app.rb +4 -0
  70. data/server/binary_data_checker.rb +15 -0
  71. data/server/extensions/hash.rb +10 -0
  72. data/server/extensions/object.rb +5 -0
  73. data/server/helpers.rb +3 -0
  74. data/server/helpers/http_headers.rb +31 -0
  75. data/server/helpers/template_requirements.rb +33 -0
  76. data/server/mock_response.rb +242 -0
  77. data/server/server.rb +184 -0
  78. data/spec/client/cli_bridge_spec.rb +63 -0
  79. data/spec/client/client_spec.rb +179 -0
  80. data/spec/client/helpers/method_builder_spec.rb +40 -0
  81. data/spec/client/request_spec.rb +39 -0
  82. data/spec/client/requests_spec.rb +9 -0
  83. data/spec/client/runner_spec.rb +138 -0
  84. data/spec/client/template/configuration_spec.rb +32 -0
  85. data/spec/client/template/model/common_methods_spec.rb +25 -0
  86. data/spec/client/template/model/instance_methods_spec.rb +169 -0
  87. data/spec/client/template/model_spec.rb +119 -0
  88. data/spec/client/template_spec.rb +146 -0
  89. data/spec/client/templates_spec.rb +197 -0
  90. data/spec/resources/binary.file +0 -0
  91. data/spec/server/binary_data_checker_spec.rb +21 -0
  92. data/spec/server/helpers/http_headers_spec.rb +20 -0
  93. data/spec/server/helpers/template_requirements_spec.rb +34 -0
  94. data/spec/server/mock_response_spec.rb +577 -0
  95. data/spec/server/server_spec.rb +156 -0
  96. data/spec/spec_helper.rb +85 -0
  97. data/tasks/application.rake +7 -0
  98. data/tasks/packaging.rake +28 -0
  99. data/tasks/tests.rake +25 -0
  100. data/views/index.haml +16 -0
  101. data/views/response.haml +46 -0
  102. metadata +337 -0
@@ -0,0 +1,51 @@
1
+ @command_line
2
+ Feature: How to check if Mirage is running
3
+
4
+ Use the Mirage client api to check if Mirage is running either on the local machine or on a remote host.
5
+
6
+
7
+ Background:
8
+ Given the following require statements are needed:
9
+ """
10
+ require 'rubygems'
11
+ require 'rspec/expectations'
12
+ require 'mirage/client'
13
+ """
14
+
15
+
16
+ Scenario: Check if mirage is running on the local machine on the default port
17
+ Given Mirage is not running
18
+ Then I run
19
+ """
20
+ Mirage.running?.should == false
21
+ """
22
+ Given Mirage is running
23
+ Then I run
24
+ """
25
+ Mirage.running?.should == true
26
+ """
27
+
28
+
29
+ Scenario: Check if mirage is running on the local machine on a non standard port
30
+ Given I run 'mirage start -p 9001'
31
+ Then I run
32
+ """
33
+ Mirage.running?(:port => 9001).should == true
34
+ """
35
+
36
+
37
+ Scenario: Checking if mirage is running on remote machine
38
+ Given I run 'mirage start -p 9001'
39
+ Then I run
40
+ """
41
+ Mirage.running? "http://localhost:9001"
42
+ """
43
+
44
+
45
+ Scenario: Check if mirage is running using the client directly
46
+ Given I run 'mirage start -p 9001'
47
+ Then I run
48
+ """
49
+ client = Mirage::Client.new "http://localhost:9001"
50
+ client.running?.should == true
51
+ """
@@ -0,0 +1,39 @@
1
+ Feature: Creating snapshots
2
+
3
+ The client can be used to snapshot and rollback the Mirage server
4
+
5
+
6
+ Background:
7
+ Given the following require statements are needed:
8
+ """
9
+ require 'rubygems'
10
+ require 'rspec/expectations'
11
+ require 'mirage/client'
12
+ """
13
+ And a template for 'greeting' has been set with a value of 'The default greeting'
14
+
15
+
16
+ Scenario: Creating a snapshot and rolling back
17
+ Given I run
18
+ """
19
+ Mirage::Client.new.save
20
+ """
21
+ And I send PUT to '/templates/leaving' with request entity
22
+ """
23
+ Goodbye
24
+ """
25
+
26
+ And I send PUT to '/templates/greeting' with request entity
27
+ """
28
+ Changed
29
+ """
30
+
31
+ When I run
32
+ """
33
+ Mirage::Client.new.revert
34
+ """
35
+ And GET is sent to '/responses/leaving'
36
+ Then a 404 should be returned
37
+
38
+ When GET is sent to '/responses/greeting'
39
+ Then 'The default greeting' should be returned
@@ -0,0 +1,46 @@
1
+ @command_line
2
+ Feature: Starting Mirage
3
+
4
+ The client can be used to start Mirage.
5
+
6
+ Both the port and default templates directory can be specified
7
+
8
+ On starting Mirage a client is returned.
9
+
10
+
11
+ Background:
12
+ Given the following require statements are needed:
13
+ """
14
+ require 'rubygems'
15
+ require 'mirage/client'
16
+ """
17
+
18
+ Scenario: Starting Mirage on the default port
19
+ When I run
20
+ """
21
+ Mirage.start
22
+ """
23
+ Then mirage should be running on 'http://localhost:7001'
24
+
25
+
26
+ Scenario: Starting Mirage on a custom port
27
+ When I run
28
+ """
29
+ Mirage.start :port => 9001
30
+ """
31
+ Then mirage should be running on 'http://localhost:9001'
32
+
33
+
34
+ Scenario: Specifying a custom templates directory.
35
+ And the file './custom_responses_location/default_greetings.rb' contains:
36
+ """
37
+ prime do |mirage|
38
+ mirage.templates.put('greeting', 'hello')
39
+ end
40
+ """
41
+ When I run
42
+ """
43
+ Mirage.start :defaults => './custom_responses_location'
44
+ """
45
+ And GET is sent to '/responses/greeting'
46
+ Then 'hello' should be returned
@@ -0,0 +1,53 @@
1
+ @command_line
2
+ Feature: Stopping Mirage
3
+
4
+ The client API can be used to stop instances of Mirage running on localhost.
5
+
6
+ Background:
7
+ Given the following require statements are needed:
8
+ """
9
+ require 'rubygems'
10
+ require 'mirage/client'
11
+ """
12
+
13
+ Scenario: Stopping Mirage
14
+ Given Mirage is running
15
+ When I run
16
+ """
17
+ Mirage.stop
18
+ """
19
+ Then mirage should not be running on 'http://localhost:7001'
20
+
21
+
22
+ Scenario: Stopping Mirage on custom port
23
+ And I run 'mirage start -p 9001'
24
+ When I run
25
+ """
26
+ Mirage.stop :port => 9001
27
+ """
28
+ Then mirage should not be running on 'http://localhost:9001'
29
+
30
+ Scenario: Stopping multiple instances of Mirage
31
+ Given I run 'mirage start -p 7001'
32
+ And I run 'mirage start -p 9001'
33
+ And I run 'mirage start -p 10001'
34
+ When I run
35
+ """
36
+ Mirage.stop :port => [9001,10001]
37
+ """
38
+ Then mirage should be running on 'http://localhost:7001'
39
+ Then mirage should not be running on 'http://localhost:9001'
40
+ Then mirage should not be running on 'http://localhost:10001'
41
+
42
+
43
+ Scenario: Stopping all instances of Mirage
44
+ Given I run 'mirage start -p 7001'
45
+ And I run 'mirage start -p 9001'
46
+ And I run 'mirage start -p 10001'
47
+ When I run
48
+ """
49
+ Mirage.stop :all
50
+ """
51
+ Then mirage should not be running on 'http://localhost:7001'
52
+ Then mirage should not be running on 'http://localhost:9001'
53
+ Then mirage should not be running on 'http://localhost:10001'
@@ -0,0 +1,17 @@
1
+ @command_line
2
+ Feature: Help
3
+ Mirage is started from the command line. Mirage logs to mirage.log at the path where Mirage is started from.
4
+
5
+
6
+ Background: Mirage usage
7
+ Given usage information:
8
+ """
9
+ mirage help [COMMAND] # Describe available commands or one specific command
10
+ mirage start # Starts mirage
11
+ mirage stop # Stops mirage
12
+ """
13
+
14
+
15
+ Scenario: Starting with help option
16
+ Given I run 'mirage help'
17
+ Then the usage information should be displayed
@@ -0,0 +1 @@
1
+ Mirage has a fully functional commandline interface check it out!
@@ -0,0 +1,18 @@
1
+ @command_line
2
+ Feature: Starting Mirage
3
+ Mirage is started from the command line. more than instance of Mirage can be started on different ports at the same time.
4
+
5
+ By default mirage runs on port 7001.
6
+
7
+
8
+ Scenario: Starting mirage
9
+ Given Mirage is not running
10
+ When I run 'mirage start'
11
+ Then mirage should be running on 'http://localhost:7001'
12
+ And 'mirage.log' should exist
13
+
14
+
15
+ Scenario: Starting Mirage on a custom port
16
+ Given Mirage is not running
17
+ When I run 'mirage start -p 9001'
18
+ Then mirage should be running on 'http://localhost:9001'
@@ -0,0 +1,42 @@
1
+ @command_line
2
+ Feature: Stopping Mirage
3
+ Mirage can be stopped from the commandline
4
+ If more than one instance of Mirage is running, you will be asked to supply the ports which represent the running instances
5
+ of mirage that you wish to stop.
6
+
7
+ Scenario: Stopping a single instance of Mirage
8
+ Given I run 'mirage start -p 7001'
9
+ When I run 'mirage stop'
10
+ Then mirage should not be running on 'http://localhost:7001'
11
+
12
+ Scenario: Stopping an instance running on a given port
13
+ Given I run 'mirage start -p 7001'
14
+ And I run 'mirage start -p 9001'
15
+ When I run 'mirage stop -p 7001'
16
+ Then mirage should be running on 'http://localhost:9001'
17
+ Then mirage should not be running on 'http://localhost:7001'
18
+
19
+ Scenario: Stopping more than one instance
20
+ Given I run 'mirage start -p 7001'
21
+ And I run 'mirage start -p 9001'
22
+ And I run 'mirage start -p 10001'
23
+ When I run 'mirage stop -p 7001 9001'
24
+ Then mirage should be running on 'http://localhost:10001'
25
+ Then mirage should not be running on 'http://localhost:7001'
26
+ Then mirage should not be running on 'http://localhost:9001'
27
+
28
+ Scenario: Stopping all running instances
29
+ Given I run 'mirage start -p 7001'
30
+ And I run 'mirage start -p 9001'
31
+ When I run 'mirage stop -p all'
32
+ Then mirage should not be running on 'http://localhost:10001'
33
+ Then mirage should not be running on 'http://localhost:7001'
34
+ Then mirage should not be running on 'http://localhost:9001'
35
+
36
+ Scenario: Calling stop when there is more than one instance running
37
+ Given I run 'mirage start -p 7001'
38
+ Given I run 'mirage start -p 9001'
39
+ When I run 'mirage stop'
40
+ Then I should see 'Mirage is running on ports 7001, 9001. Please run mirage stop -p [PORT(s)] instead' on the command line
41
+ And mirage should be running on 'http://localhost:7001'
42
+ And mirage should be running on 'http://localhost:9001'
@@ -0,0 +1,6 @@
1
+ Feature: Output from Mirage is stored in mirage.log.
2
+ This file is located at the root from which mirage is started.
3
+
4
+ Scenario: Mirage logs request
5
+ Given GET is sent to '/templates/greeting'
6
+ Then mirage.log should contain '/templates/greeting'
@@ -0,0 +1,35 @@
1
+ #TODO - rename responses directory to templates
2
+ @command_line
3
+ Feature: Preloading Templates
4
+ Mirage can be primed with a set of templates.
5
+ By default, Mirage loads any .rb files found in ./mirage on startup. Mirage can also be made to load responses from a directory
6
+ of your choosing by using the -d/--defaults option
7
+
8
+ Responses can be added to the responses directory and used to prime Mirage after Mirage has been started.
9
+
10
+ Priming causes any modifications to Mirage's current state to be lost.
11
+
12
+
13
+ Scenario: Using the default responses directory
14
+ Given the file 'mirage/default_greetings.rb' contains:
15
+ """
16
+ prime do |mirage|
17
+ mirage.templates.put('greeting', 'hello')
18
+ end
19
+ """
20
+ And I run 'mirage start'
21
+ When GET is sent to '/responses/greeting'
22
+ Then 'hello' should be returned
23
+
24
+
25
+ Scenario: Using a custom responses directory
26
+ Given Mirage is not running
27
+ And the file '/tmp/mirage/default_greetings.rb' contains:
28
+ """
29
+ prime do |mirage|
30
+ mirage.templates.put('greeting', 'hello')
31
+ end
32
+ """
33
+ And I run 'mirage start --defaults /tmp/mirage'
34
+ And GET is sent to '/responses/greeting'
35
+ Then 'hello' should be returned
@@ -0,0 +1,7 @@
1
+ Mirage in an open source project that can be used to mock HTTP services. It facilitates application development in environments where external systems aren't easily accessed or can't be made to behave in a repeatable way.
2
+
3
+ At its core, Mirage is a web application with a restful interface that can be configured with responses. The descriptors for these response are called [Templates](/lashd/mirage/docs/templates).
4
+
5
+ If you're using Ruby then Mirage has a [client](/lashd/mirage/docs/client) to get you going straight away.
6
+
7
+ If you're using another language, then the interface to Mirage is simple and it would be great to see clients emerging other languages too. If you need any help please ask! :)
@@ -0,0 +1,48 @@
1
+ Feature: Deleting tracked requests
2
+ Tracked request data can be deleted
3
+
4
+ Background: The MockServer has already got a response for greeting and leaving on it.
5
+ Given the following template template:
6
+ """
7
+ {
8
+ "response":{
9
+ "body":"Hello"
10
+ }
11
+ }
12
+ """
13
+ And 'response.body' is base64 encoded
14
+ And the template is sent using PUT to '/templates/greeting'
15
+
16
+ Given the following template template:
17
+ """
18
+ {
19
+ "response":{
20
+ "body":"Goodbye"
21
+ }
22
+ }
23
+ """
24
+ And 'response.body' is base64 encoded
25
+ And the template is sent using PUT to '/templates/leaving'
26
+
27
+
28
+ And GET is sent to '/responses/greeting'
29
+ And GET is sent to '/responses/leaving'
30
+
31
+
32
+ Scenario: Deleting all requests
33
+ And DELETE is sent to '/requests'
34
+
35
+ When GET is sent to '/requests/1'
36
+ Then a 404 should be returned
37
+ When GET is sent to '/requests/2'
38
+ Then a 404 should be returned
39
+
40
+
41
+
42
+ Scenario: Deleting a stored request for a particular response
43
+ And DELETE is sent to '/requests/1'
44
+
45
+ When GET is sent to '/requests/1'
46
+ Then a 404 should be returned
47
+ When GET is sent to '/requests/2'
48
+ Then a 200 should be returned
@@ -0,0 +1,36 @@
1
+ Feature: Checking tracked requests
2
+ After a response has been served from Mirage, the request that triggered it can be retrieved. This is useful
3
+ for testing that the correct information was sent by your application code.
4
+
5
+ Use a template's ID to retrieve the last request that was last received.
6
+
7
+
8
+ Background: A template has already be put on Mirage
9
+ Given the following template template:
10
+ """
11
+ {
12
+ "request" : {
13
+ "http_method" : "post"
14
+ },
15
+ "response":{
16
+ "body":"Hello"
17
+ }
18
+ }
19
+ """
20
+ And 'response.body' is base64 encoded
21
+ And the template is sent using PUT to '/templates/greeting'
22
+
23
+
24
+ Scenario: Getting request data when the data was in the body.
25
+ Given I send POST to '/responses/greeting' with request entity
26
+ """
27
+ Hello Mirage
28
+ """
29
+ When GET is sent to '/requests/1'
30
+ Then request data should have been retrieved
31
+
32
+
33
+ Scenario: Getting request data for a template that has not yet served a response.
34
+ Given GET is sent to '/requests/1'
35
+ Then a 404 should be returned
36
+
@@ -0,0 +1,35 @@
1
+ Feature: Having set up the Mirage with a number of defaults, your tests may continue to change its state.
2
+ Clearing and resetting all of your responses, potentially hundreds of times, can be time expensive.
3
+
4
+ Mirage provides the ability to save its current state and to revert back to that state.
5
+
6
+ Background: The MockServer has been setup with some default responses
7
+ Given the following template template:
8
+ """
9
+ {
10
+ "response":{
11
+ "body":"The default greeting"
12
+ }
13
+ }
14
+ """
15
+ And 'response.body' is base64 encoded
16
+ And the template is sent using PUT to '/templates/greeting'
17
+
18
+
19
+ Scenario: Saving Mirage and reverting it
20
+ Given PUT is sent to '/backup'
21
+ And the following template template:
22
+ """
23
+ {
24
+ "response":{
25
+ "body":"Changed"
26
+ }
27
+ }
28
+ """
29
+ And 'response.body' is base64 encoded
30
+ And the template is sent using PUT to '/templates/greeting'
31
+
32
+ When PUT is sent to '/'
33
+ And GET is sent to '/responses/greeting'
34
+
35
+ Then 'The default greeting' should be returned