Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 7b24a64f20975aeba3a1892af2632f3264caaff6 @jugyo committed Feb 21, 2012
Showing with 108 additions and 0 deletions.
  1. +4 −0 Gemfile
  2. +47 −0 README.md
  3. +1 −0 Rakefile
  4. +29 −0 lib/mocktra.rb
  5. +3 −0 lib/mocktra/version.rb
  6. +24 −0 mocktra.gemspec
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in mocktra.gemspec
+gemspec
47 README.md
@@ -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.
1 Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
29 lib/mocktra.rb
@@ -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
3 lib/mocktra/version.rb
@@ -0,0 +1,3 @@
+module Mocktra
+ VERSION = "1.0.0"
+end
24 mocktra.gemspec
@@ -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

0 comments on commit 7b24a64

Please sign in to comment.
Something went wrong with that request. Please try again.