site_prism.vcr 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -13
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +78 -0
  4. data/Gemfile +2 -0
  5. data/README.md +61 -24
  6. data/TODO.md +28 -40
  7. data/lib/site_prism_vcr/applier.rb +20 -6
  8. data/lib/site_prism_vcr/dsl/adjuster.rb +40 -19
  9. data/lib/site_prism_vcr/dsl/initial_adjuster.rb +1 -1
  10. data/lib/site_prism_vcr/element.rb +8 -5
  11. data/lib/site_prism_vcr/fixture.rb +0 -1
  12. data/lib/site_prism_vcr/options.rb +12 -1
  13. data/lib/site_prism_vcr/patches/element_container.rb +4 -0
  14. data/lib/site_prism_vcr/patches/page.rb +25 -27
  15. data/lib/site_prism_vcr/version.rb +1 -1
  16. data/site_prism.vcr.gemspec +2 -2
  17. data/spec/integration/elements/apply_spec.rb +100 -0
  18. data/spec/integration/elements/events/click_spec.rb +20 -0
  19. data/spec/integration/{immediate_http_interactions/page_load_on_click_spec.rb → pages/custom_event_spec.rb} +5 -3
  20. data/spec/integration/{immediate_http_interactions/page_load_spec.rb → pages/load_spec.rb} +13 -9
  21. data/spec/spec_helper.rb +3 -0
  22. data/spec/support/shared/integration/custom_fixtures.rb +17 -0
  23. data/spec/support/shared/integration/exchange.rb +1 -1
  24. data/spec/support/shared/integration/home_path.rb +1 -1
  25. data/spec/support/shared/integration/waiter.rb +37 -25
  26. data/spec/support/site_prism/pages/home.rb +7 -0
  27. data/spec/support/site_prism/pages/{immediate_http_interactions → page_load}/home_path.rb +1 -1
  28. data/spec/support/site_prism/pages/{immediate_http_interactions → page_load}/one_request.rb +1 -1
  29. data/spec/support/site_prism/pages/{immediate_http_interactions → page_load}/subpage.rb +1 -1
  30. data/spec/support/site_prism/pages/{immediate_http_interactions → page_load}/two_requests.rb +1 -1
  31. data/spec/support/site_prism/pages/{immediate_http_interactions → page_load}/waiter_without_fixtures_ejection.rb +1 -1
  32. data/spec/unit/applier_spec.rb +74 -56
  33. data/spec/unit/dsl/adjuster_spec.rb +58 -47
  34. data/spec/unit/dsl/initial_adjuster_spec.rb +18 -12
  35. data/spec/unit/element_spec.rb +11 -13
  36. data/spec/unit/fixtures/handler_spec.rb +7 -2
  37. data/spec/unit/fixtures/manager_spec.rb +20 -4
  38. data/spec/unit/fixtures/modifiers/home_path_spec.rb +14 -3
  39. data/spec/unit/fixtures/modifiers/path_spec.rb +9 -3
  40. data/spec/unit/fixtures/tmp_keeper_spec.rb +1 -1
  41. data/spec/unit/fixtures_spec.rb +5 -5
  42. data/spec/unit/options_spec.rb +35 -1
  43. data/spec/unit/patches/element_container_spec.rb +25 -12
  44. data/spec/unit/patches/page_spec.rb +23 -30
  45. data/spec/unit/waiter_spec.rb +16 -4
  46. metadata +30 -30
  47. data/spec/integration/http_interactions_on_even/click_spec.rb +0 -75
  48. data/spec/unit/element_container_spec.rb +0 -48
@@ -1,10 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
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) }
4
+ let(:raw_fixtures) { 'some fixtures' }
5
+ let(:fixtures) { instance_double('SPV::Fixtures', exchange: true) }
6
+ let(:tmp_keeper) {
7
+ instance_double(
8
+ 'SPV::Fixtures::TmpKeeper',
9
+ {fixtures: raw_fixtures, clean_fixtures: true}
10
+ )
11
+ }
12
+
13
+ let(:options) {
14
+ instance_double(
15
+ 'SPV::Options',
16
+ waiter: :wait_for_me,
17
+ merge_waiter_options!: nil
18
+ )
19
+ }
8
20
 
9
21
  before do
10
22
  SPV::Fixtures::TmpKeeper.stub(:new).and_return(tmp_keeper)
