mirage 3.0.0.alpha.17 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.ruby-gemset +1 -0
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile.lock +107 -76
  5. data/README.md +2 -1
  6. data/{rakefile → Rakefile} +0 -0
  7. data/VERSION +1 -1
  8. data/features/.nav +10 -0
  9. data/features/client/clear.feature +5 -3
  10. data/features/client/configure.feature +4 -2
  11. data/features/client/model.feature +95 -0
  12. data/features/client/preview_responses.feature +7 -6
  13. data/features/client/prime.feature +32 -0
  14. data/features/client/put.feature +14 -43
  15. data/features/client/readme.md +3 -0
  16. data/features/client/requests.feature +3 -1
  17. data/features/client/running.feature +4 -2
  18. data/features/client/save_and_revert.feature +5 -3
  19. data/features/client/start.feature +3 -1
  20. data/features/client/stop.feature +3 -1
  21. data/features/commandline_interface/help.feature +1 -1
  22. data/features/prime.feature +5 -5
  23. data/features/step_definitions/my_steps.rb +3 -0
  24. data/features/templates/preview.feature +2 -2
  25. data/features/templates/put_with_substitutions.feature +1 -1
  26. data/features/templates/readme.md +0 -3
  27. data/features/web_user_interface.feature +39 -27
  28. data/lib/mirage/client/client.rb +0 -1
  29. data/lib/mirage/client/error.rb +2 -2
  30. data/lib/mirage/client/runner.rb +1 -1
  31. data/lib/mirage/client/template.rb +1 -1
  32. data/lib/mirage/client/templates.rb +1 -1
  33. data/mirage.gemspec +12 -11
  34. data/server/extensions/hash.rb +1 -1
  35. data/spec/client/cli_bridge_spec.rb +2 -2
  36. data/spec/client/client_spec.rb +4 -4
  37. data/spec/client/runner_spec.rb +13 -12
  38. data/spec/client/template/model/instance_methods_spec.rb +1 -1
  39. data/spec/client/template_spec.rb +1 -1
  40. data/spec/client/templates_spec.rb +7 -7
  41. data/spec/server/server_spec.rb +1 -1
  42. data/spec/spec_helper.rb +3 -3
  43. data/{responses/default_responses.rb → todo.list} +0 -0
  44. metadata +14 -13
  45. data/.rvmrc +0 -1
  46. data/profiles.rb +0 -1
  47. data/test.html +0 -12
  48. data/test.rb +0 -5
  49. data/todo.lst +0 -2
@@ -1,18 +1,21 @@
1
- Feature: the Mirage client provides methods for setting responses and loading default responses.
2
- There is no need to escape any parameters before using the client api as this is done for you.
1
+ Feature: Adding Templates
3
2
 
4
- Patterns can be either a string or regex object.
3
+ The Mirage client provides methods for setting Templates.
4
+
5
+ The client will escape all data for you so your free to just get on with using Mirage :)
6
+
7
+ Body, Header, and Parameter requirements can be specified as either a String or Regexp
5
8
 
6
9
  Background:
7
10
  Given the following gems are required to run the Mirage client test code:
8
11
  """
9
12
  require 'rubygems'
10
- require 'rspec'
13
+ require 'rspec/expectations'
11
14
  require 'mirage/client'
12
15
  """
13
16
 
14
17
 
15
- Scenario: Setting a basic response
18
+ Scenario: Setting a Template on Mirage
16
19
  Given I run
17
20
  """
18
21
  Mirage::Client.new.put('greeting','hello')
@@ -20,7 +23,7 @@ Feature: the Mirage client provides methods for setting responses and loading de
20
23
  When GET is sent to '/responses/greeting'
21
24
  Then 'hello' should be returned
22
25
 
23
- Scenario: Setting the method that a response should be returned on
26
+ Scenario: Setting the required HTTP method
24
27
  Given I run
25
28
  """
26
29
  Mirage::Client.new.put('greeting', 'Hello Leon') do
@@ -33,7 +36,7 @@ Feature: the Mirage client provides methods for setting responses and loading de
33
36
  Then 'Hello Leon' should be returned
34
37
 
35
38
 
36
- Scenario: Setting a response with required body content
39
+ Scenario: Setting a requirement on body content
37
40
  Given I run
38
41
  """
39
42
  Mirage::Client.new.put('greeting', 'Hello Leon') do
@@ -51,7 +54,7 @@ Feature: the Mirage client provides methods for setting responses and loading de
51
54
  """
52
55
  Then 'Hello Leon' should be returned
53
56
 
54
- Scenario: Setting a response with a request parameter requirement
57
+ Scenario: Setting a requirement on requests parameters
55
58
  Given I run
