-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jugyo
committed
Feb 20, 2012
0 parents
commit 7b24a64
Showing
6 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in mocktra.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Mocktra | ||
==== | ||
|
||
A webmock DSL using sinatra. | ||
|
||
Installation | ||
---- | ||
|
||
$ gem install mocktra | ||
|
||
Examples | ||
---- | ||
|
||
require 'mocktra' | ||
|
||
# define stub | ||
Mocktra('www.example.com') do | ||
get '/foo' do | ||
'FOO!!' | ||
end | ||
|
||
post '/foo' do | ||
params.inspect | ||
end | ||
end | ||
|
||
# test it | ||
require 'httpclient' | ||
client = HTTPClient.new | ||
|
||
res = client.get("http://www.example.com/foo") | ||
p res.body | ||
#=> "FOO!!" | ||
|
||
res = client.post("http://www.example.com/foo", 'bar' => 'baz') | ||
p res.body | ||
#=> "{\"bar\"=>\"baz\"}" | ||
|
||
Notice | ||
---- | ||
|
||
Mocktra calls `WebMock.allow\_net\_connect!` when loading. | ||
|
||
Copyright | ||
---- | ||
|
||
Copyright (c) 2012 jugyo, released under the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require "mocktra/version" | ||
require 'webmock' | ||
require 'sinatra/base' | ||
|
||
WebMock.allow_net_connect! | ||
|
||
module Mocktra | ||
class << self | ||
def mocktra(pattern, &block) | ||
# TODO | ||
pattern = case pattern | ||
when Regexp | ||
pattern | ||
when /^http/ | ||
/^#{Regexp.quote(pattern)}/ | ||
else | ||
/#{Regexp.quote(pattern)}/ | ||
end | ||
rack_app = Class.new(Sinatra::Base, &block) | ||
WebMock::API.stub_request(:any, pattern).to_rack(rack_app) | ||
end | ||
end | ||
end | ||
|
||
module Kernel | ||
def Mocktra(*args, &block) | ||
Mocktra.mocktra(*args, &block) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Mocktra | ||
VERSION = "1.0.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "mocktra/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "mocktra" | ||
s.version = Mocktra::VERSION | ||
s.authors = ["jugyo"] | ||
s.email = ["jugyo.org@gmail.com"] | ||
s.homepage = "https://github.com/jugyo/mocktra" | ||
s.summary = %q{webmock + sinatra} | ||
s.description = %q{A webmock DSL using sinatra.} | ||
|
||
s.rubyforge_project = "mocktra" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
# specify any dependencies here; for example: | ||
# s.add_development_dependency "rspec" | ||
s.add_runtime_dependency "webmock" | ||
end |