site_prism.vcr 0.1.2 → 0.2.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.
Files changed (48) hide show
  1. checksums.yaml +5 -13
  2. data/.travis.yml +5 -0
  3. data/CHANGELOG.md +51 -4
  4. data/Gemfile +3 -4
  5. data/README.md +88 -10
  6. data/TODO.md +29 -31
  7. data/lib/site_prism_vcr/applier.rb +51 -13
  8. data/lib/site_prism_vcr/dsl/adjuster.rb +1 -1
  9. data/lib/site_prism_vcr/dsl/initial_adjuster.rb +26 -6
  10. data/lib/site_prism_vcr/fixture.rb +7 -4
  11. data/lib/site_prism_vcr/fixtures/manager.rb +30 -11
  12. data/lib/site_prism_vcr/fixtures/modifiers/path.rb +6 -6
  13. data/lib/site_prism_vcr/fixtures/modifiers/shortcut_path.rb +25 -0
  14. data/lib/site_prism_vcr/mixins/element.rb +23 -0
  15. data/lib/site_prism_vcr/mixins/page.rb +63 -0
  16. data/lib/site_prism_vcr/options.rb +20 -6
  17. data/lib/site_prism_vcr/patches/element.rb +4 -0
  18. data/lib/site_prism_vcr/patches/page.rb +2 -38
  19. data/lib/site_prism_vcr/version.rb +1 -1
  20. data/lib/site_prism_vcr.rb +2 -2
  21. data/spec/integration/elements/apply_spec.rb +4 -0
  22. data/spec/integration/pages/custom_event_spec.rb +1 -1
  23. data/spec/integration/pages/load_spec.rb +11 -0
  24. data/spec/spec_helper.rb +3 -2
  25. data/spec/spec_integration_helper.rb +0 -3
  26. data/spec/support/shared/integration/home_path.rb +1 -1
  27. data/spec/support/shared/integration/shortcut_path.rb +13 -0
  28. data/spec/support/site_prism/pages/page_load/subpage_with_fixtures.rb +14 -0
  29. data/spec/unit/applier_spec.rb +97 -43
  30. data/spec/unit/dsl/adjuster_spec.rb +7 -7
  31. data/spec/unit/dsl/initial_adjuster_spec.rb +29 -13
  32. data/spec/unit/element_spec.rb +3 -3
  33. data/spec/unit/fixture_spec.rb +47 -17
  34. data/spec/unit/fixtures/converter_spec.rb +1 -1
  35. data/spec/unit/fixtures/handler_spec.rb +3 -3
  36. data/spec/unit/fixtures/manager_spec.rb +76 -29
  37. data/spec/unit/fixtures/modifiers/path_spec.rb +10 -10
  38. data/spec/unit/fixtures/modifiers/relative_path_spec.rb +1 -1
  39. data/spec/unit/fixtures/modifiers/shortcut_path_spec.rb +61 -0
  40. data/spec/unit/{patches/element_container_spec.rb → mixins/element_spec.rb} +2 -2
  41. data/spec/unit/mixins/page_spec.rb +105 -0
  42. data/spec/unit/options_spec.rb +6 -6
  43. data/spec/unit/waiter_spec.rb +3 -3
  44. metadata +28 -22
  45. data/lib/site_prism_vcr/fixtures/modifiers/home_path.rb +0 -25
  46. data/lib/site_prism_vcr/patches/element_container.rb +0 -19
  47. data/spec/unit/fixtures/modifiers/home_path_spec.rb +0 -58
  48. data/spec/unit/patches/page_spec.rb +0 -50
@@ -9,8 +9,8 @@ describe SPV::DSL::InitialAdjuster do
9
9
  subject { described_class.new(options) }
10
10
 
11
11
  before do
12
- SPV::Fixtures::TmpKeeper.stub(:new).and_return(tmp_keeper)
13
- SPV::Fixtures::Handler.stub(:new).and_return(fixtures_handler)
12
+ allow(SPV::Fixtures::TmpKeeper).to receive(:new).and_return(tmp_keeper)
13
+ allow(SPV::Fixtures::Handler).to receive(:new).and_return(fixtures_handler)
14
14
  end
15
15
 
16
16
  describe '.new' do