56
59
  """
57
60
  Mirage::Client.new.put('greeting', 'Hello Leon') do
@@ -89,40 +92,8 @@ Feature: the Mirage client provides methods for setting responses and loading de
89
92
  When GET is sent to '/responses/greeting'
90
93
  And the response 'content-type' should be 'text/xml'
91
94
 
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
112
-
113
- Scenario: Setting a file as a response
114
- Given the file 'test_file.txt' contains:
115
- """
116
- test content
117
- """
118
- And I run
119
- """
120
- Mirage::Client.new.put('download', File.read('test_file.txt'))
121
- """
122
- When GET is sent to '/responses/download'
123
- Then the response should be the same as the content of 'test_file.txt'
124
-
125
- Scenario: Setting a response status code
95
+
96
+ Scenario: Setting the HTTP status code
126
97
  Given I run
127
98
  """
128
99
  Mirage::Client.new.put('greeting', 'hello'){status 203}
@@ -131,7 +102,7 @@ Feature: the Mirage client provides methods for setting responses and loading de
131
102
  Then a 203 should be returned
132
103
 
133
104
 
134
- Scenario: Setting a response with a delay
105
+ Scenario: Setting a delay
135
106
  Given I run
136
107
  """
137
108
  Mirage::Client.new.put('greeting', 'hello'){delay 2}
@@ -0,0 +1,3 @@
1
+ Mirage has a client implemented in Ruby. It's fully functional and includes a command line interface for controlling the Mirage server direct from your test suite.
2
+
3
+
@@ -1,4 +1,6 @@
1
- Feature: Requests made to the Mirage Server can be retrieved using the Mirage client
1
+ Feature: Retrieving tracked requests
2
+
3
+ Requests made to the Mirage Server can be retrieved using the Mirage client
2
4
 
3
5
  Background:
4
6
  Given the following require statements are needed:
@@ -1,12 +1,14 @@
1
1
  @command_line
2
- Feature: Use the mirage client api to check if Mirage is running either on the local machine or on a remote host.
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.
3
5
 
4
6
 
5
7
  Background:
6
8
  Given the following gems are required to run the Mirage client test code:
7
9
  """
8
10
  require 'rubygems'
9
- require 'rspec'
11
+ require 'rspec/expectations'
10
12
  require 'mirage/client'
11
13
  """
12
14
 
@@ -1,17 +1,19 @@
1
- Feature: The Mirage client can be used to snaphsot and rollback the Mirage server
1
+ Feature: Creating snapshots
2
+
3
+ The client can be used to snapshot and rollback the Mirage server
2
4
 
3
5
 
4
6
  Background:
5
7
  Given the following gems are required to run the Mirage client test code:
6
8
  """
7
9
  require 'rubygems'
8
- require 'rspec'
10
+ require 'rspec/expectations'
9
11
  require 'mirage/client'
10
12
  """
11
13
  And a template for 'greeting' has been set with a value of 'The default greeting'
12
14
 
13
15
 
14
- Scenario: saving and reverting
16
+ Scenario: Creating a snapshot and rolling back
15
17
  Given I run
16
18
  """
17
19
  Mirage::Client.new.save
@@ -1,5 +1,7 @@
1
1
  @command_line
2
- Feature: The client API can be used to start Mirage.
2
+ Feature: Starting Mirage
3
+
4
+ The client can be used to start Mirage.
3
5
 
4
6
  Both the port and default templates directory can be specified
5
7
 
@@ -1,5 +1,7 @@
1
1
  @command_line
2
- Feature:The client API can be used to stop instances of Mirage running on localhost.
2
+ Feature: Stopping Mirage
3
+
4
+ The client API can be used to stop instances of Mirage running on localhost.
3
5
 
4
6
  Background:
5
7
  Given the following require statements are needed:
@@ -6,7 +6,7 @@ Feature: Help
6
6
  Background: Mirage usage
7
7
  Given usage information:
8
8
  """
9
- mirage help [TASK] # Describe available tasks or one specific task
9
+ mirage help [COMMAND] # Describe available commands or one specific command
10
10
  mirage start # Starts mirage
11
11
  mirage stop # Stops mirage
12
12
  """
@@ -1,8 +1,8 @@
1
1
  #TODO - rename responses directory to templates
2
2
  @command_line
3
- Feature: Preloading templates
3
+ Feature: Preloading Templates
4
4
  Mirage can be primed with a set of templates.
5
- By default, Mirage loads any .rb files found in ./responses on startup. Mirage can also be made to load responses from a directory
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
6
  of your choosing by using the -d/--defaults option
7
7
 
8
8
  Responses can be added to the responses directory and used to prime Mirage after Mirage has been started.
@@ -11,7 +11,7 @@ Feature: Preloading templates
11
11
 
12
12
 
13
13
  Scenario: Using the default responses directory
