fixturama 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +2 -0
- data/lib/fixturama/changes/chain/raise_action.rb +13 -5
- data/lib/fixturama/version.rb +3 -0
- metadata +29 -38
- data/.gitignore +0 -12
- data/.rspec +0 -2
- data/.rubocop.yml +0 -22
- data/.travis.yml +0 -17
- data/Gemfile +0 -9
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -6
- data/fixturama.gemspec +0 -24
- data/spec/fixturama/load_fixture/_spec.rb +0 -53
- data/spec/fixturama/load_fixture/data.json +0 -5
- data/spec/fixturama/load_fixture/data.yaml +0 -3
- data/spec/fixturama/load_fixture/data.yml +0 -3
- data/spec/fixturama/seed_fixture/_spec.rb +0 -37
- data/spec/fixturama/seed_fixture/seed.yml +0 -11
- data/spec/fixturama/stub_fixture/_spec.rb +0 -120
- data/spec/fixturama/stub_fixture/stub.yml +0 -73
- data/spec/spec_helper.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 206c66b417306ab1f47517bbbac4fd0bbd3a713fb03a9ab6e01686010c23c9cc
|
4
|
+
data.tar.gz: 1bc6e5c7f657a7807c724cc5d36cb033da83ee24fc13aa61c01dfcc1d489476e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 155ac458d289214601ef8162bdc743d875855d094cd783fc79c67a5a0403ece59d4e3a9073245f915e793091be109f7f6f33840cab22c95aee320b88e796efae
|
7
|
+
data.tar.gz: b8d70001291a4b3f30c076c0ec11d57e5401f9527b384426ae41e9db8e91d025baf0db92bb1101dce63cb94975b781bf279ec11ea0bfc568c0cf7332ccdbe0cc
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
+
## [0.3.0] - [2020-03-08]
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Support for exception arguments (nepalez)
|
13
|
+
|
14
|
+
```yaml
|
15
|
+
---
|
16
|
+
- class: API
|
17
|
+
chain: get_product
|
18
|
+
arguments:
|
19
|
+
- 1
|
20
|
+
actions:
|
21
|
+
- raise: API::NotFoundError
|
22
|
+
arguments: # <--- that's that
|
23
|
+
- "Cannot find a product by id: 1"
|
24
|
+
```
|
25
|
+
|
26
|
+
which would raise `API::NotFoundError.new("Cannot find a product by id: 1")`
|
27
|
+
|
8
28
|
## [0.2.0] - [2020-02-17]
|
9
29
|
|
10
30
|
### Added
|
@@ -229,3 +249,4 @@ This is a first public release with features extracted from production app.
|
|
229
249
|
[0.0.7]: https://github.com/nepalez/fixturama/compare/v0.0.6...v0.0.7
|
230
250
|
[0.1.0]: https://github.com/nepalez/fixturama/compare/v0.0.7...v0.1.0
|
231
251
|
[0.2.0]: https://github.com/nepalez/fixturama/compare/v0.1.0...v0.2.0
|
252
|
+
[0.3.0]: https://github.com/nepalez/fixturama/compare/v0.2.0...v0.3.0
|
data/README.md
CHANGED
@@ -15,16 +15,24 @@ class Fixturama::Changes::Chain
|
|
15
15
|
def initialize(**options)
|
16
16
|
@error = error_from options
|
17
17
|
@repeat = repeat_from options
|
18
|
+
rescue StandardError => err
|
19
|
+
raise Fixturama::FixtureError.new("an exception class", options, err)
|
18
20
|
end
|
19
21
|
|
20
22
|
def error_from(options)
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
klass = klass_from(options)
|
24
|
+
params = options[:arguments]
|
25
|
+
params.is_a?(Array) ? klass.new(*params) : klass
|
26
|
+
end
|
27
|
+
|
28
|
+
def klass_from(options)
|
29
|
+
klass = case value = options[:raise]
|
30
|
+
when NilClass, TrueClass, "true" then StandardError
|
31
|
+
when Class then value
|
24
32
|
else Kernel.const_get(value)
|
25
33
|
end
|
26
|
-
|
27
|
-
raise
|
34
|
+
|
35
|
+
klass < Exception ? klass : raise("#{klass} is not an exception")
|
28
36
|
end
|
29
37
|
|
30
38
|
def repeat_from(options)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixturama
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin (nepalez)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot
|
@@ -72,43 +72,47 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '13.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '13.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec-its
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '1.
|
89
|
+
version: '1.3'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '1.
|
96
|
+
version: '1.3'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
103
|
+
version: '0.80'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
111
|
-
description:
|
110
|
+
version: '0.80'
|
111
|
+
description: |
|
112
|
+
Use fixtures to extract verbosity from RSpec specifications:
|
113
|
+
- load data,
|
114
|
+
- stub classes, modules and constants,
|
115
|
+
- seed the database via FactoryBot.
|
112
116
|
email: andrew.kozin@gmail.com
|
113
117
|
executables: []
|
114
118
|
extensions: []
|
@@ -116,16 +120,8 @@ extra_rdoc_files:
|
|
116
120
|
- README.md
|
117
121
|
- CHANGELOG.md
|
118
122
|
files:
|
119
|
-
- ".gitignore"
|
120
|
-
- ".rspec"
|
121
|
-
- ".rubocop.yml"
|
122
|
-
- ".travis.yml"
|
123
123
|
- CHANGELOG.md
|
124
|
-
- Gemfile
|
125
|
-
- LICENSE.txt
|
126
124
|
- README.md
|
127
|
-
- Rakefile
|
128
|
-
- fixturama.gemspec
|
129
125
|
- lib/fixturama.rb
|
130
126
|
- lib/fixturama/changes.rb
|
131
127
|
- lib/fixturama/changes/base.rb
|
@@ -145,21 +141,25 @@ files:
|
|
145
141
|
- lib/fixturama/loader/context.rb
|
146
142
|
- lib/fixturama/loader/value.rb
|
147
143
|
- lib/fixturama/rspec.rb
|
148
|
-
-
|
149
|
-
- spec/fixturama/load_fixture/data.json
|
150
|
-
- spec/fixturama/load_fixture/data.yaml
|
151
|
-
- spec/fixturama/load_fixture/data.yml
|
152
|
-
- spec/fixturama/seed_fixture/_spec.rb
|
153
|
-
- spec/fixturama/seed_fixture/seed.yml
|
154
|
-
- spec/fixturama/stub_fixture/_spec.rb
|
155
|
-
- spec/fixturama/stub_fixture/stub.yml
|
156
|
-
- spec/spec_helper.rb
|
144
|
+
- lib/fixturama/version.rb
|
157
145
|
homepage: https://github.com/nepalez/fixturama
|
158
146
|
licenses:
|
159
147
|
- MIT
|
160
|
-
metadata:
|
148
|
+
metadata:
|
149
|
+
bug_tracker_uri: https://github.com/nepalez/fixturama/issues
|
150
|
+
changelog_uri: https://github.com/nepalez/fixturama/blob/master/CHANGELOG.md
|
151
|
+
documentation_uri: https://www.rubydocs.info/gems/fixturama
|
152
|
+
homepage_uri: https://github.com/nepalez/fixturama
|
153
|
+
source_code_uri: https://github.com/nepalez/fixturama
|
161
154
|
post_install_message:
|
162
|
-
rdoc_options:
|
155
|
+
rdoc_options:
|
156
|
+
- "--title"
|
157
|
+
- Fixturama - fixtures on steroids
|
158
|
+
- "--main"
|
159
|
+
- README.md
|
160
|
+
- "--line-numbers"
|
161
|
+
- "--inline-source"
|
162
|
+
- "--quiet"
|
163
163
|
require_paths:
|
164
164
|
- lib
|
165
165
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -177,13 +177,4 @@ rubygems_version: 3.0.6
|
|
177
177
|
signing_key:
|
178
178
|
specification_version: 4
|
179
179
|
summary: A set of helpers to prettify specs with fixtures
|
180
|
-
test_files:
|
181
|
-
- spec/fixturama/load_fixture/_spec.rb
|
182
|
-
- spec/fixturama/load_fixture/data.json
|
183
|
-
- spec/fixturama/load_fixture/data.yaml
|
184
|
-
- spec/fixturama/load_fixture/data.yml
|
185
|
-
- spec/fixturama/seed_fixture/_spec.rb
|
186
|
-
- spec/fixturama/seed_fixture/seed.yml
|
187
|
-
- spec/fixturama/stub_fixture/_spec.rb
|
188
|
-
- spec/fixturama/stub_fixture/stub.yml
|
189
|
-
- spec/spec_helper.rb
|
180
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
---
|
2
|
-
AllCops:
|
3
|
-
DisplayCopNames: true
|
4
|
-
DisplayStyleGuide: true
|
5
|
-
StyleGuideCopsOnly: true
|
6
|
-
TargetRubyVersion: 2.3
|
7
|
-
|
8
|
-
Layout/LineLength:
|
9
|
-
AllowHeredoc: true
|
10
|
-
AllowURI: true
|
11
|
-
URISchemes:
|
12
|
-
- http
|
13
|
-
- https
|
14
|
-
|
15
|
-
Style/ClassAndModuleChildren:
|
16
|
-
Enabled: false
|
17
|
-
|
18
|
-
Style/Documentation:
|
19
|
-
Enabled: false
|
20
|
-
|
21
|
-
Style/StringLiterals:
|
22
|
-
EnforcedStyle: double_quotes
|
data/.travis.yml
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sudo: false
|
3
|
-
language: ruby
|
4
|
-
cache: bundler
|
5
|
-
before_install:
|
6
|
-
- gem install bundler --no-document
|
7
|
-
- gem update --system
|
8
|
-
script:
|
9
|
-
- bundle exec rspec
|
10
|
-
- bundle exec rubocop
|
11
|
-
rvm:
|
12
|
-
- 2.3.0
|
13
|
-
- 2.7.0
|
14
|
-
- ruby-head
|
15
|
-
matrix:
|
16
|
-
allow_failures:
|
17
|
-
- rvm: ruby-head
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2019 Andrew Kozin (aka nepalez)
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
data/fixturama.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |gem|
|
2
|
-
gem.name = "fixturama"
|
3
|
-
gem.version = "0.2.0"
|
4
|
-
gem.author = "Andrew Kozin (nepalez)"
|
5
|
-
gem.email = "andrew.kozin@gmail.com"
|
6
|
-
gem.homepage = "https://github.com/nepalez/fixturama"
|
7
|
-
gem.summary = "A set of helpers to prettify specs with fixtures"
|
8
|
-
gem.license = "MIT"
|
9
|
-
|
10
|
-
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
11
|
-
gem.test_files = gem.files.grep(/^spec/)
|
12
|
-
gem.extra_rdoc_files = Dir["README.md", "LICENSE", "CHANGELOG.md"]
|
13
|
-
|
14
|
-
gem.required_ruby_version = ">= 2.2"
|
15
|
-
|
16
|
-
gem.add_runtime_dependency "factory_bot", "~> 4.0"
|
17
|
-
gem.add_runtime_dependency "rspec", "~> 3.0"
|
18
|
-
gem.add_runtime_dependency "hashie", "~> 3.0"
|
19
|
-
gem.add_runtime_dependency "webmock", "~> 3.0"
|
20
|
-
|
21
|
-
gem.add_development_dependency "rake", "~> 10"
|
22
|
-
gem.add_development_dependency "rspec-its", "~> 1.0"
|
23
|
-
gem.add_development_dependency "rubocop", "~> 0.49"
|
24
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
RSpec.describe "load_fixture" do
|
2
|
-
let(:expected) { { "foo" => { "bar" => 42 } } }
|
3
|
-
|
4
|
-
context "YAML" do
|
5
|
-
subject { load_fixture("#{__dir__}/data.yaml", id: 42) }
|
6
|
-
|
7
|
-
it { is_expected.to eq expected }
|
8
|
-
end
|
9
|
-
|
10
|
-
context "YML" do
|
11
|
-
subject { load_fixture("#{__dir__}/data.yml", id: 42) }
|
12
|
-
|
13
|
-
it { is_expected.to eq expected }
|
14
|
-
end
|
15
|
-
|
16
|
-
context "YAML with ruby object" do
|
17
|
-
subject { load_fixture("#{__dir__}/data.yaml", id: foobar) }
|
18
|
-
|
19
|
-
before { class Test::Foobar; end }
|
20
|
-
|
21
|
-
let(:foobar) { Test::Foobar.new }
|
22
|
-
let(:expected) { { "foo" => { "bar" => foobar } } }
|
23
|
-
|
24
|
-
it { is_expected.to eq expected }
|
25
|
-
end
|
26
|
-
|
27
|
-
context "JSON" do
|
28
|
-
subject { load_fixture("#{__dir__}/data.json", id: 42) }
|
29
|
-
|
30
|
-
it { is_expected.to eq expected }
|
31
|
-
end
|
32
|
-
|
33
|
-
context "JSON with ruby object" do
|
34
|
-
subject { load_fixture("#{__dir__}/data.json", id: foobar) }
|
35
|
-
|
36
|
-
before { class Test::Foobar; end }
|
37
|
-
|
38
|
-
let(:foobar) { Test::Foobar.new }
|
39
|
-
let(:expected) { { "foo" => { "bar" => foobar } } }
|
40
|
-
|
41
|
-
it { is_expected.to eq expected }
|
42
|
-
end
|
43
|
-
|
44
|
-
context "with RSpec argument matchers" do
|
45
|
-
subject { load_fixture("#{__dir__}/data.yaml", id: kind_of(Numeric)) }
|
46
|
-
|
47
|
-
it "loads the matcher", aggregate_failures: true do
|
48
|
-
expect("foo" => { "bar" => 42 }).to include subject
|
49
|
-
expect("foo" => { "bar" => 99 }).to include subject
|
50
|
-
expect("foo" => { "bar" => :a }).not_to include subject
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
RSpec.describe "seed_fixture" do
|
2
|
-
subject { seed_fixture "#{__dir__}/seed.yml" }
|
3
|
-
|
4
|
-
before do
|
5
|
-
FactoryBot.define do
|
6
|
-
factory :foo, class: Hash do
|
7
|
-
transient do
|
8
|
-
bar { 0 }
|
9
|
-
baz { 0 }
|
10
|
-
qux { 0 }
|
11
|
-
end
|
12
|
-
|
13
|
-
trait :bar do
|
14
|
-
bar { 99 }
|
15
|
-
end
|
16
|
-
|
17
|
-
trait :baz do
|
18
|
-
baz { 77 }
|
19
|
-
end
|
20
|
-
|
21
|
-
skip_create
|
22
|
-
initialize_with { { bar: bar, baz: baz, qux: qux } }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
it "runs the factory", aggregate_failures: true do
|
28
|
-
expect(FactoryBot).to receive(:create_list).with(:foo, 1, :baz, qux: 42)
|
29
|
-
|
30
|
-
expect(FactoryBot).to receive(:create_list) do |*args, **opts|
|
31
|
-
expect(args).to eq [:foo, 3, :bar]
|
32
|
-
expect(opts).to be_empty
|
33
|
-
end
|
34
|
-
|
35
|
-
subject
|
36
|
-
end
|
37
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
RSpec.describe "stub_fixture" do
|
2
|
-
subject { arguments.map { |argument| Payment.new.pay(argument) } }
|
3
|
-
|
4
|
-
before do
|
5
|
-
class Payment
|
6
|
-
def pay(_)
|
7
|
-
5
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context "without stubbing" do
|
13
|
-
let(:arguments) { [0] }
|
14
|
-
|
15
|
-
it { is_expected.to eq [5] }
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when message chain stubbed" do
|
19
|
-
before { stub_fixture "#{__dir__}/stub.yml" }
|
20
|
-
|
21
|
-
context "with a :raise option" do
|
22
|
-
let(:arguments) { [0] }
|
23
|
-
|
24
|
-
it "raises an exception" do
|
25
|
-
expect { subject }.to raise_error ArgumentError
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "with a :return option" do
|
30
|
-
let(:arguments) { [1] }
|
31
|
-
|
32
|
-
it "returns stubbed value" do
|
33
|
-
expect(subject).to eq [8]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "with several actions" do
|
38
|
-
let(:arguments) { [2] * 4 }
|
39
|
-
|
40
|
-
it "calls the consecutive actions and then repeates the last one" do
|
41
|
-
expect(subject).to eq [4, 2, 0, 0]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "with multi-count actions" do
|
46
|
-
let(:arguments) { [3] * 4 }
|
47
|
-
|
48
|
-
it "repeats the action a specified number of times" do
|
49
|
-
expect(subject).to eq [6, 6, 0, 0]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "with several arguments" do
|
54
|
-
let(:arguments) { [2, 3, 2, 3, 2, 3] }
|
55
|
-
|
56
|
-
it "counts actions for every stub in isolation from the others" do
|
57
|
-
expect(subject).to eq [4, 6, 2, 6, 0, 0]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "with partially defined options" do
|
62
|
-
subject { Payment.new.pay(10, overdraft: true, notiy: true) }
|
63
|
-
|
64
|
-
it "uses the stub" do
|
65
|
-
expect(subject).to eq(-5)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when options differ" do
|
70
|
-
subject { Payment.new.pay(10, overdraft: false) }
|
71
|
-
|
72
|
-
it "uses universal stub" do
|
73
|
-
expect(subject).to eq(-1)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "with unspecified argument" do
|
78
|
-
let(:arguments) { [4] }
|
79
|
-
|
80
|
-
it "uses universal stub" do
|
81
|
-
expect(subject).to eq [-1]
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when constant stubbed" do
|
87
|
-
before do
|
88
|
-
TIMEOUT = 20
|
89
|
-
stub_fixture "#{__dir__}/stub.yml"
|
90
|
-
end
|
91
|
-
|
92
|
-
it "stubs the constant" do
|
93
|
-
expect(TIMEOUT).to eq 10
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "when http request stubbed" do
|
98
|
-
before { stub_fixture "#{__dir__}/stub.yml" }
|
99
|
-
|
100
|
-
it "stubs the request properly" do
|
101
|
-
req = Net::HTTP::Get.new("/foo")
|
102
|
-
res = Net::HTTP.start("www.example.com") { |http| http.request(req) }
|
103
|
-
|
104
|
-
expect(res.code).to eq "200"
|
105
|
-
expect(res.body).to eq "foo"
|
106
|
-
expect(res["Content-Length"]).to eq "3"
|
107
|
-
end
|
108
|
-
|
109
|
-
def delete_request
|
110
|
-
req = Net::HTTP::Delete.new("/foo")
|
111
|
-
Net::HTTP.start("www.example.com") { |http| http.request(req) }
|
112
|
-
end
|
113
|
-
|
114
|
-
it "stubs repetitive requests properly" do
|
115
|
-
expect(delete_request.code).to eq "200"
|
116
|
-
expect(delete_request.code).to eq "404"
|
117
|
-
expect(delete_request.code).to eq "404"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
---
|
2
|
-
- class: Payment
|
3
|
-
chain:
|
4
|
-
- new
|
5
|
-
- pay
|
6
|
-
actions:
|
7
|
-
- return: -1
|
8
|
-
|
9
|
-
- class: Payment
|
10
|
-
chain:
|
11
|
-
- new
|
12
|
-
- pay
|
13
|
-
arguments:
|
14
|
-
- 0
|
15
|
-
actions:
|
16
|
-
- raise: ArgumentError
|
17
|
-
|
18
|
-
- class: Payment
|
19
|
-
chain:
|
20
|
-
- new
|
21
|
-
- pay
|
22
|
-
arguments:
|
23
|
-
- 1
|
24
|
-
actions:
|
25
|
-
- return: 8
|
26
|
-
|
27
|
-
- class: Payment
|
28
|
-
chain:
|
29
|
-
- new
|
30
|
-
- pay
|
31
|
-
arguments:
|
32
|
-
- 2
|
33
|
-
actions:
|
34
|
-
- return: 4
|
35
|
-
- return: 2
|
36
|
-
- return: 0
|
37
|
-
|
38
|
-
- object: Payment.itself
|
39
|
-
chain:
|
40
|
-
- new
|
41
|
-
- pay
|
42
|
-
arguments:
|
43
|
-
- 3
|
44
|
-
actions:
|
45
|
-
- return: 6
|
46
|
-
repeat: 2
|
47
|
-
- return: 0
|
48
|
-
|
49
|
-
- class: Payment
|
50
|
-
chain:
|
51
|
-
- new
|
52
|
-
- pay
|
53
|
-
arguments:
|
54
|
-
- 10
|
55
|
-
- :overdraft: true
|
56
|
-
actions:
|
57
|
-
- return: -5
|
58
|
-
|
59
|
-
- const: TIMEOUT
|
60
|
-
value: 10
|
61
|
-
|
62
|
-
- method: get
|
63
|
-
uri: www.example.com/foo
|
64
|
-
responses:
|
65
|
-
- body: foo
|
66
|
-
headers:
|
67
|
-
Content-Length: 3
|
68
|
-
|
69
|
-
- method: delete
|
70
|
-
uri: /example.com/foo/ # Regexp!
|
71
|
-
responses:
|
72
|
-
- status: 200
|
73
|
-
- status: 404 # for any request except for the first one
|
data/spec/spec_helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require "pry"
|
3
|
-
rescue LoadError
|
4
|
-
nil
|
5
|
-
end
|
6
|
-
|
7
|
-
require "bundler/setup"
|
8
|
-
require "fixturama/rspec"
|
9
|
-
|
10
|
-
RSpec.configure do |config|
|
11
|
-
# Enable flags like --only-failures and --next-failure
|
12
|
-
config.example_status_persistence_file_path = ".rspec_status"
|
13
|
-
|
14
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
15
|
-
config.disable_monkey_patching!
|
16
|
-
|
17
|
-
config.expect_with :rspec do |c|
|
18
|
-
c.syntax = :expect
|
19
|
-
end
|
20
|
-
|
21
|
-
config.around do |example|
|
22
|
-
module Test; end
|
23
|
-
example.run
|
24
|
-
Object.send(:remove_const, :Test)
|
25
|
-
end
|
26
|
-
end
|