@@ -12,55 +24,50 @@ describe SPV::DSL::Adjuster do
12
24
 
13
25
  subject { described_class.new(options, fixtures) }
14
26
 
15
- describe '#replace' do
16
- let(:replaced_fixtures) { 'replaced fixtures' }
27
+ describe '#prepare_fixtures' do
28
+ context 'when the replace action is defined' do
29
+ let(:replaced_fixtures) { 'replaced fixtures' }
17
30
 
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
31
+ before do
32
+ fixtures.stub(:replace).and_return(replaced_fixtures)
27
33
 
28
- it 'cleans fixtures being kept in the fixtures handler' do
29
- expect(tmp_keeper).to receive(:clean_fixtures)
34
+ subject.replace
35
+ end
30
36
 
31
- subject.replace
32
- end
37
+ it 'replaces fixtures' do
38
+ expect(fixtures).to receive(:replace).with(raw_fixtures)
33
39
 
34
- it 'returns a new container with fixtures' do
35
- subject.replace
40
+ subject.prepare_fixtures
41
+ end
36
42
 
37
- expect(subject.prepared_fixtures).to eq(replaced_fixtures)
43
+ it 'returns a new container with fixtures' do
44
+ expect(subject.prepare_fixtures).to eq(replaced_fixtures)
45
+ end
38
46
  end
39
- end
40
-
41
- describe '#union' do
42
- let(:new_fixtures) { 'new fixtures' }
43
47
 
44
- before do
45
- fixtures.stub(:union).and_return(new_fixtures)
46
- end
48
+ context 'when the union action is defined' do
49
+ let(:new_fixtures) { 'new fixtures' }
47
50
 
48
- it 'replaces fixtures' do
49
- expect(fixtures).to receive(:union).with(raw_fixtures)
51
+ before do
52
+ fixtures.stub(:union).and_return(new_fixtures)
53
+ subject.union
54
+ end
50
55
 
51
- subject.union
52
- end
56
+ it 'joins fixtures' do
57
+ expect(fixtures).to receive(:union).with(raw_fixtures)
53
58
 
54
- it 'cleans fixtures being kept in the fixtures handler' do
55
- expect(tmp_keeper).to receive(:clean_fixtures)
59
+ subject.prepare_fixtures
60
+ end
56
61
 
57
- subject.union
62
+ it 'returns a new container with fixtures' do
63
+ expect(subject.prepare_fixtures).to eq(new_fixtures)
64
+ end
58
65
  end
59
66
 
60
- it 'returns a new container with fixtures' do
61
- subject.union
67
+ it 'the replace action is used as a default' do
68
+ expect(fixtures).to receive(:replace).with(raw_fixtures)
62
69
 
63
- expect(subject.prepared_fixtures).to eq(new_fixtures)
70
+ subject.prepare_fixtures
64
71
  end
65
72
  end
66
73
 
@@ -84,9 +91,8 @@ describe SPV::DSL::Adjuster do
84
91
  end
85
92
  end
86
93
 
87
- let(:fixtures) { double(exchange: true) }
88
- let(:fixtures_handler) { double }
89
- let(:home_path_modifier) { double(modify: true) }
94
+ let(:fixtures_handler) { instance_double('SPV::Fixtures::Handler') }
95
+ let(:home_path_modifier) { double('home path modifier') }
90
96
 
91
97
  let(:raw_old_fixtures) { ['old fixtures'] }
92
98
  let(:raw_new_fixtures) { ['new fixtures'] }
@@ -94,11 +100,8 @@ describe SPV::DSL::Adjuster do
94
100
  let(:expected_raw_old_fixtures) { raw_old_fixtures }
95
101
  let(:expected_raw_new_fixtures) { raw_new_fixtures }
96
102
 
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] }
103
+ let(:handled_old_fixtures) { ['old fixture'] }
104
+ let(:handled_new_fixtures) { ['old fixture'] }
102
105
 
103
106
  before do
104
107
  SPV::Fixtures::Handler.stub(:new).and_return(fixtures_handler)
@@ -138,4 +141,12 @@ describe SPV::DSL::Adjuster do
138
141
  exchange
139
142
  end
140
143
  end