@@ -33,12 +33,12 @@ describe SPV::DSL::InitialAdjuster do
33
33
  let(:relative_path_modifier) { double('relative path modifier') }
34
34
 
35
35
  before do
36
- SPV::Fixtures::Modifiers::HomePath.stub(:new).and_return(home_path_modifier)
37
- SPV::Fixtures::Modifiers::RelativePath.stub(:new).and_return(relative_path_modifier)
36
+ allow(SPV::Fixtures::Modifiers::ShortcutPath).to receive(:new).and_return(home_path_modifier)
37
+ allow(SPV::Fixtures::Modifiers::RelativePath).to receive(:new).and_return(relative_path_modifier)
38
38
  end
39
39
 
40
40
  it 'initializes the home path modifier' do
41
- expect(SPV::Fixtures::Modifiers::HomePath).to receive(:new).with(options)
41
+ expect(SPV::Fixtures::Modifiers::ShortcutPath).to receive(:new).with(options)
42
42
 
43
43
  subject.fixtures(raw_fixtures)
44
44
  end
@@ -71,13 +71,29 @@ describe SPV::DSL::InitialAdjuster do
71
71
  describe '#home_path' do
72
72
  let(:raw_home_path) { 'some home path' }
73
73
 
74
- it 'defines a default home path' do
75
- expect(options).to receive(:home_path=).with(raw_home_path)
74
+ it 'defines a shortcut for a home path' do
75
+ expect(options).to receive(:add_shortcut_path).with(
76
+ '~',
77
+ raw_home_path
78
+ )
76
79
 
77
80
  subject.home_path(raw_home_path)
78
81
  end
79
82
  end
80
83
 
84
+ describe '#shortcut_path' do
85
+ let(:raw_path) { 'some path' }
86
+
87
+ it 'defines a shortcut for the path' do
88
+ expect(options).to receive(:add_shortcut_path).with(
89
+ 'test_shortcut',
90
+ raw_path
91
+ )
92
+
93
+ subject.shortcut_path('test_shortcut', raw_path)
94
+ end
95
+ end
96
+
81
97
  describe '#path' do
82
98
  def set_path
83
99
  subject.path 'path', raw_fixtures
@@ -90,9 +106,9 @@ describe SPV::DSL::InitialAdjuster do
90
106
  let(:home_path_modifier) { double('home path modifier') }
91
107
 
92
108
  before do
93
- SPV::OptionsWithPath.stub(:new).and_return(options_with_path)
94
- SPV::Fixtures::Modifiers::Path.stub(:new).and_return(path_modifier)
95
- SPV::Fixtures::Modifiers::HomePath.stub(:new).and_return(home_path_modifier)
109
+ allow(SPV::OptionsWithPath).to receive(:new).and_return(options_with_path)
110
+ allow(SPV::Fixtures::Modifiers::Path).to receive(:new).and_return(path_modifier)
111
+ allow(SPV::Fixtures::Modifiers::ShortcutPath).to receive(:new).and_return(home_path_modifier)
96
112
  end
97
113
 
98
114
  it 'initializes a new object with options' do
@@ -117,7 +133,7 @@ describe SPV::DSL::InitialAdjuster do
117
133
 
118
134
  it 'initializes the modifier to set home path' do
119
135
  expect(
120
- SPV::Fixtures::Modifiers::HomePath
136
+ SPV::Fixtures::Modifiers::ShortcutPath
121
137
  ).to receive(:new).with(options_with_path)
122
138
 
123
139
  set_path
@@ -169,9 +185,9 @@ describe SPV::DSL::InitialAdjuster do
169
185
  let(:raw_fixtures) { 'some raw fixtures' }
170
186
 
171
187
  before do
172
- SPV::Fixtures.stub(:new).and_return(fixtures)
188
+ allow(SPV::Fixtures).to receive(:new).and_return(fixtures)
173
189
 
174
- tmp_keeper.stub(:fixtures).and_return(raw_fixtures)
190
+ allow(tmp_keeper).to receive(:fixtures).and_return(raw_fixtures)
175
191
  end
176
192
 
177
193
  it 'initializes the fixtures handler' do
