lashd / mirage Goto Github PK
View Code? Open in Web Editor NEWA HTTP based mock server written in Ruby
A HTTP based mock server written in Ruby
Creating this as an enhancement after a discussion with @lashd. Using Rack Test will be a performance enhancement in terms of speed.
When using the mirage client to access request data for a template that has not yet been triggered an nonsensical exception is reported
Mirage.start.requests(300)
=>
/home/team/.rvm/gems/ruby-2.0.0-p451@accessory-shop/gems/httparty-0.13.1/lib/httparty/response.rb:66:in `method_missing': undefined method `each_pair' for #<HTTParty::Response:0x00000000ab48c0> (NoMethodError)
from /home/team/.rvm/gems/ruby-2.0.0-p451@accessory-shop/gems/hashie-2.1.1/lib/hashie/mash.rb:152:in `deep_update'
from /home/team/.rvm/gems/ruby-2.0.0-p451@accessory-shop/gems/hashie-2.1.1/lib/hashie/mash.rb:67:in `initialize'
from /home/team/.rvm/gems/ruby-2.0.0-p451@accessory-shop/gems/mirage-3.0.6/lib/mirage/client/request.rb:9:in `new'
from /home/team/.rvm/gems/ruby-2.0.0-p451@accessory-shop/gems/mirage-3.0.6/lib/mirage/client/request.rb:9:in `get'
from /home/team/.rvm/gems/ruby-2.0.0-p451@accessory-shop/gems/mirage-3.0.6/lib/mirage/client/client.rb:41:in `requests'
Trying to add a required header value for Content-Type or Content-Length results in a condition never met.
The problem doesn't seem to be related to the hyphen in the header key as it works for other header keys like 'If-Then'
Adding one more letter to the previous failing headers make it working properly. e.g Content-Lenghta, Content-Typea
To reproduce the bug:
mirage.put('/some','hello') do
required_headers[:'Content-Type']='type'
end
I've received feed back that it could be useful to know how many times requests have been received for a particular template.
E.g. by making a call such as
client.requests(template_id).count
The http service end point could be something like
Example Request
GET /requests/id/count
Example Response
HTTP Status: 200
Content-Type: application/json
Body: {count: 123}
This feature should be accompanied with some kind of reset capability so that the count/all counts can be reset.
estimate 5
Hey Leon,
Would it be possible to get a Mirage Docker image pushed https://hub.docker.com/ so it can be used in a docker environment as an external dependency?
Chris
When getting request data back, the url that triggered this template is not reported.
When setting a template as the default for a URI or using wildcards in the template URI it could be useful to find out what URL was used
Installed Mirage through sudo gem install mirage : Then ran mirage start and got the following output from Mirage.
WARNING: #<ArgumentError: Illformed requirement ["#YAML::Syck::DefaultKey:0x105fb5ad0 2.6.0"]>
Gem::Specification.new do |s|
s.name = %q{mirage}
s.version = "2.0.11"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Leon Davis"]
s.date = %q{2011-12-20 00:00:00.000000000Z}
s.default_executable = %q{mirage}
s.description = %q{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.}
s.executables = ["mirage"]
s.extra_rdoc_files = ["README.md"]
s.files = [".rvmrc", "Gemfile", "Gemfile.lock", "HISTORY", "README.md", "VERSION", "bin/mirage", "features/client/clear.feature", "features/client/mirage_client.feature", "features/client/put.feature", "features/client/request.feature", "features/client/response.feature", "features/client/save_and_revert.feature", "features/server/command_line_iterface.feature", "features/server/logging.feature", "features/server/prime.feature", "features/server/requests/delete.feature", "features/server/requests/get.feature", "features/server/save_and_revert.feature", "features/server/templates/delete.feature", "features/server/templates/get.feature", "features/server/templates/put/put.feature", "features/server/templates/put/put_as_default.feature", "features/server/templates/put/put_with_delay.feature", "features/server/templates/put/put_with_pattern.feature", "features/server/templates/put/put_with_substitutions.feature", "features/server/web_user_interface.feature", "features/step_definitions/my_steps.rb", "features/support/env.rb", "full_build.sh", "lib/mirage/client.rb", "lib/mirage/client/web.rb", "mirage.gemspec", "mirage_server.rb", "rakefile", "server/extensions/hash.rb", "server/extensions/object.rb", "server/mock_response.rb", "server/util.rb", "test.rb", "views/index.erb"]
s.homepage = %q{https://github.com/lashd/mirage}
s.licenses = ["MIT"]
Thanks you for installing mirage.
Run Mirage with:
mirage start
}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
s.summary = %q{Mirage is a easy mock server for testing your applications}
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<sinatra>, [">= 0"])
s.add_runtime_dependency(%q<childprocess>, ["~> 0.1"])
s.add_runtime_dependency(%q<waitforit>, [">= 0"])
s.add_development_dependency(%q<rake>, [">= 0"])
s.add_development_dependency(%q<cucumber>, [">= 0"])
s.add_development_dependency(%q<rspec>, ["#<YAML::Syck::DefaultKey:0x105fb5ad0> 2.6.0"])
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
s.add_development_dependency(%q<sinatra-contrib>, [">= 0"])
s.add_development_dependency(%q<mechanize>, ["#<YAML::Syck::DefaultKey:0x105fb08c8> 1.0.0"])
s.add_development_dependency(%q<gemcutter>, [">= 0"])
s.add_development_dependency(%q<nokogiri>, ["#<YAML::Syck::DefaultKey:0x105fad2b8> 1.4.7"])
else
s.add_dependency(%q<sinatra>, [">= 0"])
s.add_dependency(%q<childprocess>, ["~> 0.1"])
s.add_dependency(%q<waitforit>, [">= 0"])
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<cucumber>, [">= 0"])
s.add_dependency(%q<rspec>, ["#<YAML::Syck::DefaultKey:0x105fb5ad0> 2.6.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
s.add_dependency(%q<sinatra-contrib>, [">= 0"])
s.add_dependency(%q<mechanize>, ["#<YAML::Syck::DefaultKey:0x105fb08c8> 1.0.0"])
s.add_dependency(%q<gemcutter>, [">= 0"])
s.add_dependency(%q<nokogiri>, ["#<YAML::Syck::DefaultKey:0x105fad2b8> 1.4.7"])
end
else
s.add_dependency(%q, [">= 0"])
s.add_dependency(%q, ["> 0.1"])> 1.5.2"])
s.add_dependency(%q, [">= 0"])
s.add_dependency(%q, [">= 0"])
s.add_dependency(%q, [">= 0"])
s.add_dependency(%q, ["#YAML::Syck::DefaultKey:0x105fb5ad0 2.6.0"])
s.add_dependency(%q, ["
s.add_dependency(%q, [">= 0"])
s.add_dependency(%q, ["#YAML::Syck::DefaultKey:0x105fb08c8 1.0.0"])
s.add_dependency(%q, [">= 0"])
s.add_dependency(%q, ["#YAML::Syck::DefaultKey:0x105fad2b8 1.4.7"])
end
end
WARNING: Invalid .gemspec format in '/Library/Ruby/Gems/1.8/specifications/mirage-2.0.11.gemspec'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:827:in report_activate_error': Could not find RubyGem mirage (>= 0) (Gem::LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:261:in
activate'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:68:in `gem'
from /usr/bin/mirage:18
#require 'mirage/client'
#Mirage.stop
#mirage = Mirage.start
#mirage.clear
#mirage.put('/greeting/*/nice', 'very nice to meet you')
#mirage.put('/greeting/leon/nice', 'very nice to meet you Leon')
You would expect the following code to result in to unique response templates being put on to Mirage. However when the second template is sent it replaces the content of the first instead of being added as new and unique entry.
This is due to the hack made to Hash and the way that it finds values based on Keys. I.e. If a stored key is a regex, it also try to match required key based on that. In this case the second endpoint can be matched with the first when used as a regex.
Would be nice to change
When a site makes a cross-origin ajax request, the browser makes 2 calls to the destination URL under the hood. The first call is a request with the OPTIONS
HTTP verb, to which the webserver sends back appropriate Access-Control headers which determine whether the webserver will accept the next request. This is followed by the actual request.
When mocking such a cross origin request, we need to populate mirage with two templates. Below is an example of what we had to do for a simple POST
request for example:
mirage.put('/api/endpoint', "") do
http_method :options
headers "Access-Control-Allow-Headers" => "Origin, X-Requested-With, Content-Type",
"Access-Control-Allow-Methods" => "POST",
"Access-Control-Allow-Origin" => "*"
end
mirage.put('/api/endpoint', {response: :body}.to_json) do
http_method :post
end
Might be worth having a DSL method for doing it in one go. If not then might be worth having it somewhere in the README as a recipe for front-end cross-origin testing.
Hi, good day.
I got mirage to crash with a binary request, of application/octet-stream content-type. I took a peak and it crashes when trying to read the body into a string.
Would you be willing to support such requests in some way? To me it is good enough that it doesn't crash when handling them but I guess it would be nice if they would also be handled in some way, even though it wouldn't make much sense to match responses with requests of binary tipe perhaps?
If not, would you be willing to accept a pull request for this issue somehow?
Cheers and thanks.
The feature tests for this gem are contained within, and naming our own steps with identical names results in duplicate warnings in Intellij IDEA. for example implementing "I click..".
Setting nil parameter for the response does not work with the builder methods as expected and returns default value instead of being updated to nil.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.