144
+
145
+ describe '#waiter_options' do
146
+ it 'merges default waiter options with a given' do
147
+ expect(options).to receive(:merge_waiter_options!).with(my: 'options')
148
+
149
+ subject.waiter_options(my: 'options')
150
+ end
151
+ end
141
152
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
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) }
4
+ let(:options) { instance_double('SPV::Options') }
5
+ let(:tmp_keeper) { instance_double('SPV::Fixtures::TmpKeeper', add_fixtures: true) }
6
+ let(:handled_fixtures) { 'handled fixtures' }
7
+ let(:fixtures_handler) { instance_double('SPV::Fixtures::Handler', handle_raw: handled_fixtures) }
8
8
 
9
9
  subject { described_class.new(options) }
10
10
 
@@ -29,7 +29,7 @@ describe SPV::DSL::InitialAdjuster do
29
29
 
30
30
  describe '#fixtures' do
31
31
  let(:raw_fixtures) { 'some fixtures' }
32
- let(:home_path_modifier) { 'some home path modifier' }
32
+ let(:home_path_modifier) { double('home path modifier') }
33
33
 
34
34
  before do
35
35
  SPV::Fixtures::Modifiers::HomePath.stub(:new).and_return(home_path_modifier)
@@ -73,10 +73,10 @@ describe SPV::DSL::InitialAdjuster do
73
73
  end
74
74
 
75
75
  let(:raw_fixtures) { 'some raw fixtures' }
76
- let(:options_with_path) { double('path=' => true) }
76
+ let(:options_with_path) { instance_double('SPV::OptionsWithPath', 'path=' => true) }
77
77
 
78
- let(:path_modifier) { double }
79
- let(:home_path_modifier) { double }
78
+ let(:path_modifier) { double('path modifier') }
79
+ let(:home_path_modifier) { double('home path modifier') }
80
80
 
81
81
  before do
82
82
  SPV::OptionsWithPath.stub(:new).and_return(options_with_path)
@@ -132,7 +132,13 @@ describe SPV::DSL::InitialAdjuster do
132
132
  end
133
133
 
134
134
  describe '#waiter' do
135
- let(:options) { double('waiter='.to_sym => true, 'waiter_options='.to_sym => true) }
135
+ let(:options) {
136
+ instance_double(
137
+ 'SPV::Options',
138
+ 'waiter='.to_sym => true,
139
+ 'waiter_options='.to_sym => true
140
+ )
141
+ }
136
142
 
137
143
  it 'defines a new waiter' do
138
144
  expect(options).to receive(:waiter=).with(kind_of(Proc))
@@ -147,8 +153,8 @@ describe SPV::DSL::InitialAdjuster do
147
153
  end
148
154
  end
149
155
 
150
- describe '#prepared_fixtures' do
151
- let(:fixtures) { double }
156
+ describe '#prepare_fixtures' do
157
+ let(:fixtures) { double('fixtures') }
152
158
  let(:raw_fixtures) { 'some raw fixtures' }
153
159
 
154
160
  before do
@@ -160,7 +166,7 @@ describe SPV::DSL::InitialAdjuster do
160
166
  it 'initializes the fixtures handler' do
161
167
  expect(SPV::Fixtures).to receive(:new).with(raw_fixtures).and_return(fixtures)
162
168
 
163
- expect(subject.prepared_fixtures).to eq(fixtures)
169
+ expect(subject.prepare_fixtures).to eq(fixtures)
164
170
  end
165
171
  end
166
172
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SPV::Element do
4
- let(:node) { stub }
5
- let(:parent) { double }
6
- let(:applier) { double(apply: true) }
4
+ let(:node) { double('node of DOM') }
5
+ let(:parent) { double('parent element') }
6
+ let(:applier) { instance_double('SPV::Applier', apply_vcr: true) }
7
7
 
8
8
  before do
9
9
  SPV::Applier.stub(:new).and_return(applier)
@@ -26,22 +26,20 @@ describe SPV::Element do
26
26
 
27
27
  before do
28
28
  subject.stub(:click)
29
+ subject.stub(:shift_event).and_yield.and_return(applier)
29
30
  end
30
31
 
31
- it 'applies custom fixtures' do
32
- expect(applier).to receive(:apply).with(
33
- kind_of(Proc)
34
- )
32
+ it 'shifts a click event to the applier' do
33
+ expect(subject).to receive(:shift_event).and_yield.and_return(applier)
34
+ expect(subject).to receive(:click)
35
35
 