14
- Given the file 'responses/default_greetings.rb' contains:
14
+ Given the file 'mirage/default_greetings.rb' contains:
15
15
  """
16
16
  prime do |mirage|
17
17
  mirage.templates.put('greeting', 'hello')
@@ -24,12 +24,12 @@ Feature: Preloading templates
24
24
 
25
25
  Scenario: Using a custom responses directory
26
26
  Given Mirage is not running
27
- And the file '/tmp/responses/default_greetings.rb' contains:
27
+ And the file '/tmp/mirage/default_greetings.rb' contains:
28
28
  """
29
29
  prime do |mirage|
30
30
  mirage.templates.put('greeting', 'hello')
31
31
  end
32
32
  """
33
- And I run 'mirage start --defaults /tmp/responses'
33
+ And I run 'mirage start --defaults /tmp/mirage'
34
34
  And GET is sent to '/responses/greeting'
35
35
  Then 'hello' should be returned
@@ -275,4 +275,7 @@ Then(/^the template (request|response) specification should have the following s
275
275
  end
276
276
  Then(/^the following json should be returned:$/) do |text|
277
277
  JSON.parse(text).should == JSON.parse(@response.body)
278
+ end
279
+ When(/^the content-type should be '(.*)'$/) do |content_type|
280
+ @response.content_type.should == content_type
278
281
  end
@@ -1,5 +1,5 @@
1
- Feature: Retrieving
2
- A Templates body can be previewed
1
+ Feature: Previewing
2
+ A Template's body can be previewed
3
3
 
4
4
 
5
5
  Scenario: Preview template body
@@ -1,5 +1,5 @@
1
1
  Feature: Substituting values from requests in to a template
2
- Parts of a response can be substitued for values found in the request body or query string.
2
+ Parts of a response can be substituted for values found in the request body or query string.
3
3
  This allows dynamic content to be sent back to a client.
4
4
 
5
5
  To do this, substitution, matchers must be put in the the response value.
@@ -2,6 +2,3 @@ Templates are the descriptors pushed to Mirage to tell it what to return to a cl
2
2
 
3
3
  They can be configured to place restrictions on the requests that should be met before they are allowed to be used to generate a response.
4
4
 
5
- title
6
- -----
7
-
@@ -1,32 +1,44 @@
1
1
  Feature: Web interface
2
- Mirage's home page allows you to see what response are currently being hosted.
3
- From this page you can:
4
- - Peek at a responses content
5
- - Track the response to see if a request has been made to it
6
-
7
- #TODO tests needed for displaying pattern and delay values and http method
2
+ Note: This feature is being rewritten but the screens pretty basic so take a look:
8
3
 
9
- Background: There are already a couple of responses hosted on he Mirage server
10
- Given I send PUT to '/templates/greeting' with body 'hello' and headers:
11
- | X-mirage-default | true |
12
- | X-mirage-method | POST |
13
- And I send PUT to '/templates/leaving' with body 'goodbye'
4
+ The home page is served from '/' so by default is found at http://localhost:7001/
14
5
 
15
- Scenario: Using the home page to see what response are being hosted
16
- Given I goto ''
17
- Then I should see 'greeting/*'
18
- Then I should see 'leaving'
6
+ Mirage's home page allows you to see what response are currently being hosted.
7
+ From this page you can:
8
+ - See all currently hosted templates
9
+ - Preview at a Templates content
10
+ - View the last request to trigger a particular Template
19
11
 
20
- Scenario: Using the home page to peek at a response
21
- Given I goto ''
22
- When I click 'peek_response_1'
23
- Then I should see 'hello'
24
12
 
25
- Scenario: Using the home page to track if a request has been made
26
- Given I send POST to '/responses/greeting' with request entity
27
- """
28
- Yo!
29
- """
30
- Given I goto ''
31
- When I click 'track_response_1'
32
- Then I should see 'Yo!'
13
+ # Background: There are already a couple of responses hosted on he Mirage server
14
+ # Given the following template template:
15
+ # """
16
+ # {
17
+ # "response":{
18
+ # "body":"SGVsbG8="
19
+ # },
20
+ # "request":{
21
+ # }
22
+ # }
23
+ # """
24
+ # And the template is sent using PUT to '/templates/greeting'
25
+ #
26
+ #
27
+ # Scenario: Using the home page to see what response are being hosted
28
+ # Given I goto to the Mirage home page
29
+ # Then I should see 'greeting/*'
30
+ # Then I should see 'leaving'
31
+ #
32
+ # Scenario: Using the home page to peek at a response
33
+ # Given I goto ''
34
+ # When I click 'peek_response_1'
35
+ # Then I should see 'hello'
36
+ #
37
+ # Scenario: Using the home page to track if a request has been made
38
+ # Given I send POST to '/responses/greeting' with request entity
39
+ # """
40
+ # Yo!
41
+ # """
42
+ # Given I goto ''
43
+ # When I click 'track_response_1'
44
+ # Then I should see 'Yo!'
@@ -11,7 +11,6 @@ module Mirage
11
11
 
