mocktra 1.0.0

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.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mocktra.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ Mocktra
2
+ ====
3
+
4
+ A webmock DSL using sinatra.
5
+
6
+ Installation
7
+ ----
8
+
9
+ $ gem install mocktra
10
+
11
+ Examples
12
+ ----
13
+
14
+ require 'mocktra'
15
+
16
+ # define stub
17
+ Mocktra('www.example.com') do
18
+ get '/foo' do
19
+ 'FOO!!'
20
+ end
21
+
22
+ post '/foo' do
23
+ params.inspect
24
+ end
25
+ end
26
+
27
+ # test it
28
+ require 'httpclient'
29
+ client = HTTPClient.new
30
+
31
+ res = client.get("http://www.example.com/foo")
32
+ p res.body
33
+ #=> "FOO!!"
34
+
35
+ res = client.post("http://www.example.com/foo", 'bar' => 'baz')
36
+ p res.body
37
+ #=> "{\"bar\"=>\"baz\"}"
38
+
39
+ Notice
40
+ ----
41
+
42
+ Mocktra calls `WebMock.allow\_net\_connect!` when loading.
43
+
44
+ Copyright
45
+ ----
46
+
47
+ Copyright (c) 2012 jugyo, released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Mocktra
2
+ VERSION = "1.0.0"
3
+ end
data/lib/mocktra.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "mocktra/version"
2
+ require 'webmock'
3
+ require 'sinatra/base'
4
+
5
+ WebMock.allow_net_connect!
6
+
7
+ module Mocktra
8
+ class << self
9
+ def mocktra(pattern, &block)
10
+ # TODO
11
+ pattern = case pattern
12
+ when Regexp
13
+ pattern
14
+ when /^http/
15
+ /^#{Regexp.quote(pattern)}/
16
+ else
17
+ /#{Regexp.quote(pattern)}/
18
+ end
19
+ rack_app = Class.new(Sinatra::Base, &block)
20
+ WebMock::API.stub_request(:any, pattern).to_rack(rack_app)
21
+ end
22
+ end
23
+ end
24
+
25
+ module Kernel
26
+ def Mocktra(*args, &block)
27
+ Mocktra.mocktra(*args, &block)
28
+ end
29
+ end
data/mocktra.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mocktra/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mocktra"
7
+ s.version = Mocktra::VERSION
8
+ s.authors = ["jugyo"]
9
+ s.email = ["jugyo.org@gmail.com"]
10
+ s.homepage = "https://github.com/jugyo/mocktra"
11
+ s.summary = %q{webmock + sinatra}
12
+ s.description = %q{A webmock DSL using sinatra.}
13
+
14
+ s.rubyforge_project = "mocktra"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "webmock"
24
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mocktra
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jugyo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: webmock
16
+ requirement: &70205948425660 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70205948425660
25
+ description: A webmock DSL using sinatra.
26
+ email:
27
+ - jugyo.org@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - Gemfile
33
+ - README.md
34
+ - Rakefile
35
+ - lib/mocktra.rb
36
+ - lib/mocktra/version.rb
37
+ - mocktra.gemspec
38
+ homepage: https://github.com/jugyo/mocktra
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project: mocktra
58
+ rubygems_version: 1.8.10
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: webmock + sinatra
62
+ test_files: []