36
- subject.click_and_apply_vcr() {}
36
+ subject.click_and_apply_vcr
37
37
  end
38
38
 
39
- it 'clicks on an element' do
40
- applier.stub(:apply).and_yield
41
-
42
- expect(subject).to receive(:click)
39
+ it 'applies vcr' do
40
+ expect(applier).to receive(:apply_vcr)
43
41
 
44
42
  subject.click_and_apply_vcr
45
43
  end
46
44
  end
47
- end
45
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SPV::Fixtures::Handler do
4
- let(:options) { double }
4
+ let(:options) { instance_double('SPV::Options') }
5
5
  let(:converted_fixtures) { [] }
6
6
  let(:fixtures_converter) { SPV::Fixtures::Converter }
7
7
 
@@ -19,7 +19,12 @@ describe SPV::Fixtures::Handler do
19
19
  let(:raw_fixtures) { 'some raw fixtures' }
20
20
  let(:converted_fixture) { 'converted fixture' }
21
21
  let(:converted_fixtures) { [converted_fixture] }
22
- let(:modifier) { double(modify: true) }
22
+ let(:modifier) do
23
+ instance_double(
24
+ 'SPV::Fixtures::Modifiers::HomePath',
25
+ modify: true
26
+ )
27
+ end
23
28
 
24
29
  it 'converts raw fixtures' do
25
30
  expect(fixtures_converter).to receive(:convert_raw).with(raw_fixtures)
@@ -1,12 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SPV::Fixtures::Manager do
4
- let(:options) { double(fixtures: ['some fixture']) }
4
+ let(:options) { instance_double('SPV::Options', fixtures: ['some fixture']) }
5
5
 
6
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] }
7
+ let(:fixture1) do
8
+ instance_double(
9
+ 'SPV::Fixture',
10
+ name: 'arya_stark',
11
+ options: {erb: {testvar: true}}
12
+ )
13
+ end
14
+
15
+ let(:fixture2) do
16
+ instance_double(
17
+ 'SPV::Fixture',
18
+ name: 'jon_snow',
19
+ options: {}
20
+ )
21
+ end
22
+
23
+ let(:fixtures) do
24
+ [fixture1, fixture2]
25
+ end
10
26
 
11
27
  subject(:manager) { described_class.new(options) }
12
28
 
@@ -3,8 +3,14 @@ require 'spec_helper'
3
3
  describe SPV::Fixtures::Modifiers::HomePath do
4
4
  describe '#modify' do
5
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) }
6
+ let(:options) { instance_double('SPV::Options', home_path: path) }
7
+ let(:fixture) do
8
+ instance_double(
9
+ 'SPV::Fixture',
10
+ name: 'test_with_home_path',
11
+ :has_link_to_home_path? => true
12
+ )
13
+ end
8
14
 
9
15
  subject { described_class.new(options).modify(fixture) }
10
16
 
@@ -35,7 +41,12 @@ describe SPV::Fixtures::Modifiers::HomePath do
35
41
  end
36
42
 
37
43
  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) }
44
+ let(:fixture) do
45
+ instance_double(
46
+ 'SPV::Fixture',
47
+ :has_link_to_home_path? => false
48
+ )
49
+ end
39
50
 
40
51
  it 'does not set any home path' do
41
52
  expect(fixture).to_not receive(:set_home_path)
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe SPV::Fixtures::Modifiers::Path do
4
4
  describe '#modify' do
5
5
  let(:path) { 'some path' }
6
- let(:options) { double(path: path) }
7
- let(:fixture) { double(:has_link_to_home_path? => false) }
6
+ let(:options) { instance_double('SPV::Options', path: path) }
7
+ let(:fixture) { instance_double('SPV::Fixture', :has_link_to_home_path? => false) }
8
8
 
9
9
  subject { described_class.new(options).modify(fixture) }
10
10
 
@@ -27,7 +27,13 @@ describe SPV::Fixtures::Modifiers::Path do
27
27
  end
28
28
 
29
29
  context 'when the fixture has a link to the home path' do
30
- let(:fixture) { double(:has_link_to_home_path? => true, clean_name: 'Max') }
30
+ let(:fixture) do
31
+ instance_double(
32
+ 'SPV::Fixture',
33
+ :has_link_to_home_path? => true,
34
+ clean_name: 'Max'
35
+ )
36
+ end
31
37
 