@@ -6,7 +6,7 @@ describe SPV::Element do
6
6
  let(:applier) { instance_double('SPV::Applier', apply_vcr: true) }
7
7
 
8
8
  before do
9
- SPV::Applier.stub(:new).and_return(applier)
9
+ allow(SPV::Applier).to receive(:new).and_return(applier)
10
10
  end
11
11
 
12
12
  describe '.new' do
@@ -25,8 +25,8 @@ describe SPV::Element do
25
25
  subject { described_class.new(nil, parent) }
26
26
 
27
27
  before do
28
- subject.stub(:click)
29
- subject.stub(:shift_event).and_yield.and_return(applier)
28
+ allow(subject).to receive(:click)
29
+ allow(subject).to receive(:shift_event).and_yield.and_return(applier)
30
30
  end
31
31
 
32
32
  it 'shifts a click event to the applier' do
@@ -55,34 +55,64 @@ describe SPV::Fixture do
55
55
  end
56
56
 
57
57
  describe '#set_home_path' do
58
- subject { described_class.new('~/fixture_name') }
58
+ context 'when a simple shortcut is used' do
59
+ it 'defines a new name with a replaced shortcut path' do
60
+ fixture = described_class.new(':shortcut/fixture_name')
61
+
62
+ expect(fixture).to receive(:path=).with('my_home_path/')
63
+
64
+ fixture.set_home_path('my_home_path/')
65
+ end
59
66
 
60
- it 'defines a new name with replaced home path symbol' do
61
- expect(subject).to receive(:path=).with('my_home_path/')
67
+ it 'defines a new name with a replaced shortcut path and keeps a path to subdirectory' do
68
+ fixture = described_class.new(':shortcut/sub/fixture_name')
62
69
 
63
- subject.set_home_path('my_home_path/')
70
+ expect(fixture).to receive(:path=).with('my_home_path/sub')
71
+
72
+ fixture.set_home_path('my_home_path/')
73
+ end
64
74
  end
65
75
 
66
- it 'defines a new name with replaced home path symbol and keeps a path to subdirectory' do
67
- fixture = described_class.new('~/sub/fixture_name')
76
+ context 'when a home path is used' do
77
+ it 'defines a new name with a replaced home path symbol' do
78
+ fixture = described_class.new('~/fixture_name')
68
79
 
69
- expect(fixture).to receive(:path=).with('my_home_path/sub')
80
+ expect(fixture).to receive(:path=).with('my_home_path/')
81
+
82
+ fixture.set_home_path('my_home_path/')
83
+ end
70
84
 
71
- fixture.set_home_path('my_home_path/')
85
+ it 'defines a new name with replaced a home path symbol and keeps a path to subdirectory' do
86
+ fixture = described_class.new('~/sub/fixture_name')
87
+
88
+ expect(fixture).to receive(:path=).with('my_home_path/sub')
89
+
90
+ fixture.set_home_path('my_home_path/')
91
+ end
72
92
  end
73
93
  end
74
94
 
75
- describe '#has_link_to_home_path?' do
76
- it 'returns true when a name of fixture starts with "~/"' do
77
- expect(
78
- described_class.new('~/some').has_link_to_home_path?
79
- ).to be_true
95
+ describe '#shortcut_path' do
96
+ context 'when a fixture has a shortcut' do
97
+ it 'returns "~" for "~/some"' do
98
+ expect(
99
+ described_class.new('~/some').shortcut_path
100
+ ).to eq('~')
101
+ end
102
+
103
+ it 'returns "path" for ":path/some"' do
104
+ expect(
105
+ described_class.new(':path/some').shortcut_path
106
+ ).to eq('path')
107
+ end
80
108
  end
81
109
 
82
- it 'returns true when a name of fixture does not start with "~/"' do
83
- expect(
84
- described_class.new('some').has_link_to_home_path?
85
- ).to be_false
110
+ context 'when a fixture has not a shortcut' do
111
+ it 'returns nil' do
112
+ expect(
113
+ described_class.new('some').shortcut_path
114
+ ).to be_nil
115
+ end
86
116
  end
87
117
  end
88
118
 
@@ -12,7 +12,7 @@ describe SPV::Fixtures::Converter do
12
12
  }
13
13
 
14
14
  before do
