so_stub_very_test 0.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +199 -0
- data/Rakefile +7 -0
- data/lib/so_stub_very_test.rb +146 -0
- data/lib/so_stub_very_test/version.rb +3 -0
- data/so_stub_very_test.gemspec +24 -0
- data/test/so_stub_very_test_test.rb +198 -0
- data/test/test_helper.rb +5 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d912b883c1d926912500fa80ce5f4e460ea01dc9
|
4
|
+
data.tar.gz: d82a68fabdf2f56a50b878633dcd2949dab11852
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea777bbd8495e096e869297969cdcf534601e4a889b47764a3cdaa14704328b00ca28fe4fb531b6efe534b08a8349883af8cb5a6924c94abc2021fd96545c2cf
|
7
|
+
data.tar.gz: ba463db45f01362989a81c6186c3d18d411ad8da0238c9496371f5117f92fe094bd890615c43932980ddfc3afc4bd1f9b68cdd7bd7a22556c6b0cad1eec2f262
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jonathan Clem
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
# SoStubVeryTest
|
2
|
+
|
3
|
+
```doge
|
4
|
+
so stub
|
5
|
+
|
6
|
+
very test
|
7
|
+
|
8
|
+
much excon
|
9
|
+
wow
|
10
|
+
```
|
11
|
+
|
12
|
+
SoStubVeryTest provides a simpler method for stubbing Excon in your tests, because
|
13
|
+
typing `Excon.stub({}, {})` over and over again is like taking the first train to
|
14
|
+
Repetitive Stress Injury town.
|
15
|
+
|
16
|
+
Further, it provides an easy way to set up default stubs for your test suite, so
|
17
|
+
that you can clear out the Excon stubs that were stubbed in your individual test
|
18
|
+
setup, but still have useful default ones around (they usually return empty arrays
|
19
|
+
and hashes).
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
gem 'so_stub_very_test'
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install so_stub_very_test
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
### HTTP Verb Stubs
|
38
|
+
|
39
|
+
SoStubVeryTest is a module that you include to provide some handy methods for
|
40
|
+
stubbing Excon requests. Here's a random smattering of examples:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
stub_get "/foo", [1,2,3]
|
44
|
+
# Equivalent: Excon.stub({ path: /\A\/foo\Z/, method: :get }, { body: [1,2,3] })
|
45
|
+
# ^ so stubbed
|
46
|
+
|
47
|
+
stub_post "/foo", body: [1,2,3], status: 201
|
48
|
+
# Equivalent: Excon.stub({ path: /\A\/foo\Z/, method: :post }, { body: [1,2,3], status: 201 })
|
49
|
+
# ^ very protocol
|
50
|
+
```
|
51
|
+
|
52
|
+
You can use blocks for your response body:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
stub_get "/foo" do
|
56
|
+
{
|
57
|
+
body: "no meme here"
|
58
|
+
}
|
59
|
+
end
|
60
|
+
# Equivalent: Excon.stub({ path: /\A\/foo\Z/, method: :post }, { body: "no meme here" })
|
61
|
+
```
|
62
|
+
|
63
|
+
SoStubVeryTest will naïvely turn path parameters (any group of non-`/` preceded
|
64
|
+
by a colon) into regex thingies:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
stub_get "/foo/:bar", [1,2,3]
|
68
|
+
# Equivalent: Excon.stub({ path: /\A\/foo\/[^\/]+\Z/, method: :get }, { body: [1,2,3] })
|
69
|
+
# ^ much regular expression
|
70
|
+
```
|
71
|
+
|
72
|
+
### Namespacing
|
73
|
+
|
74
|
+
You can namespace things:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
namespace "/doges" do
|
78
|
+
stub_get [] # no path stubs the namespace's path
|
79
|
+
stub_post "/wow", [1,2,3]
|
80
|
+
|
81
|
+
namespace "/very" do
|
82
|
+
stub_get "/much", {}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Equivalent:
|
87
|
+
# Excon.stub({ path: /\A\/doges\Z/, method: :get }, { body: [] })
|
88
|
+
# Excon.stub({ path: /\A\/doges\/wow\Z/, method: :post }, { body: [1,2,3] })
|
89
|
+
# Excon.stub({ path: /\A\/doges\/very\/much\Z/, method: :get }, { body: {} })
|
90
|
+
```
|
91
|
+
|
92
|
+
### Default Host Setting Upping
|
93
|
+
|
94
|
+
You can set a default host:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
SoStubVeryTest.default_host = "doge.example.com"
|
98
|
+
stub_get "/foo", [1,2,3]
|
99
|
+
# Equivalent: Excon.stub({ path: /\A\/foo\Z/, method: :get, host: "doge.example.com" }, { body: [1,2,3] })
|
100
|
+
```
|
101
|
+
|
102
|
+
### Extra Host Setting Upping
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
SoStubVeryTest.register_host :doge, "doge.example.com"
|
106
|
+
|
107
|
+
# Use namespaces
|
108
|
+
doge_namespace "/w00t" do
|
109
|
+
stub_get "/cool", [] # the host prefix isn't necessary when in a namespace block
|
110
|
+
end
|
111
|
+
|
112
|
+
# Or don't use namespaces
|
113
|
+
doge_stub_get "/twinkie", []
|
114
|
+
|
115
|
+
# Excon.stub({ path: /\A\/w00t\/cool\Z/, method: :get, host: "doge.example.com"})
|
116
|
+
# Excon.stub({ path: /\A\/twinkie\Z/, method: :get, host: "doge.example.com"})
|
117
|
+
```
|
118
|
+
|
119
|
+
### Providing Default Stubs
|
120
|
+
|
121
|
+
You can provide default stubs that will not be cleared when calling
|
122
|
+
`SoStubVeryTest.clear_custom_stubs` by creating them in a special `defaults`
|
123
|
+
block:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
# Ensures that unless you manually call `Excon.stubs.clear` or override the stub,
|
127
|
+
# GETing /woot will always be stubbed with a `[]` response.
|
128
|
+
SoStubVeryTest.defaults do
|
129
|
+
namespace "/woot" do
|
130
|
+
stub_get []
|
131
|
+
end
|
132
|
+
end
|
133
|
+
```
|
134
|
+
|
135
|
+
## Testing with SoStubVeryTest
|
136
|
+
|
137
|
+
### For RSpec
|
138
|
+
|
139
|
+
In your `spec_helper.rb`, you'll probably want something like this:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
require "so_stub_very_test"
|
143
|
+
|
144
|
+
RSpec.configure do |config|
|
145
|
+
config.include SoStubVeryTest
|
146
|
+
|
147
|
+
before :all do
|
148
|
+
Excon.defaults[:mock] = true
|
149
|
+
end
|
150
|
+
|
151
|
+
after :each do
|
152
|
+
SoStubVeryTest.clear_custom_stubs
|
153
|
+
end
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
Then you can spend less time writing stubs for your specs:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
before do
|
161
|
+
stub_get "/doge", "hi from doge"
|
162
|
+
end
|
163
|
+
|
164
|
+
it "gets the doge" do
|
165
|
+
# ...
|
166
|
+
end
|
167
|
+
```
|
168
|
+
|
169
|
+
### For Minitest
|
170
|
+
|
171
|
+
I don't really use Minitest much (lol i know i'm using it in this very repo),
|
172
|
+
but you'd probs do this:
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
require "so_stub_very_test"
|
176
|
+
|
177
|
+
class TestDoges < Minitest::Test
|
178
|
+
def setup
|
179
|
+
Excon.defaults[:mock] = true
|
180
|
+
end
|
181
|
+
|
182
|
+
def teardown
|
183
|
+
SoStubVeryTest.clear_custom_stubs
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_the_doge
|
187
|
+
stub_get "/doge", "hi from doge"
|
188
|
+
assert_equal "hi from doge", Excon.get({ path: "/doge" })
|
189
|
+
end
|
190
|
+
end
|
191
|
+
```
|
192
|
+
|
193
|
+
## Contributing
|
194
|
+
|
195
|
+
1. Fork it ( http://github.com/<my-github-username>/so_stub_very_test/fork )
|
196
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
197
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
198
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
199
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
require "so_stub_very_test/version"
|
2
|
+
require "excon"
|
3
|
+
|
4
|
+
module SoStubVeryTest
|
5
|
+
extend self
|
6
|
+
|
7
|
+
class AmbiguousResponseError < StandardError; end
|
8
|
+
class MixedNamespacesError < StandardError; end
|
9
|
+
class NoPathGivenError < StandardError; end
|
10
|
+
|
11
|
+
def namespace(path, host = nil, &block)
|
12
|
+
if stub_paths.any? && stub_host != host
|
13
|
+
raise MixedNamespacesError
|
14
|
+
end
|
15
|
+
|
16
|
+
stub_paths << path
|
17
|
+
self.stub_host = host || default_host
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
stub_paths.pop
|
21
|
+
|
22
|
+
if stub_paths.empty?
|
23
|
+
self.stub_host = nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Excon::HTTP_VERBS.each do |verb|
|
28
|
+
define_method "stub_#{verb}" do |path, response = nil, &block|
|
29
|
+
validate_path_given(path)
|
30
|
+
|
31
|
+
unless path.is_a? String
|
32
|
+
response = path
|
33
|
+
path = ""
|
34
|
+
end
|
35
|
+
|
36
|
+
validate_single_response(block, response)
|
37
|
+
|
38
|
+
if block
|
39
|
+
response = block
|
40
|
+
end
|
41
|
+
|
42
|
+
path = stub_path + path
|
43
|
+
path = replace_path_params(path)
|
44
|
+
path = create_path_regexp(path)
|
45
|
+
|
46
|
+
request = { method: verb, path: path }
|
47
|
+
|
48
|
+
if stub_host || default_host
|
49
|
+
request[:host] = stub_host || default_host
|
50
|
+
end
|
51
|
+
|
52
|
+
unless response.is_a?(Proc) || (response.is_a?(Hash) && response.has_key?(:body))
|
53
|
+
response = { body: response }
|
54
|
+
end
|
55
|
+
|
56
|
+
unless SoStubVeryTest.defining_default_stubs
|
57
|
+
SoStubVeryTest.custom_stubs << [request, response]
|
58
|
+
end
|
59
|
+
|
60
|
+
Excon.stub(request, response)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class << self
|
65
|
+
attr_accessor :default_host
|
66
|
+
|
67
|
+
def clear_custom_stubs
|
68
|
+
custom_stubs.each do |stub|
|
69
|
+
Excon.stubs.delete stub
|
70
|
+
end
|
71
|
+
|
72
|
+
custom_stubs.clear
|
73
|
+
end
|
74
|
+
|
75
|
+
def custom_stubs
|
76
|
+
@custom_stubs ||= []
|
77
|
+
end
|
78
|
+
|
79
|
+
def defining_default_stubs
|
80
|
+
@defining_default_stubs ||= false
|
81
|
+
end
|
82
|
+
|
83
|
+
def register_host(name, host)
|
84
|
+
define_method "#{name}_namespace" do |path, &block|
|
85
|
+
namespace path, host, &block
|
86
|
+
end
|
87
|
+
|
88
|
+
Excon::HTTP_VERBS.each do |verb|
|
89
|
+
define_method "#{name}_stub_#{verb}" do |path, response = nil|
|
90
|
+
namespace path, host do
|
91
|
+
send "stub_#{verb}", response
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def defaults(&block)
|
98
|
+
@defining_default_stubs = true
|
99
|
+
instance_exec &block
|
100
|
+
ensure
|
101
|
+
@defining_default_stubs = false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def create_path_regexp(path)
|
108
|
+
Regexp.new '\A' + path + '\Z'
|
109
|
+
end
|
110
|
+
|
111
|
+
def default_host
|
112
|
+
SoStubVeryTest.default_host
|
113
|
+
end
|
114
|
+
|
115
|
+
def replace_path_params(path)
|
116
|
+
path.gsub /:[^\/]+/, '[^\/]+'
|
117
|
+
end
|
118
|
+
|
119
|
+
def stub_host=(host)
|
120
|
+
@stub_host = host
|
121
|
+
end
|
122
|
+
|
123
|
+
def stub_host
|
124
|
+
@stub_host
|
125
|
+
end
|
126
|
+
|
127
|
+
def stub_path
|
128
|
+
stub_paths.join
|
129
|
+
end
|
130
|
+
|
131
|
+
def stub_paths
|
132
|
+
@stub_paths ||= []
|
133
|
+
end
|
134
|
+
|
135
|
+
def validate_path_given(path)
|
136
|
+
if stub_paths.empty? && !path.is_a?(String)
|
137
|
+
raise NoPathGivenError
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def validate_single_response(block, response)
|
142
|
+
if block && response
|
143
|
+
raise AmbiguousResponseError
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'so_stub_very_test/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "so_stub_very_test"
|
8
|
+
spec.version = SoStubVeryTest::VERSION
|
9
|
+
spec.authors = ["Jonathan Clem"]
|
10
|
+
spec.email = ["jonathan@jclem.net"]
|
11
|
+
spec.summary = %q{so stub...very test...much excon...wow}
|
12
|
+
spec.description = %q{build sensible default Excon stubs...and then build more of them}
|
13
|
+
spec.homepage = "https://github.com/jclem/so_stub_very_test"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "excon", "~> 0.25", ">= 0.25.1"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestSoStubVeryTest < Minitest::Test
|
4
|
+
include SoStubVeryTest
|
5
|
+
|
6
|
+
def teardown
|
7
|
+
SoStubVeryTest.default_host = nil
|
8
|
+
SoStubVeryTest.clear_custom_stubs
|
9
|
+
Excon.stubs.clear
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_can_stub_get
|
13
|
+
stub_get "/foo", body: [true]
|
14
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, method: :get }, body: [true]]]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_can_stub_post
|
18
|
+
stub_post "/foo", body: [true]
|
19
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, method: :post }, body: [true]]]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_can_stub_put
|
23
|
+
stub_put "/foo", body: [true]
|
24
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, method: :put }, body: [true]]]
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_can_stub_patch
|
28
|
+
stub_patch "/foo", body: [true]
|
29
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, method: :patch }, body: [true]]]
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_can_stub_delete
|
33
|
+
stub_delete "/foo", body: [true]
|
34
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, method: :delete }, body: [true]]]
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_performs_param_substitution
|
38
|
+
stub_get "/foo/:bar", body: [true]
|
39
|
+
assert_equal Excon.stubs, [[{ path: Regexp.new('\A/foo/[^\/]+\Z'), method: :get }, body: [true]]]
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_can_have_default_host
|
43
|
+
SoStubVeryTest.default_host = "example.com"
|
44
|
+
stub_get "/foo", body: [true]
|
45
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, method: :get, host: "example.com" }, body: [true]]]
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_can_set_response_options
|
49
|
+
stub_get "/foo", body: [true], status: 201
|
50
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, method: :get }, body: [true], status: 201]]
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_need_not_pass_body_param
|
54
|
+
stub_get "/foo", [true]
|
55
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, method: :get }, body: [true]]]
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_can_pass_block_as_response
|
59
|
+
stub_get "/foo" do
|
60
|
+
[true]
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_equal Excon.stubs[0][0], { path: /\A\/foo\Z/, method: :get }
|
64
|
+
assert_equal Excon.stubs[0][1].call, [true]
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_raises_exception_when_given_response_and_block
|
68
|
+
assert_raises SoStubVeryTest::AmbiguousResponseError do
|
69
|
+
stub_get "/foo", "bar" do
|
70
|
+
[true]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_raises_exception_when_given_response_and_block_with_no_path
|
76
|
+
assert_raises SoStubVeryTest::AmbiguousResponseError do
|
77
|
+
namespace "/foo" do
|
78
|
+
stub_get true do
|
79
|
+
[true]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_can_use_namespaces
|
86
|
+
namespace "/foo" do
|
87
|
+
stub_get "/bar", true
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\/bar\Z/, method: :get }, { body: true }]]
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_can_nest_namespaces
|
94
|
+
namespace "/foo" do
|
95
|
+
namespace "/bar" do
|
96
|
+
stub_get "/baz", true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\/bar\/baz\Z/, method: :get }, { body: true }]]
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_can_use_no_path_when_in_namespace
|
104
|
+
namespace "/foo" do
|
105
|
+
stub_get true
|
106
|
+
end
|
107
|
+
|
108
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, method: :get }, { body: true }]]
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_raises_no_path_when_not_given_path_outside_of_namespace
|
112
|
+
assert_raises SoStubVeryTest::NoPathGivenError do
|
113
|
+
stub_get true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_clears_namespaces_each_block
|
118
|
+
namespace "/foo" do
|
119
|
+
end
|
120
|
+
|
121
|
+
namespace "/bar" do
|
122
|
+
stub_get true
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_equal Excon.stubs, [[{ path: /\A\/bar\Z/, method: :get }, { body: true }]]
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_can_define_more_namespaces
|
129
|
+
SoStubVeryTest.register_host :foo, "foo.example.com"
|
130
|
+
foo_namespace "/foo" do
|
131
|
+
stub_get true
|
132
|
+
end
|
133
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, host: "foo.example.com", method: :get }, { body: true }]]
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_new_namespaces_come_with_http_verb_methods
|
137
|
+
SoStubVeryTest.register_host :foo, "foo.example.com"
|
138
|
+
foo_stub_get "/foo", true
|
139
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, host: "foo.example.com", method: :get }, { body: true }]]
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_can_not_mismatch_namespaces
|
143
|
+
SoStubVeryTest.register_host :foo, "foo.example.com"
|
144
|
+
|
145
|
+
assert_raises SoStubVeryTest::MixedNamespacesError do
|
146
|
+
namespace "/foo" do
|
147
|
+
foo_namespace "bar" do
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_can_not_mismatch_namespaces_and_http_verb_methods
|
154
|
+
SoStubVeryTest.register_host :foo, "foo.example.com"
|
155
|
+
|
156
|
+
assert_raises SoStubVeryTest::MixedNamespacesError do
|
157
|
+
namespace "/foo" do
|
158
|
+
foo_stub_get true
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_unsets_stub_host_after_each_namespace
|
164
|
+
SoStubVeryTest.register_host :foo, "foo.example.com"
|
165
|
+
|
166
|
+
foo_namespace "/foo" do
|
167
|
+
stub_get true
|
168
|
+
end
|
169
|
+
|
170
|
+
stub_get "/bar", true
|
171
|
+
|
172
|
+
assert_equal Excon.stubs[0], [{ path: /\A\/bar\Z/, method: :get }, body: true]
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_can_have_default_stubs
|
176
|
+
SoStubVeryTest.defaults do
|
177
|
+
stub_get "/bar", true
|
178
|
+
end
|
179
|
+
|
180
|
+
assert_equal Excon.stubs, [[{ path: /\A\/bar\Z/, method: :get }, body: true]]
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_can_clear_stubs
|
184
|
+
stub_get "/bar", true
|
185
|
+
SoStubVeryTest.clear_custom_stubs
|
186
|
+
assert_empty Excon.stubs
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_does_not_clear_default_stubs
|
190
|
+
SoStubVeryTest.defaults do
|
191
|
+
stub_get "/foo", true
|
192
|
+
end
|
193
|
+
|
194
|
+
stub_get "/bar", true
|
195
|
+
SoStubVeryTest.clear_custom_stubs
|
196
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, method: :get }, body: true]]
|
197
|
+
end
|
198
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: so_stub_very_test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Clem
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.25'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.25.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.25'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.25.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.5'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.5'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
description: build sensible default Excon stubs...and then build more of them
|
62
|
+
email:
|
63
|
+
- jonathan@jclem.net
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lib/so_stub_very_test.rb
|
74
|
+
- lib/so_stub_very_test/version.rb
|
75
|
+
- so_stub_very_test.gemspec
|
76
|
+
- test/so_stub_very_test_test.rb
|
77
|
+
- test/test_helper.rb
|
78
|
+
homepage: https://github.com/jclem/so_stub_very_test
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.2.0
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: so stub...very test...much excon...wow
|
102
|
+
test_files:
|
103
|
+
- test/so_stub_very_test_test.rb
|
104
|
+
- test/test_helper.rb
|
105
|
+
has_rdoc:
|