32
38
  it 'raises an error about link to the home path' do
33
39
  expect{
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SPV::Fixtures::TmpKeeper do
4
- let(:options) { double }
4
+ let(:options) { instance_double('SPV::Options') }
5
5
  let(:tmp_keeper) { described_class.new(options) }
6
6
 
7
7
  describe '#add_fixtures' do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SPV::Fixtures do
4
- let(:fixture1) { double(name: 'fixture1') }
5
- let(:fixture2) { double(name: 'fixture2') }
6
- let(:fixture3) { double(name: 'fixture3') }
7
- let(:fixture4) { double(name: 'fixture4') }
8
- let(:fixture5) { double(name: 'fixture5') }
4
+ let(:fixture1) { instance_double('SPV::Fixture', name: 'fixture1') }
5
+ let(:fixture2) { instance_double('SPV::Fixture', name: 'fixture2') }
6
+ let(:fixture3) { instance_double('SPV::Fixture', name: 'fixture3') }
7
+ let(:fixture4) { instance_double('SPV::Fixture', name: 'fixture4') }
8
+ let(:fixture5) { instance_double('SPV::Fixture', name: 'fixture5') }
9
9
 
10
10
  subject(:fixtures) { described_class.new([fixture1, fixture2, fixture3]) }
11
11
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SPV::Options do
4
- let(:options) { described_class.new }
4
+ subject(:options) { described_class.new }
5
5
 
6
6
  describe '.new' do
7
7
  it 'holds the passed options' do
@@ -38,4 +38,38 @@ describe SPV::Options do
38
38
  expect(cloned_options.object_id).to_not eq(options.object_id)
39
39
  end
40
40
  end
41
+
42
+ describe '#waiter_options' do
43
+ context 'when options are not defined' do
44
+ it 'returns an empty hash' do
45
+ expect(options.waiter_options).to be_a(Hash)
46
+ end
47
+ end
48
+
49
+ context 'when options are defined' do
50
+ it 'returns it' do
51
+ expected = {eject_fixtures: false}
52
+
53
+ subject.waiter_options = expected
54
+
55
+ expect(subject.waiter_options).to eq(expected)
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '#merge_waiter_options!' do
61
+ it 'redefines default options' do
62
+ subject.waiter_options = {
63
+ eject_fixtures: false,
64
+ some_another_option: true
65
+ }
66
+
67
+ subject.merge_waiter_options!(eject_fixtures: true)
68
+
69
+ expect(options.waiter_options).to include(
70
+ eject_fixtures: true,
71
+ some_another_option: true
72
+ )
73
+ end
74
+ end
41
75
  end
@@ -7,38 +7,51 @@ class TestPageWithElement
7
7
  def element(*); end
8
8
  end
9
9
 
10
- def el_with_options
11
- 'original element with options'
10
+ def test_el1; end
11
+ def test_el2
12
+ 'original element'
12
13
  end
13
14
 
14
- def test_el; end
15
-
16
- element_with_vcr(:el_with_options, '#selector', fixtures: 'some fixtures') {}
15
+ link_vcr_with_element :test_el2
17
16
  end
18
17
 
19
18
  describe SitePrism::ElementContainer do
20
19
  describe '.element_with_vcr' do
20
+ subject do
21
+ TestPageWithElement.instance_eval do
22
+ element_with_vcr :test_el1, '#test_selector', visible: false
23
+ end
24
+ end
25
+
21
26
  it 'calls the original element method with given arguments' do
22
27
  expect(TestPageWithElement).to receive(:element).with(
23
- :test_el,
28
+ :test_el1,
24
29
  '#test_selector',
25
30
  visible: false
26
31
  )
27
32
 
28
- TestPageWithElement.instance_eval do
29
- element_with_vcr :test_el, '#test_selector', visible: false
30
- end
33
+ subject
34
+ end
35
+
36
+ it 'links vcr with an element' do
37
+ expect(TestPageWithElement).to receive(:link_vcr_with_element).with(
38
+ :test_el1
39
+ )
40
+
41
+ subject
31
42
  end
43
+ end
32
44
 
45
+ describe '.link_vcr_with_element' do
33
46
  context 'when a method for getting an element is called' do
34
47
  let(:page) { TestPageWithElement.new }
35
48
  let(:vcr_el) { 'vcr element' }
36
49
 
37
- subject { page.el_with_options }
50
+ subject { page.test_el2 }
38
51
 
39
- it 'initializes a new instance of an element with empty options' do
52
+ it 'initializes a new instance of an element' do
40
53
  expect(SPV::Element).to receive(:new).with(
41
- 'original element with options', page
54
+ 'original element', page
42
55
  ).and_return(vcr_el)
43
56
 
44
57
  expect(subject).to eq(vcr_el)
@@ -3,55 +3,48 @@ require 'spec_helper'
3
3
  describe SitePrism::Page do
4
4
  subject { SitePrism::Page.new }
5
5
 
6
- describe '#apply_vcr' do
7
- let(:applier) { double(apply: true) }
8
- let(:action_block) { double(call: true) }
6
+ let(:applier) do
7
+ instance_double(
8
+ 'SPV::Applier',
9
+ apply_vcr: true
10
+ )
11
+ end
9
12
 
10
- before do
11
- SitePrism::Page.vcr_options_for_load { }
13
+ before do
14
+ SitePrism::Page.vcr_options_for_load { }
15
+ end
12
16
 
17
+ describe '.new' do
18
+ before do
13
19
  SPV::Applier.stub(:new).and_return(applier)
14
20
  end
15
21
 
16
22
  it 'initializes the fixtures applier' do
17
23
  expect(SPV::Applier).to receive(:new).with(
18
- subject
19
- ).and_return(applier)
20
-
21
- subject.apply_vcr(action_block)
22
- end
23
-
24
- it 'applies fixtures' do
25
- expect(applier).to receive(:apply).with(
26
- kind_of(Proc)
24
+ kind_of(described_class)
27
25
  )
28
26
 
29
- subject.apply_vcr(action_block) { }
30
- end
31
-
32
- it 'does the action from the action block' do
33
- applier.stub(:apply).and_yield
34
-
35
- expect(action_block).to receive(:call)
36
-
37
- subject.apply_vcr('arg1', 'arg2', action_block) { }
27
+ subject
38
28
  end
39
29
  end
40
30
 
41
31
  describe '#load_and_apply_vcr' do
42
32
  before do
43
- subject.stub(:apply_vcr)
44
33
  subject.stub(:load)
34
+ subject.stub(:shift_event).and_yield.and_return(applier)
45
35
  end
46
36
 
47
- it 'applies vcr fixtures and loads the page' do
48
- expect(subject).to receive(:apply_vcr) do |action_block|
49
- expect(subject).to receive(:load).with('arg1', 'arg2')
37
+ it 'shifts a load event to the applier' do
38
+ expect(subject).to receive(:shift_event).and_yield.and_return(applier)
39
+ expect(subject).to receive(:load).with('some arguments')
40
+
41
+ subject.load_and_apply_vcr('some arguments')
42
+ end
50
43
 
51
- action_block.call
52
- end
44
+ it 'applies vcr' do
45
+ expect(applier).to receive(:apply_vcr)
53
46
 
54
- subject.load_and_apply_vcr('arg1', 'arg2') { }
47
+ subject.load_and_apply_vcr
55
48
  end
56
49
  end
57
50
  end
@@ -1,15 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SPV::Waiter do
4
- let(:node) { double }
5
- let(:options) { double(waiter_options: nil, waiter: nil) }
6
- let(:fixtures_manager) { double(eject: true) }
4
+ let(:node) { double('node of DOM') }
5
+ let(:options) {
6
+ instance_double(
7
+ 'SPV::Options',
8
+ waiter_options: nil,
9
+ waiter: nil
10
+ )
11
+ }
12
+
13
+ let(:fixtures_manager) {
14
+ instance_double(
15
+ 'SPV::Fixtures::Manager',
16
+ eject: true
17
+ )
18
+ }
7
19
 
8
20
  subject(:waiter) { described_class.new(node, fixtures_manager, options) }
9
21
 
10
22
  describe '#wait' do
11
23
  context 'when a waiter is defined' do
12
- let(:node) { double(wait_for_content: true) }
24
+ let(:node) { double('node of DOM', wait_for_content: true) }
13
25
 
14
26
  before do
15
27
  options.stub(:waiter).and_return(proc { self.wait_for_content })