15
- SPV::Fixture.stub(:new).and_return('first prepared', 'second prepared')
15
+ allow(SPV::Fixture).to receive(:new).and_return('first prepared', 'second prepared')
16
16
  end
17
17
 
18
18
  it 'initializes first object of Fixture class' do
@@ -8,7 +8,7 @@ describe SPV::Fixtures::Handler do
8
8
  subject { described_class.new(options) }
9
9
 
10
10
  before do
11
- SPV::Fixtures::Converter.stub(:convert_raw).and_return(converted_fixtures)
11
+ allow(SPV::Fixtures::Converter).to receive(:convert_raw).and_return(converted_fixtures)
12
12
  end
13
13
 
14
14
  describe '#handle_raw' do
@@ -21,7 +21,7 @@ describe SPV::Fixtures::Handler do
21
21
  let(:converted_fixtures) { [converted_fixture] }
22
22
  let(:modifier) do
23
23
  instance_double(
24
- 'SPV::Fixtures::Modifiers::HomePath',
24
+ 'SPV::Fixtures::Modifiers::ShortcutPath',
25
25
  modify: true
26
26
  )
27
27
  end
@@ -55,7 +55,7 @@ describe SPV::Fixtures::Handler do
55
55
  let(:modifiers) { 'some modifiers' }
56
56
 
57
57
  before do
58
- subject.stub(:handle_raw).and_return(handled_fixtures_1, handled_fixtures_2)
58
+ allow(subject).to receive(:handle_raw).and_return(handled_fixtures_1, handled_fixtures_2)
59
59
  end
60
60
 
61
61
  it 'handles the first set of raw fixtures' do