12
12
  def initialize options={:url => "http://localhost:7001"}, &block
13
13
  if options.is_a?(String) && options =~ URI.regexp
14
- warn("Client.new(url): Deprecated usage, please use :url => url | :port => port")
15
14
  @url = options
16
15
  elsif options.kind_of?(Hash) && options[:port]
17
16
  @url = "http://localhost:#{options[:port]}"
@@ -8,10 +8,10 @@ module Mirage
8
8
  end
9
9
  end
10
10
 
11
- class InternalServerException < MirageError;
11
+ class InternalServerException < MirageError
12
12
  end
13
13
 
14
- class ResponseNotFound < ::Exception
14
+ class TemplateNotFound < ::Exception
15
15
  end
16
16
 
17
17
  class ClientError < ::Exception
@@ -56,7 +56,7 @@ module Mirage
56
56
 
57
57
  desc "start", "Starts mirage"
58
58
  method_option :port, :aliases => "-p", :type => :numeric, :default => 7001, :desc => "port that mirage should be started on"
59
- method_option :defaults, :aliases => "-d", :type => :string, :default => 'responses', :desc => "location to load default responses from"
59
+ method_option :defaults, :aliases => "-d", :type => :string, :default => 'mirage', :desc => "location to load default responses from"
60
60
  method_option :debug, :type => :boolean, :default => false, :desc => "run in debug mode"
61
61
 
62
62
  def start
@@ -19,7 +19,7 @@ module Mirage
19
19
 
20
20
  def get url
21
21
  response = backedup_get(url, :format => :json)
22
- raise ResponseNotFound if response.code == 404
22
+ raise TemplateNotFound if response.code == 404
23
23
  response_hashie = Hashie::Mash.new response
24
24
 
25
25
  response_config = response_hashie.response
@@ -25,7 +25,7 @@ module Mirage
25
25
  if args.first.class.is_a?(Template::Model)
26
26
  template = args.first
27
27
  template = template.clone
28
- template.endpoint "#{@url}/#{template.endpoint}" unless template.endpoint.to_s.start_with?(@url)
28
+ template.endpoint "#{@url}/#{template.endpoint}"
29
29
  else
30
30
 
31
31
  endpoint, template = args
data/mirage.gemspec CHANGED
@@ -1,34 +1,40 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mirage"
8
- s.version = "3.0.0.alpha.17"
8
+ s.version = "3.0.0"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Leon Davis"]
12
- s.date = "2013-10-22"
12
+ s.date = "2013-10-27"
13
13
  s.description = "Mirage aids testing of your applications by hosting mock responses so that your applications do not have to talk to real endpoints. Its accessible via HTTP and has a RESTful interface."
14
14
  s.executables = ["mirage"]
15
15
  s.extra_rdoc_files = [
16
16
  "README.md"
17
17
  ]
18
18
  s.files = [
19
- ".rvmrc",
19
+ ".ruby-gemset",
20
+ ".ruby-version",
20
21
  ".simplecov",
22
+ ".travis.yml",
21
23
  "Gemfile",
22
24
  "Gemfile.lock",
23
25
  "HISTORY",
24
26
  "README.md",
27
+ "Rakefile",
25
28
  "VERSION",
26
29
  "bin/mirage",
27
30
  "features/.nav",
28
31
  "features/client/clear.feature",
29
32
  "features/client/configure.feature",
33
+ "features/client/model.feature",
30
34
  "features/client/preview_responses.feature",
35
+ "features/client/prime.feature",
31
36
  "features/client/put.feature",
37
+ "features/client/readme.md",
32
38
  "features/client/requests.feature",
33
39
  "features/client/running.feature",
34
40
  "features/client/save_and_revert.feature",
@@ -76,9 +82,6 @@ Gem::Specification.new do |s|
76
82
  "lib/mirage/client/templates.rb",
77
83
  "mirage.gemspec",
78
84
  "mirage_server.rb",
79
- "profiles.rb",
80
- "rakefile",
81
- "responses/default_responses.rb",
82
85
  "server/app.rb",
83
86
  "server/binary_data_checker.rb",
84
87
  "server/extensions/hash.rb",
@@ -104,9 +107,7 @@ Gem::Specification.new do |s|
104
107
  "spec/server/mock_response_spec.rb",
105
108
  "spec/server/server_spec.rb",
106
109
  "spec/spec_helper.rb",
107
- "test.html",
108
- "test.rb",
109
- "todo.lst",
110
+ "todo.list",
110
111
  "views/index.haml",
111
112
  "views/response.haml"
112
113
  ]