mirage-on-thin 3.0.8

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 (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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62b859169722e9d419435c65f7406d62c8d696f1
4
+ data.tar.gz: 0fd4b89ec3c0414af7bee9bc247c3221e17d4b13
5
+ SHA512:
6
+ metadata.gz: 3aa820fa3ff4484d74777840b4d9445cfb3d4bab2121c5ce9b1a7a01b31569172c9eb17ce9a72060b619badcecaaaf431edbaa6535e896069135fe0aa1305b97
7
+ data.tar.gz: 5dd72fc9d2b33df6096e452e8c19ea52e095e82b155ba18fe929dc1524839b1d5de97a233f3af03683067ae03effb8243d3ccc6d5d374d811c377a89619521ff
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ mirage
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p353
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/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - '1.9.3'
3
+ - '2.0.0'
data/Gemfile ADDED
@@ -0,0 +1,29 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sinatra'
4
+ gem 'thin'
5
+ gem 'childprocess'
6
+ gem "waitforit"
7
+ gem "thor"
8
+ gem "ptools"
9
+ gem "httparty"
10
+ gem "haml"
11
+ gem 'hashie'
12
+
13
+ group :test do
14
+ gem 'cucumber'
15
+ gem 'rspec', require: 'rspec/core/rake_task'
16
+ gem 'rack-test'
17
+ gem 'simplecov', require: false
18
+ end
19
+
20
+ group :development do
21
+ gem 'rake'
22
+ gem "jeweler"
23
+ gem 'sinatra-contrib'
24
+
25
+ platform :jruby do
26
+ gem "jruby-openssl"
27
+ end
28
+ end
29
+
data/Gemfile.lock ADDED
@@ -0,0 +1,151 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ backports (3.3.5)
6
+ bouncy-castle-java (1.5.0147)
7
+ builder (3.2.2)
8
+ childprocess (0.3.9)
9
+ ffi (~> 1.0, >= 1.0.11)
10
+ cucumber (1.3.8)
11
+ builder (>= 2.1.2)
12
+ diff-lcs (>= 1.1.3)
13
+ gherkin (~> 2.12.1)
14
+ multi_json (>= 1.7.5, < 2.0)
15
+ multi_test (>= 0.0.2)
16
+ daemons (1.1.9)
17
+ diff-lcs (1.2.4)
18
+ eventmachine (1.0.3)
19
+ faraday (0.8.8)
20
+ multipart-post (~> 1.2.0)
21
+ ffi (1.9.0)
22
+ ffi (1.9.0-java)
23
+ ffi (1.9.0-x86-mingw32)
24
+ gherkin (2.12.2)
25
+ multi_json (~> 1.3)
26
+ gherkin (2.12.2-java)
27
+ multi_json (~> 1.3)
28
+ gherkin (2.12.2-x86-mingw32)
29
+ multi_json (~> 1.3)
30
+ git (1.2.6)
31
+ github_api (0.10.1)
32
+ addressable
33
+ faraday (~> 0.8.1)
34
+ hashie (>= 1.2)
35
+ multi_json (~> 1.4)
36
+ nokogiri (~> 1.5.2)
37
+ oauth2
38
+ haml (4.0.3)
39
+ tilt
40
+ hashie (2.0.5)
41
+ highline (1.6.20)
42
+ httparty (0.12.0)
43
+ json (~> 1.8)
44
+ multi_xml (>= 0.5.2)
45
+ httpauth (0.2.0)
46
+ jeweler (1.8.8)
47
+ builder
48
+ bundler (~> 1.0)
49
+ git (>= 1.2.5)
50
+ github_api (= 0.10.1)
51
+ highline (>= 1.6.15)
52
+ nokogiri (= 1.5.10)
53
+ rake
54
+ rdoc
55
+ jruby-openssl (0.9.4)
56
+ bouncy-castle-java (>= 1.5.0147)
57
+ json (1.8.1)
58
+ json (1.8.1-java)
59
+ jwt (0.1.8)
60
+ multi_json (>= 1.5)
61
+ multi_json (1.8.2)
62
+ multi_test (0.0.2)
63
+ multi_xml (0.5.5)
64
+ multipart-post (1.2.0)
65
+ nokogiri (1.5.10)
66
+ nokogiri (1.5.10-java)
67
+ nokogiri (1.5.10-x86-mingw32)
68
+ oauth2 (0.9.2)
69
+ faraday (~> 0.8)
70
+ httpauth (~> 0.2)
71
+ jwt (~> 0.1.4)
72
+ multi_json (~> 1.0)
73
+ multi_xml (~> 0.5)
74
+ rack (~> 1.2)
75
+ ptools (1.2.2)
76
+ ptools (1.2.2-x86-mingw32)
77
+ win32-file (>= 0.5.4)
78
+ rack (1.5.2)
79
+ rack-protection (1.5.1)
80
+ rack
81
+ rack-test (0.6.2)
82
+ rack (>= 1.0)
83
+ rake (10.1.0)
84
+ rdoc (4.0.1)
85
+ json (~> 1.4)
86
+ rspec (2.14.1)
87
+ rspec-core (~> 2.14.0)
88
+ rspec-expectations (~> 2.14.0)
89
+ rspec-mocks (~> 2.14.0)
90
+ rspec-core (2.14.6)
91
+ rspec-expectations (2.14.3)
92
+ diff-lcs (>= 1.1.3, < 2.0)
93
+ rspec-mocks (2.14.4)
94
+ simplecov (0.7.1)
95
+ multi_json (~> 1.0)
96
+ simplecov-html (~> 0.7.1)
97
+ simplecov-html (0.7.1)
98
+ sinatra (1.4.4)
99
+ rack (~> 1.4)
100
+ rack-protection (~> 1.4)
101
+ tilt (~> 1.3, >= 1.3.4)
102
+ sinatra-contrib (1.4.1)
103
+ backports (>= 2.0)
104
+ multi_json
105
+ rack-protection
106
+ rack-test
107
+ sinatra (~> 1.4.0)
108
+ tilt (~> 1.3)
109
+ thin (1.6.2)
110
+ daemons (>= 1.0.9)
111
+ eventmachine (>= 1.0.0)
112
+ rack (>= 1.0.0)
113
+ thor (0.18.1)
114
+ tilt (1.4.1)
115
+ waitforit (0.0.1)
116
+ win32-api (1.5.0-x86-mingw32)
117
+ win32-file (0.6.8)
118
+ win32-api (>= 1.2.1)
119
+ win32-file-stat (>= 1.3.2)
120
+ windows-pr (>= 1.0.8)
121
+ win32-file-stat (1.3.6)
122
+ windows-pr (>= 1.0.0)
123
+ windows-api (0.4.2)
124
+ win32-api (>= 1.4.5)
125
+ windows-pr (1.2.2)
126
+ win32-api (>= 1.4.5)
127
+ windows-api (>= 0.3.0)
128
+
129
+ PLATFORMS
130
+ java
131
+ ruby
132
+ x86-mingw32
133
+
134
+ DEPENDENCIES
135
+ childprocess
136
+ cucumber
137
+ haml
138
+ hashie
139
+ httparty
140
+ jeweler
141
+ jruby-openssl
142
+ ptools
143
+ rack-test
144
+ rake
145
+ rspec
146
+ simplecov
147
+ sinatra
148
+ sinatra-contrib
149
+ thin
150
+ thor
151
+ waitforit
data/HISTORY ADDED
@@ -0,0 +1,22 @@
1
+ V3.0.8 - bug fix for issue 13: https://github.com/lashd/mirage/issues/13 - match Content-Length header
2
+ V3.0.7 - bug fix for issue 13: https://github.com/lashd/mirage/issues/13 - match Content-Type header
3
+ V3.0.6 - bug fix
4
+ V3.0.5 - fixed bug in builder methods
5
+ V3.0.1 - updating gem post install message to point people towards the readme due checkout the differences between version 2 and 3 of Mirage
6
+ V3.0.0 - Major update see README.md
7
+ V2.4.2 - update eventmachine, make sure Mirage.start always returns a client
8
+ V2.4.1 - adding rdoc for configure method
9
+ V2.4.0 - Adding ability to set defaults
10
+ V2.3.0 - Enhanced commandline/programmatic api
11
+ V2.2.3 - fix bug where mirage is already running a client calls exit.
12
+ V2.2.1/2 - Code tidy up
13
+ V2.2.0 - Api for starting and stopping Mirage locally
14
+ V2.1.2 - rename status_code to status
15
+ V2.1.1 - Set response code and tidy ups
16
+ V2.0.16 - minor typo fix for window command window title in windows
17
+ V2.0.15 - fix uploading files from client and fix starting mirage on windows
18
+ V2.0.12/13/14 - updating gem versions
19
+ V2.0.8/9/10/11 - tidy up code, still a lot to do :)
20
+ V2.0.7 - fix missing dependency on waitforit gem
21
+ V2.0.1/2/3 - tidying up code
22
+ V2.0.0 - Converted to restful interface
data/README.md ADDED
@@ -0,0 +1,156 @@
1
+ [![Build Status](https://travis-ci.org/lashd/mirage.png)](https://travis-ci.org/lashd/mirage)
2
+ Mirage
3
+ ======
4
+ Mirage aids testing of your applications by hosting mock responses so that your applications do not have to talk to real endpoints. It's accessible via HTTP and has a RESTful interface.
5
+
6
+ Any ideas/improvements or feedback you have are greatly appreciated.
7
+
8
+ Information on how to use Mirage can be found [here](https://github.com/lashd/mirage/wiki).
9
+
10
+ I hope you find it useful,
11
+
12
+ Leon
13
+
14
+ P.s. Mirage runs on Linux,MacOSX and Windows; Rubies 1.9.3+ and JRuby.
15
+
16
+ Installation
17
+ ------------
18
+ gem install mirage
19
+
20
+ What's New?
21
+ -----------
22
+ ### 3.0.0
23
+ ------------------------------
24
+ 3.0.0 is now out the following is a description of what's new.
25
+
26
+ A full description of the functionality is also available in the projects [feature files](https://www.relishapp.com/lashd/mirage/docs) hosted on Relish. A lot of effort has gone in to trying to make these tests readable so if something is missing or unclear drop me a line.
27
+
28
+
29
+ #### What's new in the Server:
30
+ ##### 1: Mirage uses JSON as its communucations medium
31
+ Mirage is now configured using JSON. JSON is also used as the output format for Mirage's other operations.
32
+ ##### 2: Wildcards are now supported in the URI.
33
+ You can now specify wild cards in the URI matcher. This means that a url such as '/*/world' would match '/hello/world' :)
34
+ ##### 3: Full Request Data now tracked
35
+ You can now retrieve all data associated with a request that triggers a response. Previously only the the request body/query string was tracked.
36
+ Now the full request, including HTTP headers are returned when querying '/requests/template_id'
37
+
38
+ ##### 4. Parameters and body content matchers are now specified seperately
39
+ Now you can specify as many parameter and body matchers as you want. These can be both litteral strings or Regex's
40
+
41
+ Previously, it was only possible to specify a single matcher and this would be applied against both the querystring and the request body.
42
+ ##### 5. HTTP Header matchers
43
+ You can now also specify matchers against HTTP headers.
44
+ ##### 6. More advanced template resolution.
45
+ Templates are now scored to find the most appropriate template when finding a match for a particular request. Previously the first potential match was returned even
46
+ if there was a more appropriate template.
47
+
48
+ Litteral matchers are worth more in the scoring process than regex based ones for example.
49
+ ##### 7. The url has changed
50
+ Mirage is now accessible via: http://localhost:7001. I.e. 'mirage' has been removed from all resources
51
+
52
+ e.g. responses are now under http://localhost:7001/responses
53
+ ##### 8. Default responses directory renamed to mirage
54
+ Default templates used to be stored in a directory named 'responses'. The term 'response' was the incorrect word to describe what is now called a 'template'. Rather than rename this directory to templates, which is a directory name that may already be in use in your project, the default name for this directory has been changed to 'mirage'.
55
+
56
+ The old directory name can still be used if you use the client or command line interface to overide where the responses are loaded from
57
+
58
+ #### What's new in the Client:
59
+ ##### 1. Template Models
60
+ Perhaps the biggest addition to the client. Simply mixin Mirage::Template::Model in to a class, give it a method called body and there you have it... a class that can be used to put objects straight on to Mirage.
61
+
62
+ * All the methods you find on a standard response can then be used at the class level to set defaults.
63
+
64
+ * Add builder methods to your class using the builder_methods class method.
65
+
66
+ **Example Usage:** (See rdoc for full details)
67
+
68
+ class UserProfile
69
+ extend Mirage::Template::Model
70
+
71
+ endpoint '/users'
72
+ http_method :get
73
+ status 200
74
+ content_type 'application/json'
75
+
76
+ builder_methods :firstname, :lastname, :age
77
+
78
+ def body
79
+ {firstname: firstname, lastname: lastname, age: age}.to_json
80
+ end
81
+ end
82
+
83
+
84
+ Mirage::Client.new.put UserProfile.new.firstname('Joe').lastname('blogs')
85
+
86
+ ##### Client interface
87
+ The client interface has been overhauled to make it more usable. It supports a couple of different ways of specifying a template
88
+ to let to specify templates in the style that best suites your code. The block in the examples is executed in the scope of the template
89
+ object itself so any method in it can be called. The template is also passed in to the block if you prefer to to call the methods
90
+ on a variable.
91
+
92
+ **Example Usage:** (See rdoc for full details)
93
+
94
+ mirage = Mirage::Client.new
95
+ mirage.put('/users') do
96
+ status 201
97
+ http_method :put
98
+ body 'response'
99
+
100
+ required_body_content << 'Abracadabra'
101
+ required_headers['Header'] = 'value'
102
+
103
+ delay 1.5
104
+ end
105
+
106
+ # Template Model classes can be customised in exactly the same way
107
+
108
+ mirage.put UserProfile.new do
109
+ status 404
110
+ required_parameters[:name] = /joe.*/
111
+ end
112
+ #### What you don't get
113
+ A better UI :) it's on its way though!
114
+
115
+ ### 2.4.0
116
+ ---------
117
+ #### What do I get?
118
+ ##### 1: Configure your client with defaults for each of your responses
119
+ Remove the repetition of setting things like the content-type each to time you put a response on to Mirage
120
+
121
+ **Example Usage:** (See rdoc for full details)
122
+
123
+ client = Mirage::Client.new do |defaults|
124
+ defaults.content_type = "text/xml"
125
+ defaults.delay = 0.5
126
+ end
127
+
128
+ client.put("greeting", "hello") -> template put on to Mirage with a delay of 0.5 seconds and content-type text/xml configured
129
+ #### What do I have to do to upgrade?
130
+ Nothing, this is a new feature. Let me know if you have any problems :)
131
+
132
+
133
+
134
+
135
+ ### 2.3.0
136
+ ---------
137
+ #### What do I get?
138
+ ##### 1: Run more than one instance of Mirage per machine.
139
+ ##### 2: Programmatic interface for starting and stopping Mirage
140
+ The client API now includes the ability to start and stop Mirage locally. No more calling out to the command line.
141
+
142
+ **Example Usage:** (See rdoc for full details)
143
+
144
+ mirage_client = Mirage.start :port => 9001 #with out args start mirage on 7001 by default
145
+ Mirage.stop # stops the current running instance as long as only one is running
146
+
147
+ ##### 3: Updated command line interface
148
+ Now powered by the mighty Thor, the stop subcommand has been enhanced.
149
+ **Usage:**
150
+
151
+ mirage stop -> As it always did, stops the current instances of Mirage as long as there is only one running instance.
152
+ mirage stop -p port -> stops Mirage on a given port.
153
+ mirage stop -p port1, port2... -> stop multiple instances of Mirage.
154
+ mirage stop -p all -> stop all instances of mirage.
155
+ #### What do I have to do to upgrade?
156
+ You shouldn't have to do anything to move from the last version of Mirage to this one. Let me know if something stops working!
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+
3
+ Bundler.setup(:default, :development)
4
+ Bundler.require(:test, :development)
5
+
6
+ Dir["#{File.dirname(__FILE__)}/tasks/**/*.rake"].each do |tasks|
7
+ import tasks
8
+ end
9
+
10
+ task :default => [:specs, :install, :features, :clean]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 3.0.8
data/bin/mirage ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+
4
+
5
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib")
6
+ require 'mirage/client'
7
+
8
+ begin
9
+ Mirage::Runner.start
10
+ rescue Mirage::ClientError => e
11
+ puts e.message
12
+ exit 1
13
+ end
14
+
data/features/.nav ADDED
@@ -0,0 +1,29 @@
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):
20
+ - start.feature
21
+ - stop.feature
22
+ - running.feature
23
+ - put.feature
24
+ - configure.feature
25
+ - clear.feature
26
+ - preview_responses.feature
27
+ - model.feature
28
+ - requests.feature
29
+ - save_and_revert.feature