@@ -1,35 +1,63 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SPV::Fixtures::Manager do
4
- let(:options) { instance_double('SPV::Options', fixtures: ['some fixture']) }
5
-
6
- describe '#inject' do
7
- let(:fixture1) do
8
- instance_double(
9
- 'SPV::Fixture',
10
- name: 'arya_stark',
11
- options: {
12
- erb: {
13
- testvar: true,
14
- port: 123
15
- }
4
+ let(:options) { instance_double('SPV::Options') }
5
+
6
+ let(:fixture1) do
7
+ instance_double(
8
+ 'SPV::Fixture',
9
+ name: 'arya_stark',
10
+ options: {
11
+ erb: {
12
+ testvar: true,
13
+ port: 123
16
14
  }
17
- )
15
+ }
16
+ )
17
+ end
18
+
19
+ let(:fixture2) do
20
+ instance_double(
21
+ 'SPV::Fixture',
22
+ name: 'jon_snow',
23
+ options: {}
24
+ )
25
+ end
26
+
27
+ let(:fixtures) do
28
+ [fixture1, fixture2]
29
+ end
30
+
31
+ describe '.inject' do
32
+ let(:manager) { instance_double('SPV::Fixtures::Manager', inject: true) }
33
+
34
+ subject { described_class.inject(fixtures, options) }
35
+
36
+ before do
37
+ allow(described_class).to receive(:new).and_return(manager)
18
38
  end
19
39
 
20
- let(:fixture2) do
21
- instance_double(
22
- 'SPV::Fixture',
23
- name: 'jon_snow',
24
- options: {}
25
- )
40
+ it 'initializes a new instance of the fixtures manager class' do
41
+ expect(described_class).to receive(:new).with(fixtures, options)
42
+
43
+ subject
26
44
  end
27
45
 
28
- let(:fixtures) do
29
- [fixture1, fixture2]
46
+ it 'injects fixtures' do
47
+ expect(manager).to receive(:inject)
48
+
49
+ subject
30
50
  end
31
51
 
32
- subject(:manager) { described_class.new(options) }
52
+ it 'returns an instance of the manager' do
53
+ res = subject
54
+
55
+ expect(manager).to eq(res)
56
+ end
57
+ end
58
+
59
+ describe '#inject' do
60
+ subject(:manager) { described_class.new(fixtures, options) }
33
61
 
34
62
  context 'when there are fixtures' do
35
63
  after do
@@ -39,7 +67,7 @@ describe SPV::Fixtures::Manager do
39
67
 
40
68
  context 'when VCR holds the first fixture' do
41
69
  before do
42
- manager.inject(fixtures)
70
+ manager.inject
43
71
 
44
72
  VCR.eject_cassette
45
73
  @fixture = VCR.eject_cassette
@@ -56,7 +84,7 @@ describe SPV::Fixtures::Manager do
56
84
 
57
85
  context 'when VCR holds the second fixture' do
58
86
  before do
59
- manager.inject(fixtures)
87
+ manager.inject
60
88
 
61
89
  @fixture = VCR.eject_cassette
62
90
  end
@@ -72,8 +100,10 @@ describe SPV::Fixtures::Manager do
72
100
  end
73
101
 
74
102
  context 'when there are not any fixtures' do
103
+ let(:fixtures) { [] }
104
+
75
105
  it 'raises an error about no fixtures' do
76
- expect { manager.inject([]) }.to raise_error(
106
+ expect { manager.inject }.to raise_error(
77
107
  ArgumentError,
78
108
  'No fixtures were specified to insert them into VCR'
79
109
  )
@@ -82,12 +112,29 @@ describe SPV::Fixtures::Manager do
82
112
  end
83
113
 
84
114
  describe '#eject' do
85
- subject { described_class.new(options).eject }
115
+ subject(:manager) { described_class.new(fixtures, options) }
86
116
 
87
- it 'ejects all fixtures from VCR' do
88
- expect(SPV::Helpers).to receive(:eject_all_cassettes)
117
+ before do
118
+ manager.inject
119
+ end
89
120
 
90
- subject
121
+ it 'ejects the inserted fixtures' do
122
+ manager.eject
123
+
124
+ expect(VCR.eject_cassette).to equal(nil)
125
+ end
126
+
127
+ context 'when there are fixtures inserted by another code' do
128
+ before do
129
+ VCR.insert_cassette('test_cassette')
130
+ end
131
+
132
+ it 'does not remove fixtures which are not inserted by this instance of the fixtures manager' do
133
+ manager.eject
134
+
135
+ expect(VCR.eject_cassette.name).to eq('test_cassette')
136
+ expect(VCR.eject_cassette).to equal(nil)
137
+ end
91
138
  end
92
139
  end
93
140
  end
@@ -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) { instance_double('SPV::Options', path: path) }
7
- let(:fixture) { instance_double('SPV::Fixture', :has_link_to_home_path? => false) }
6
+ let(:options) { instance_double('SPV::OptionsWithPath', path: path) }
7
+ let(:fixture) { instance_double('SPV::Fixture', shortcut_path: nil) }
8
8
 
9
9
  subject { described_class.new(options).modify(fixture) }
10
10
 
@@ -26,24 +26,24 @@ describe SPV::Fixtures::Modifiers::Path do
26
26
  end
27
27
  end
28
28
 
29
- context 'when the fixture has a link to the home path' do
29
+ context 'when the fixture has a shortcut path' do
30
30
  let(:fixture) do
31
31
  instance_double(
32
32
  'SPV::Fixture',
33
- :has_link_to_home_path? => true,
34
- clean_name: 'Max'
33
+ shortcut_path: 'myshortcut',
34
+ clean_name: 'Max'
35
35
  )
36
36
  end
37
37
 
38
- it 'raises an error about link to the home path' do
38
+ it 'raises an error about a shortcut path' do
39
39
  expect{
40
40
  subject
41
41
  }.to raise_error(
42
- SPV::Fixtures::Modifiers::Path::HomePathError,
43
- "You cannot use the home path while listing fixtures in the 'path' method. " <<
42
+ SPV::Fixtures::Modifiers::Path::ShortcutPathError,
43
+ "You cannot use a shortcut path while listing fixtures in the 'path' method. " <<
44
44
  "Please, use 'fixtures' method for 'Max' fixture or " <<
45
- "you can additionally use the 'path' method where you will specify a home path as a path name." <<
46
- "Example: path('~/', ['Max'])"
45
+ "you can additionally use the 'path' method where you will specify a shortcut path as a path name." <<
46
+ "Example: path(':myshortcut', ['Max'])"
47
47
  )
48
48
  end
49
49
  end
@@ -13,7 +13,7 @@ describe SPV::Fixtures::Modifiers::RelativePath do
13
13
  end
14
14
 
15
15
  it 'moves up on 2 levels in the hierarchy of directories' do
16
- fixture.stub(:path).and_return('parent_dir/some_dir/next_dir/../../')
16
+ allow(fixture).to receive(:path).and_return('parent_dir/some_dir/next_dir/../../')
17
17
 
18
18
  expect(fixture).to receive(:path=).with('parent_dir')
19
19
 
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe SPV::Fixtures::Modifiers::ShortcutPath do
4
+ describe '#modify' do
5
+ let(:path) { 'some home path' }
6
+ let(:shortcut_path) { 'some shortcut' }
7
+ let(:options) { instance_double('SPV::Options') }
8
+ let(:fixture) do
9
+ instance_double(
10
+ 'SPV::Fixture',
11
+ name: 'test_with_home_path',
12
+ shortcut_path: shortcut_path
13
+ )
14
+ end
15
+
16
+ subject { described_class.new(options).modify(fixture) }
17
+
18
+ context 'when a name of the fixture has a shortcut path' do
19
+ context 'when a given shortcut path is defined' do
20
+ it 'writes a proper path to the fixture' do
21
+ expect(options).to receive(:shortcut_path).with(shortcut_path).and_return(path)
22
+ expect(fixture).to receive(:set_home_path).with(path)
23
+
24
+ subject
25
+ end
26
+ end
27
+
28
+ context 'when a given shortcut path is not defined' do
29
+ before do
30
+ allow(options).to receive(:shortcut_path).and_return(nil)
31
+ end
32
+
33
+ it 'raises an argument error about wrong way of defining fixtures' do
34
+ msg = "You are trying to use the 'some shortcut' shortcut path " \
35
+ "for test_with_home_path fixture. This shortcut path cannot be " \
36
+ "used since it is not defined, please refer to the documentation to make " \
37
+ "sure you properly define the shortcut path."
38
+
39
+ expect { subject }.to raise_error(
40
+ ArgumentError, msg
41
+ )
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'when a name of the fixture has not a shortcut path' do
47
+ let(:fixture) do
48
+ instance_double(
49
+ 'SPV::Fixture',
50
+ shortcut_path: nil
51
+ )
52
+ end
53
+
54
+ it 'does not set any home path' do
55
+ expect(fixture).to_not receive(:set_home_path)
56
+
57
+ subject
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class TestPageWithElement
4
- extend SitePrism::ElementContainer
4
+ extend SPV::Mixins::Element
5
5
 
6
6
  class << self
7
7
  def element(*); end
@@ -15,7 +15,7 @@ class TestPageWithElement
15
15
  link_vcr_with_element :test_el2
16
16
  end
17
17
 
18
- describe SitePrism::ElementContainer do
18
+ describe SPV::Mixins::Element do
19
19
  describe '.element_with_vcr' do
20
20
  subject do
21
21
  TestPageWithElement.instance_eval do
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ class TestPage
4
+ include SPV::Mixins::Page
5
+ end
6
+
7
+ describe SPV::Mixins::Page do
8
+ describe 'class methods' do
9
+ subject { TestPage }
10
+
11
+ describe '.adjust_parent_vcr_options' do
12
+ subject { TestPage.adjust_parent_vcr_options }
13
+
14
+ context 'when there are not defined vcr options' do
15
+ it 'raises an error' do
16
+ expect{
17
+ subject
18
+ }.to raise_error(ArgumentError, 'There is not any Vcr options defined for the parent class')
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ describe 'instance methods' do
25
+ subject { TestPage.new }
26
+
27
+ let(:applier) do
28
+ instance_double(
29
+ 'SPV::Applier',
30
+ apply_vcr: true,
31
+ alter_fixtures: true
32
+ )
33
+ end
34
+
35
+ before do
36
+ TestPage.vcr_options_for_load { }
37
+ end
38
+
39
+ describe '#load_and_apply_vcr' do
40
+ before do
41
+ allow(subject).to receive(:shift_event).and_return(applier)
42
+ allow(subject).to receive(:load)
43
+ end
44
+
45
+ it 'shifts a load event to the applier' do
46
+ expect(subject).to receive(:shift_event).and_yield.and_return(applier)
47
+ expect(subject).to receive(:load).with('some arguments')
48
+
49
+ subject.load_and_apply_vcr('some arguments')
50
+ end
51
+
52
+ it 'applies vcr' do
53
+ expect(applier).to receive(:apply_vcr)
54
+
55
+ subject.load_and_apply_vcr
56
+ end
57
+ end
58
+
59
+ describe '#shift_event' do
60
+ before do
61
+ allow(SPV::Applier).to receive(:new).and_return(applier)
62
+ allow(applier).to receive(:shift_event).and_yield.and_return(applier)
63
+ end
64
+
65
+ context 'when the applier is not initialized yet' do
66
+ it 'initializes the fixtures applier' do
67
+ expect(SPV::Applier).to receive(:new).with(
68
+ subject
69
+ )
70
+
71
+ subject.shift_event {}
72
+ end
73
+
74
+ context 'when there are the defined blocks to adjust Vcr options' do
75
+ before do
76
+ TestPage.vcr_options_for_load { }
77
+ TestPage.adjust_parent_vcr_options {}
78
+ TestPage.adjust_parent_vcr_options {}
79
+ end
80
+
81
+ it 'alters Vcr fixtures' do
82
+ expect(applier).to receive(:alter_fixtures).twice
83
+
84
+ subject.shift_event {}
85
+ end
86
+ end
87
+ end
88
+
89
+ context 'when the applier is already initialized' do
90
+ it 'does not initialize it twice' do
91
+ expect(SPV::Applier).to receive(:new).once
92
+
93
+ subject.shift_event {}
94
+ subject.shift_event {}
95
+ end
96
+ end
97
+
98
+ it 'shifts an event to the applier' do
99
+ expect(applier).to receive(:shift_event)
100
+
101
+ subject.shift_event { }
102
+ end
103
+ end
104
+ end
105
+ end
@@ -15,18 +15,18 @@ describe SPV::Options do
15
15
  end
16
16
  end
17
17
 
18
- describe '#home_path=' do
18
+ describe '#add_shortcut_path' do
19
19
  context 'when the last symbol is a slash' do
20
- it 'returns the home path as it is' do
21
- options.home_path = 'some/path/'
22
- expect(options.home_path).to eq('some/path/')
20
+ it 'returns the path as it is' do
21
+ options.add_shortcut_path('~', 'some/path/')
22
+ expect(options.shortcut_path('~')).to eq('some/path/')
23
23
  end
24
24
  end
25
25
 
26
26
  context 'when the last symbol is not slash' do
27
27
  it 'returns the home path with a slash at the end of the path' do
28
- options.home_path = 'some/path'
29
- expect(options.home_path).to eq('some/path/')
28
+ options.add_shortcut_path('~', 'some/path')
29
+ expect(options.shortcut_path('~')).to eq('some/path/')
30
30
  end
31
31
  end
32
32
  end
@@ -26,7 +26,7 @@ describe SPV::Waiter do
26
26
  let(:waiter) { instance_double('SPV::Waiter', wait: true) }
27
27
 
28
28
  before do
29
- described_class.stub(:new).and_return(waiter)
29
+ allow(described_class).to receive(:new).and_return(waiter)
30
30
  end
31
31
 
32
32
  it 'initializes a new instance of the waiter' do
@@ -57,7 +57,7 @@ describe SPV::Waiter do
57
57
  let(:node) { double('node of DOM', wait_for_content: true) }
58
58
 
59
59
  before do
60
- options.stub(:waiter).and_return(proc { self.wait_for_content })
60
+ allow(options).to receive(:waiter).and_return(proc { self.wait_for_content })
61
61
  end
62
62
 
63
63
  it 'calls the waiter to wait until all HTTP interactions are finished' do
@@ -76,7 +76,7 @@ describe SPV::Waiter do
76
76
 
77
77
  context 'when the option disallowing fixtures ejection is passed' do
78
78
  before do
79
- options.stub(:waiter_options).and_return(eject_cassettes: false)
79
+ allow(options).to receive(:waiter_options).and_return(eject_cassettes: false)
80
80
  end
81
81
 
82
82
  it 'does not eject fixtures' do