site_prism.vcr 0.0.1
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 +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +12 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +381 -0
- data/Rakefile +1 -0
- data/TODO.md +71 -0
- data/lib/site_prism.vcr.rb +1 -0
- data/lib/site_prism_vcr/applier.rb +54 -0
- data/lib/site_prism_vcr/dsl/adjuster.rb +82 -0
- data/lib/site_prism_vcr/dsl/initial_adjuster.rb +97 -0
- data/lib/site_prism_vcr/element.rb +18 -0
- data/lib/site_prism_vcr/fixture.rb +29 -0
- data/lib/site_prism_vcr/fixtures/converter.rb +17 -0
- data/lib/site_prism_vcr/fixtures/handler.rb +31 -0
- data/lib/site_prism_vcr/fixtures/manager.rb +38 -0
- data/lib/site_prism_vcr/fixtures/modifiers/home_path.rb +27 -0
- data/lib/site_prism_vcr/fixtures/modifiers/path.rb +30 -0
- data/lib/site_prism_vcr/fixtures/tmp_keeper.rb +21 -0
- data/lib/site_prism_vcr/fixtures.rb +41 -0
- data/lib/site_prism_vcr/options.rb +22 -0
- data/lib/site_prism_vcr/options_with_path.rb +7 -0
- data/lib/site_prism_vcr/patches/element_container.rb +15 -0
- data/lib/site_prism_vcr/patches/page.rb +41 -0
- data/lib/site_prism_vcr/vcr_helpers.rb +18 -0
- data/lib/site_prism_vcr/version.rb +3 -0
- data/lib/site_prism_vcr/waiter.rb +23 -0
- data/lib/site_prism_vcr.rb +24 -0
- data/site_prism.vcr.gemspec +24 -0
- data/spec/fixtures/arya_stark.yml +44 -0
- data/spec/fixtures/custom/blank.yml +44 -0
- data/spec/fixtures/custom/bran_stark.yml +44 -0
- data/spec/fixtures/custom/daenerys_targaryen.yml +44 -0
- data/spec/fixtures/jon_snow.yml +44 -0
- data/spec/fixtures/ned_stark.yml +44 -0
- data/spec/fixtures/robb_stark.yml +44 -0
- data/spec/integration/http_interactions_on_even/click_spec.rb +75 -0
- data/spec/integration/immediate_http_interactions/page_load_on_click_spec.rb +18 -0
- data/spec/integration/immediate_http_interactions/page_load_spec.rb +56 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/spec_integration_helper.rb +27 -0
- data/spec/support/shared/integration/custom_fixtures.rb +32 -0
- data/spec/support/shared/integration/exchange.rb +42 -0
- data/spec/support/shared/integration/home_path.rb +49 -0
- data/spec/support/shared/integration/waiter.rb +75 -0
- data/spec/support/site_prism/pages/base.rb +18 -0
- data/spec/support/site_prism/pages/home.rb +44 -0
- data/spec/support/site_prism/pages/immediate_http_interactions/home_path.rb +15 -0
- data/spec/support/site_prism/pages/immediate_http_interactions/one_request.rb +13 -0
- data/spec/support/site_prism/pages/immediate_http_interactions/subpage.rb +7 -0
- data/spec/support/site_prism/pages/immediate_http_interactions/two_requests.rb +12 -0
- data/spec/support/site_prism/pages/immediate_http_interactions/waiter_without_fixtures_ejection.rb +12 -0
- data/spec/support/site_prism/sections/console_block.rb +8 -0
- data/spec/support/test_app/public/jquery.min.js +5 -0
- data/spec/support/test_app/public/test.js +44 -0
- data/spec/support/test_app/test_app.rb +46 -0
- data/spec/support/test_app/views/index.erb +26 -0
- data/spec/unit/applier_spec.rb +134 -0
- data/spec/unit/dsl/adjuster_spec.rb +141 -0
- data/spec/unit/dsl/initial_adjuster_spec.rb +166 -0
- data/spec/unit/element_container_spec.rb +48 -0
- data/spec/unit/element_spec.rb +47 -0
- data/spec/unit/fixture_spec.rb +45 -0
- data/spec/unit/fixtures/converter_spec.rb +36 -0
- data/spec/unit/fixtures/handler_spec.rb +72 -0
- data/spec/unit/fixtures/manager_spec.rb +58 -0
- data/spec/unit/fixtures/modifiers/home_path_spec.rb +47 -0
- data/spec/unit/fixtures/modifiers/path_spec.rb +45 -0
- data/spec/unit/fixtures/tmp_keeper_spec.rb +17 -0
- data/spec/unit/fixtures_spec.rb +76 -0
- data/spec/unit/options_spec.rb +41 -0
- data/spec/unit/patches/element_container_spec.rb +48 -0
- data/spec/unit/patches/page_spec.rb +57 -0
- data/spec/unit/vcr_helpers_spec.rb +18 -0
- data/spec/unit/waiter_spec.rb +67 -0
- metadata +213 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SPV::DSL::Adjuster do
|
4
|
+
let(:raw_fixtures) { 'some fixtures' }
|
5
|
+
let(:fixtures) { double }
|
6
|
+
let(:tmp_keeper) { double(fixtures: raw_fixtures, clean_fixtures: true) }
|
7
|
+
let(:options) { double(waiter: :wait_for_me) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
SPV::Fixtures::TmpKeeper.stub(:new).and_return(tmp_keeper)
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { described_class.new(options, fixtures) }
|
14
|
+
|
15
|
+
describe '#replace' do
|
16
|
+
let(:replaced_fixtures) { 'replaced fixtures' }
|
17
|
+
|
18
|
+
before do
|
19
|
+
fixtures.stub(:replace).and_return(replaced_fixtures)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'replaces fixtures' do
|
23
|
+
expect(fixtures).to receive(:replace).with(raw_fixtures)
|
24
|
+
|
25
|
+
subject.replace
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'cleans fixtures being kept in the fixtures handler' do
|
29
|
+
expect(tmp_keeper).to receive(:clean_fixtures)
|
30
|
+
|
31
|
+
subject.replace
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns a new container with fixtures' do
|
35
|
+
subject.replace
|
36
|
+
|
37
|
+
expect(subject.prepared_fixtures).to eq(replaced_fixtures)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#union' do
|
42
|
+
let(:new_fixtures) { 'new fixtures' }
|
43
|
+
|
44
|
+
before do
|
45
|
+
fixtures.stub(:union).and_return(new_fixtures)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'replaces fixtures' do
|
49
|
+
expect(fixtures).to receive(:union).with(raw_fixtures)
|
50
|
+
|
51
|
+
subject.union
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'cleans fixtures being kept in the fixtures handler' do
|
55
|
+
expect(tmp_keeper).to receive(:clean_fixtures)
|
56
|
+
|
57
|
+
subject.union
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns a new container with fixtures' do
|
61
|
+
subject.union
|
62
|
+
|
63
|
+
expect(subject.prepared_fixtures).to eq(new_fixtures)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#exchange' do
|
68
|
+
def exchange
|
69
|
+
subject.exchange(
|
70
|
+
raw_old_fixtures,
|
71
|
+
raw_new_fixtures
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
shared_examples 'when passed arguments are handled' do
|
76
|
+
it 'handles raw fixtures' do
|
77
|
+
expect(fixtures_handler).to receive(:handle_set_raws).with(
|
78
|
+
expected_raw_old_fixtures,
|
79
|
+
expected_raw_new_fixtures,
|
80
|
+
[home_path_modifier]
|
81
|
+
)
|
82
|
+
|
83
|
+
exchange
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
let(:fixtures) { double(exchange: true) }
|
88
|
+
let(:fixtures_handler) { double }
|
89
|
+
let(:home_path_modifier) { double(modify: true) }
|
90
|
+
|
91
|
+
let(:raw_old_fixtures) { ['old fixtures'] }
|
92
|
+
let(:raw_new_fixtures) { ['new fixtures'] }
|
93
|
+
|
94
|
+
let(:expected_raw_old_fixtures) { raw_old_fixtures }
|
95
|
+
let(:expected_raw_new_fixtures) { raw_new_fixtures }
|
96
|
+
|
97
|
+
let(:old_fixture) { double }
|
98
|
+
let(:new_fixture) { double }
|
99
|
+
|
100
|
+
let(:handled_old_fixtures) { [old_fixture] }
|
101
|
+
let(:handled_new_fixtures) { [new_fixture] }
|
102
|
+
|
103
|
+
before do
|
104
|
+
SPV::Fixtures::Handler.stub(:new).and_return(fixtures_handler)
|
105
|
+
SPV::Fixtures::Modifiers::HomePath.stub(:new).and_return(home_path_modifier)
|
106
|
+
|
107
|
+
fixtures_handler.stub(:handle_set_raws).and_return([
|
108
|
+
handled_old_fixtures,
|
109
|
+
handled_new_fixtures
|
110
|
+
])
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'initializes the home path modifier' do
|
114
|
+
expect(SPV::Fixtures::Modifiers::HomePath).to receive(:new).with(options)
|
115
|
+
|
116
|
+
exchange
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when no arrays are passed as arguments' do
|
120
|
+
let(:raw_old_fixtures) { {old_fixtures: 'hash with vcr options'} }
|
121
|
+
let(:raw_new_fixtures) { {new_fixtures: 'hash with vcr options'} }
|
122
|
+
|
123
|
+
let(:expected_raw_old_fixtures) { [raw_old_fixtures] }
|
124
|
+
let(:expected_raw_new_fixtures) { [raw_new_fixtures] }
|
125
|
+
|
126
|
+
it_behaves_like 'when passed arguments are handled'
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'when arrays are passed as arguments' do
|
130
|
+
it_behaves_like 'when passed arguments are handled'
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'exchanges fixtures' do
|
134
|
+
expect(fixtures).to receive(:exchange).with(
|
135
|
+
handled_old_fixtures, handled_new_fixtures
|
136
|
+
)
|
137
|
+
|
138
|
+
exchange
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SPV::DSL::InitialAdjuster do
|
4
|
+
let(:options) { double }
|
5
|
+
let(:tmp_keeper) { double(add_fixtures: true) }
|
6
|
+
let(:handled_fixtures) { double }
|
7
|
+
let(:fixtures_handler) { double(handle_raw: handled_fixtures) }
|
8
|
+
|
9
|
+
subject { described_class.new(options) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
SPV::Fixtures::TmpKeeper.stub(:new).and_return(tmp_keeper)
|
13
|
+
SPV::Fixtures::Handler.stub(:new).and_return(fixtures_handler)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.new' do
|
17
|
+
it 'initializes the fixtures tmp keeper' do
|
18
|
+
expect(SPV::Fixtures::TmpKeeper).to receive(:new).with(options)
|
19
|
+
|
20
|
+
subject
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'initializes the fixtures handler' do
|
24
|
+
expect(SPV::Fixtures::Handler).to receive(:new)
|
25
|
+
|
26
|
+
subject
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#fixtures' do
|
31
|
+
let(:raw_fixtures) { 'some fixtures' }
|
32
|
+
let(:home_path_modifier) { 'some home path modifier' }
|
33
|
+
|
34
|
+
before do
|
35
|
+
SPV::Fixtures::Modifiers::HomePath.stub(:new).and_return(home_path_modifier)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'initializes the home path modifier' do
|
39
|
+
expect(SPV::Fixtures::Modifiers::HomePath).to receive(:new).with(options)
|
40
|
+
|
41
|
+
subject.fixtures(raw_fixtures)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'handles raw fixtures' do
|
45
|
+
expect(fixtures_handler).to receive(:handle_raw).with(
|
46
|
+
raw_fixtures,
|
47
|
+
[home_path_modifier]
|
48
|
+
)
|
49
|
+
|
50
|
+
subject.fixtures(raw_fixtures)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'adds fixtures' do
|
54
|
+
expect(tmp_keeper).to receive(:add_fixtures).with(handled_fixtures)
|
55
|
+
|
56
|
+
subject.fixtures(raw_fixtures)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#home_path' do
|
61
|
+
let(:raw_home_path) { 'some home path' }
|
62
|
+
|
63
|
+
it 'defines a default home path' do
|
64
|
+
expect(options).to receive(:home_path=).with(raw_home_path)
|
65
|
+
|
66
|
+
subject.home_path(raw_home_path)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#path' do
|
71
|
+
def set_path
|
72
|
+
subject.path 'path', raw_fixtures
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:raw_fixtures) { 'some raw fixtures' }
|
76
|
+
let(:options_with_path) { double('path=' => true) }
|
77
|
+
|
78
|
+
let(:path_modifier) { double }
|
79
|
+
let(:home_path_modifier) { double }
|
80
|
+
|
81
|
+
before do
|
82
|
+
SPV::OptionsWithPath.stub(:new).and_return(options_with_path)
|
83
|
+
SPV::Fixtures::Modifiers::Path.stub(:new).and_return(path_modifier)
|
84
|
+
SPV::Fixtures::Modifiers::HomePath.stub(:new).and_return(home_path_modifier)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'initializes a new object with options' do
|
88
|
+
expect(SPV::OptionsWithPath).to receive(:new).with(options)
|
89
|
+
|
90
|
+
set_path
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'defines path to fixtures' do
|
94
|
+
expect(options_with_path).to receive(:path=).with('path')
|
95
|
+
|
96
|
+
set_path
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'initializes the modifier to modify path' do
|
100
|
+
expect(
|
101
|
+
SPV::Fixtures::Modifiers::Path
|
102
|
+
).to receive(:new).with(options_with_path)
|
103
|
+
|
104
|
+
set_path
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'initializes the modifier to set home path' do
|
108
|
+
expect(
|
109
|
+
SPV::Fixtures::Modifiers::HomePath
|
110
|
+
).to receive(:new).with(options_with_path)
|
111
|
+
|
112
|
+
set_path
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'handles raw fixtures' do
|
116
|
+
expect(fixtures_handler).to receive(:handle_raw).with(
|
117
|
+
raw_fixtures,
|
118
|
+
[
|
119
|
+
path_modifier,
|
120
|
+
home_path_modifier
|
121
|
+
]
|
122
|
+
)
|
123
|
+
|
124
|
+
set_path
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'adds fixtures into tmp keeper' do
|
128
|
+
expect(tmp_keeper).to receive(:add_fixtures).with(handled_fixtures)
|
129
|
+
|
130
|
+
set_path
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#waiter' do
|
135
|
+
let(:options) { double('waiter='.to_sym => true, 'waiter_options='.to_sym => true) }
|
136
|
+
|
137
|
+
it 'defines a new waiter' do
|
138
|
+
expect(options).to receive(:waiter=).with(kind_of(Proc))
|
139
|
+
|
140
|
+
subject.waiter { 'some waiter here' }
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'defines an options for a waiter' do
|
144
|
+
expect(options).to receive(:waiter_options=).with(eject_cassettes: false)
|
145
|
+
|
146
|
+
subject.waiter(eject_cassettes: false) { 'some waiter here' }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#prepared_fixtures' do
|
151
|
+
let(:fixtures) { double }
|
152
|
+
let(:raw_fixtures) { 'some raw fixtures' }
|
153
|
+
|
154
|
+
before do
|
155
|
+
SPV::Fixtures.stub(:new).and_return(fixtures)
|
156
|
+
|
157
|
+
tmp_keeper.stub(:fixtures).and_return(raw_fixtures)
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'initializes the fixtures handler' do
|
161
|
+
expect(SPV::Fixtures).to receive(:new).with(raw_fixtures).and_return(fixtures)
|
162
|
+
|
163
|
+
expect(subject.prepared_fixtures).to eq(fixtures)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestPageWithElement
|
4
|
+
extend SitePrism::ElementContainer
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def element(*); end
|
8
|
+
end
|
9
|
+
|
10
|
+
def el_with_options
|
11
|
+
'original element with options'
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_el; end
|
15
|
+
|
16
|
+
element_with_vcr(:el_with_options, '#selector', fixtures: 'some fixtures') {}
|
17
|
+
end
|
18
|
+
|
19
|
+
describe SitePrism::ElementContainer do
|
20
|
+
describe '.element_with_vcr' do
|
21
|
+
it 'calls the original element method with given arguments' do
|
22
|
+
expect(TestPageWithElement).to receive(:element).with(
|
23
|
+
:test_el,
|
24
|
+
'#test_selector',
|
25
|
+
visible: false
|
26
|
+
)
|
27
|
+
|
28
|
+
TestPageWithElement.instance_eval do
|
29
|
+
element_with_vcr :test_el, '#test_selector', visible: false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when a method for getting an element is called' do
|
34
|
+
let(:page) { TestPageWithElement.new }
|
35
|
+
let(:vcr_el) { 'vcr element' }
|
36
|
+
|
37
|
+
subject { page.el_with_options }
|
38
|
+
|
39
|
+
it 'initializes a new instance of an element with empty options' do
|
40
|
+
expect(SPV::Element).to receive(:new).with(
|
41
|
+
'original element with options', page
|
42
|
+
).and_return(vcr_el)
|
43
|
+
|
44
|
+
expect(subject).to eq(vcr_el)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SPV::Element do
|
4
|
+
let(:node) { stub }
|
5
|
+
let(:parent) { double }
|
6
|
+
let(:applier) { double(apply: true) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
SPV::Applier.stub(:new).and_return(applier)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.new' do
|
13
|
+
it 'initializes the fixtures applier' do
|
14
|
+
expect(SPV::Applier).to receive(:new).with(
|
15
|
+
parent
|
16
|
+
)
|
17
|
+
|
18
|
+
b1 = proc { }
|
19
|
+
|
20
|
+
described_class.new(nil, parent)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#click_and_apply_vcr' do
|
25
|
+
subject { described_class.new(nil, parent) }
|
26
|
+
|
27
|
+
before do
|
28
|
+
subject.stub(:click)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'applies custom fixtures' do
|
32
|
+
expect(applier).to receive(:apply).with(
|
33
|
+
kind_of(Proc)
|
34
|
+
)
|
35
|
+
|
36
|
+
subject.click_and_apply_vcr() {}
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'clicks on an element' do
|
40
|
+
applier.stub(:apply).and_yield
|
41
|
+
|
42
|
+
expect(subject).to receive(:click)
|
43
|
+
|
44
|
+
subject.click_and_apply_vcr
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SPV::Fixture do
|
4
|
+
describe '#add_path' do
|
5
|
+
subject { described_class.new('some name') }
|
6
|
+
|
7
|
+
it 'have added path to a name of fixture' do
|
8
|
+
subject.add_path('some path/')
|
9
|
+
|
10
|
+
expect(subject.name).to eq('some path/some name')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#set_home_path' do
|
15
|
+
subject { described_class.new('~/fixture_name') }
|
16
|
+
|
17
|
+
it 'defines a new name with replaced home path symbol' do
|
18
|
+
subject.set_home_path('my_home_path/')
|
19
|
+
|
20
|
+
expect(subject.name).to eq('my_home_path/fixture_name')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#has_link_to_home_path?' do
|
25
|
+
it 'returns true when a name of fixture starts with "~/"' do
|
26
|
+
expect(
|
27
|
+
described_class.new('~/some').has_link_to_home_path?
|
28
|
+
).to be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns true when a name of fixture does not start with "~/"' do
|
32
|
+
expect(
|
33
|
+
described_class.new('some').has_link_to_home_path?
|
34
|
+
).to be_false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#clean_name' do
|
39
|
+
subject { described_class.new('~/fixture_name') }
|
40
|
+
|
41
|
+
it 'returns a name without a home path' do
|
42
|
+
expect(subject.clean_name).to eq('fixture_name')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SPV::Fixtures::Converter do
|
4
|
+
describe '.convert_raw' do
|
5
|
+
let(:first_fixture) { 'test_fixture' }
|
6
|
+
let(:second_fixture) { {fixture: 'fixture_name', options: 'vcr options'} }
|
7
|
+
|
8
|
+
subject {
|
9
|
+
described_class.convert_raw(
|
10
|
+
[first_fixture, second_fixture]
|
11
|
+
)
|
12
|
+
}
|
13
|
+
|
14
|
+
before do
|
15
|
+
SPV::Fixture.stub(:new).and_return('first prepared', 'second prepared')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'initializes first object of Fixture class' do
|
19
|
+
expect(SPV::Fixture).to receive(:new).with(first_fixture)
|
20
|
+
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'initializes second object of Fixture class' do
|
25
|
+
expect(SPV::Fixture).to receive(:new).with(
|
26
|
+
second_fixture[:fixture], second_fixture[:options]
|
27
|
+
)
|
28
|
+
|
29
|
+
subject
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns a prepared list of fixtures' do
|
33
|
+
expect(subject).to eq(['first prepared', 'second prepared'])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SPV::Fixtures::Handler do
|
4
|
+
let(:options) { double }
|
5
|
+
let(:converted_fixtures) { [] }
|
6
|
+
let(:fixtures_converter) { SPV::Fixtures::Converter }
|
7
|
+
|
8
|
+
subject { described_class.new(options) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
SPV::Fixtures::Converter.stub(:convert_raw).and_return(converted_fixtures)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#handle_raw' do
|
15
|
+
def handle_raw
|
16
|
+
subject.handle_raw(raw_fixtures, [modifier])
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:raw_fixtures) { 'some raw fixtures' }
|
20
|
+
let(:converted_fixture) { 'converted fixture' }
|
21
|
+
let(:converted_fixtures) { [converted_fixture] }
|
22
|
+
let(:modifier) { double(modify: true) }
|
23
|
+
|
24
|
+
it 'converts raw fixtures' do
|
25
|
+
expect(fixtures_converter).to receive(:convert_raw).with(raw_fixtures)
|
26
|
+
|
27
|
+
handle_raw
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'modifies the converted fixtures' do
|
31
|
+
expect(modifier).to receive(:modify).with(converted_fixture)
|
32
|
+
|
33
|
+
handle_raw
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns handled fixtures' do
|
37
|
+
expect(handle_raw).to eq(converted_fixtures)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#handle_set_raws' do
|
42
|
+
def handle_set_raws
|
43
|
+
subject.handle_set_raws(raw_fixtures_1, raw_fixtures_2, modifiers)
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:raw_fixtures_1) { 'raw fixtures #1' }
|
47
|
+
let(:raw_fixtures_2) { 'raw fixtures #2' }
|
48
|
+
let(:handled_fixtures_1) { 'handled fixtures #1' }
|
49
|
+
let(:handled_fixtures_2) { 'handled fixtures #2' }
|
50
|
+
let(:modifiers) { 'some modifiers' }
|
51
|
+
|
52
|
+
before do
|
53
|
+
subject.stub(:handle_raw).and_return(handled_fixtures_1, handled_fixtures_2)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'handles the first set of raw fixtures' do
|
57
|
+
expect(subject).to receive(:handle_raw).with(raw_fixtures_1, modifiers)
|
58
|
+
|
59
|
+
handle_set_raws
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'handles the second set of raw fixtures' do
|
63
|
+
expect(subject).to receive(:handle_raw).with(raw_fixtures_2, modifiers)
|
64
|
+
|
65
|
+
handle_set_raws
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns all handled fixtures' do
|
69
|
+
expect(handle_set_raws).to eq([handled_fixtures_1, handled_fixtures_2])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SPV::Fixtures::Manager do
|
4
|
+
let(:options) { double(fixtures: ['some fixture']) }
|
5
|
+
|
6
|
+
describe '#inject' do
|
7
|
+
let(:fixture1) { double(name: 'arya_stark', options: {erb: {testvar: true}}) }
|
8
|
+
let(:fixture2) { double(name: 'jon_snow', options: {}) }
|
9
|
+
let(:fixtures) { [fixture1, fixture2] }
|
10
|
+
|
11
|
+
subject(:manager) { described_class.new(options) }
|
12
|
+
|
13
|
+
context 'when there are fixtures' do
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
VCR.eject_cassette
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'VCR holds the first fixture' do
|
20
|
+
manager.inject(fixtures)
|
21
|
+
|
22
|
+
VCR.eject_cassette
|
23
|
+
fixture = VCR.eject_cassette
|
24
|
+
|
25
|
+
expect(fixture.name).to eq('arya_stark')
|
26
|
+
expect(fixture.erb).to eq({testvar: true})
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'VCR holds the second fixture' do
|
30
|
+
manager.inject(fixtures)
|
31
|
+
|
32
|
+
fixture = VCR.eject_cassette
|
33
|
+
|
34
|
+
expect(fixture.name).to eq('jon_snow')
|
35
|
+
expect(fixture.erb).to be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when there are not any fixtures' do
|
40
|
+
it 'raises an error about no fixtures' do
|
41
|
+
expect { manager.inject([]) }.to raise_error(
|
42
|
+
ArgumentError,
|
43
|
+
'No fixtures were specified to insert them into VCR'
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#eject' do
|
50
|
+
subject { described_class.new(options).eject }
|
51
|
+
|
52
|
+
it 'ejects all fixtures from VCR' do
|
53
|
+
expect(SPV::Helpers).to receive(:eject_all_cassettes)
|
54
|
+
|
55
|
+
subject
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SPV::Fixtures::Modifiers::HomePath do
|
4
|
+
describe '#modify' do
|
5
|
+
let(:path) { 'some home path' }
|
6
|
+
let(:options) { double(home_path: path) }
|
7
|
+
let(:fixture) { double(name: 'test_with_home_path', :has_link_to_home_path? => true) }
|
8
|
+
|
9
|
+
subject { described_class.new(options).modify(fixture) }
|
10
|
+
|
11
|
+
context 'when a name of the fixture has a link to the home path' do
|
12
|
+
context 'when the home_path is defined' do
|
13
|
+
it 'writes a proper path to the fixture' do
|
14
|
+
expect(fixture).to receive(:set_home_path).with(path)
|
15
|
+
|
16
|
+
subject
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when the home_path is not defined' do
|
21
|
+
before do
|
22
|
+
options.stub(:home_path).and_return(nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'raises an argument error about wrong way of defining fixtures' do
|
26
|
+
msg = 'You are trying to use a home path for test_with_home_path fixture. ' \
|
27
|
+
'Home path cannot be used since it is not defined, please refer to the documentation ' \
|
28
|
+
'to make sure you define the home path properly.'
|
29
|
+
|
30
|
+
expect { subject }.to raise_error(
|
31
|
+
ArgumentError, msg
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when a name of the fixture has no link to the home path' do
|
38
|
+
let(:fixture) { double(:has_link_to_home_path? => false) }
|
39
|
+
|
40
|
+
it 'does not set any home path' do
|
41
|
+
expect(fixture).to_not receive(:set_home_path)
|
42
|
+
|
43
|
+
subject
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|