click_session 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -6
- data/Rakefile +1 -0
- data/click_session.gemspec +1 -1
- data/lib/click_session/configuration.rb +6 -7
- data/lib/click_session/sync.rb +2 -6
- data/lib/click_session/version.rb +1 -1
- data/lib/click_session/web_runner.rb +8 -1
- data/lib/click_session/web_runner_processor.rb +11 -9
- data/lib/generators/click_session/initializers/click_session.rb +1 -1
- data/lib/tasks/click_session.rake +1 -5
- data/spec/click_session/click_session_processor_spec.rb +2 -4
- data/spec/click_session/configuration_spec.rb +5 -5
- data/spec/click_session/sync_spec.rb +6 -9
- data/spec/click_session/web_runner_processor_spec.rb +98 -60
- data/spec/click_session/web_runner_spec.rb +18 -3
- data/spec/support/click_session_runner.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a68539042bc00feeb639ded737a7e67a9cf10cd
|
4
|
+
data.tar.gz: a557ea3a524b0185444fb3b3dd49220540c07c3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60a468b5b3f6109cde7556f6fe12575c2f26c63555c8d363956ac71268f1371c6fb07cac64fce844974098a408c7cdae3928cd63a27f50f6de8acf82e6110186
|
7
|
+
data.tar.gz: 65e1c0739b3e400b120ec3e43428602f7ba5822aa33cc66d3da36ff32fbd40f14c3991948cb0586fbd0a2ac0b7a04b759dbc88e8c7747f27f22e12398ab865e1
|
data/README.md
CHANGED
@@ -7,13 +7,17 @@ Modern web apps rely more and more on html to be loaded asyncronously after the
|
|
7
7
|
The Capybara team has put a lot of thought into how these web apps can be tested and because of this, it also makes a good tool for scraping these web sites.
|
8
8
|
|
9
9
|
## Installation
|
10
|
+
Add to `Gemfile`
|
11
|
+
```gem "click_session"```
|
10
12
|
|
11
|
-
|
13
|
+
Run `bundle install`
|
12
14
|
|
13
15
|
### Generate a migration
|
14
|
-
`rails generate click_session:install`
|
16
|
+
`rails generate click_session:install`
|
15
17
|
This will create a migration and generate an initializer with configuration parameters needed for click_session
|
16
18
|
|
19
|
+
## How to set up
|
20
|
+
|
17
21
|
### Define the steps in a class
|
18
22
|
Name the class ```ClickSessionRunner``` and add a method called ```run```.
|
19
23
|
|
@@ -59,7 +63,22 @@ result = sync_click_session.run
|
|
59
63
|
# --> result contains the serialized user data
|
60
64
|
```
|
61
65
|
|
66
|
+
Example of result hash:
|
67
|
+
```
|
68
|
+
{
|
69
|
+
id: 1234,
|
70
|
+
status: {
|
71
|
+
success: true, # Boolean
|
72
|
+
},
|
73
|
+
data: { # This is the output of the Serialized model
|
74
|
+
name: "Joe",
|
75
|
+
facebook_avatar: "http://fb.com/i/joe.png"
|
76
|
+
}
|
77
|
+
}
|
78
|
+
```
|
79
|
+
|
62
80
|
### Run session asyncronously
|
81
|
+
__1__ Create a new session
|
63
82
|
```ruby
|
64
83
|
user = User.new
|
65
84
|
async_click_session = ClickSession::Async.new(user)
|
@@ -67,16 +86,29 @@ result = async_click_session.run
|
|
67
86
|
# --> saves the User
|
68
87
|
# --> saves the SessionState
|
69
88
|
# --> result contains the ID of the saved SessionState
|
89
|
+
```
|
90
|
+
Example of result
|
91
|
+
```
|
92
|
+
{
|
93
|
+
id: 1234,
|
94
|
+
status: {
|
95
|
+
success: true, # Boolean
|
96
|
+
}
|
97
|
+
}
|
98
|
+
```
|
70
99
|
|
100
|
+
__2__ Run the rake task to process all the session that has not yet been executed
|
101
|
+
```
|
71
102
|
# $ rake click_session:process_active
|
72
103
|
# --> run the steps in the ClickSessionRunner
|
104
|
+
```
|
73
105
|
|
106
|
+
__3__ Run the rake task that reports all the successful sessions
|
107
|
+
```
|
74
108
|
# $ rake click_session:report_successful
|
75
109
|
# --> the request sent contains the serialized user data
|
76
110
|
```
|
77
|
-
|
78
|
-
### result hash
|
79
|
-
Example:
|
111
|
+
Example of payload posted to your webhook
|
80
112
|
```
|
81
113
|
{
|
82
114
|
id: 1234,
|
@@ -89,6 +121,8 @@ Example:
|
|
89
121
|
}
|
90
122
|
}
|
91
123
|
```
|
124
|
+
|
125
|
+
|
92
126
|
The only optional part of the result is the ```data```.
|
93
127
|
|
94
128
|
### Example of how to use it in a rails controller action
|
@@ -108,6 +142,11 @@ end
|
|
108
142
|
|
109
143
|
```
|
110
144
|
|
145
|
+
### Additional methods available to use in the specified steps
|
146
|
+
Method | Description
|
147
|
+
------ | -----------
|
148
|
+
`point_of_no_return`| This step prevents the processor running your steps to __NOT__ retry the steps if an error is raised. This is especially useful if you are automating a payment and you don't want the payment to be processed more than once.
|
149
|
+
|
111
150
|
## Mandatory configurations
|
112
151
|
```ruby
|
113
152
|
ClickSession.configure do | config |
|
@@ -119,7 +158,7 @@ end
|
|
119
158
|
|
120
159
|
```ruby
|
121
160
|
ClickSession.configure do | config |
|
122
|
-
config.
|
161
|
+
config.runner_class = MyCustomRunner
|
123
162
|
config.notifier_class = MyCustomNotifier
|
124
163
|
config.serializer_class = MyCustomSerializer
|
125
164
|
config.success_callback_url = "https://my.domain.com/webhook_success"
|
@@ -217,6 +256,12 @@ __Note:__ This requires you to add the S3 credentials and bucket name to the con
|
|
217
256
|
|
218
257
|
|
219
258
|
## Rake tasks
|
259
|
+
In order to run the included rake tasks, you need to load them in your applications `Rakefile`
|
260
|
+
```
|
261
|
+
spec = Gem::Specification.find_by_name 'click_session'
|
262
|
+
load "#{spec.gem_dir}/lib/tasks/click_session.rake"
|
263
|
+
```
|
264
|
+
|
220
265
|
### click_session:process_active
|
221
266
|
Processes all the active click sessions, meaning the ones that are ready to be run.
|
222
267
|
|
data/Rakefile
CHANGED
data/click_session.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["tobias@talltorp.se"]
|
11
11
|
spec.summary = "Navigates the web for you"
|
12
12
|
spec.description = "Navigates the web for you"
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/talltorp/click_session"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -16,8 +16,7 @@ module ClickSession
|
|
16
16
|
end
|
17
17
|
|
18
18
|
class Configuration
|
19
|
-
attr_accessor :
|
20
|
-
:success_callback_url,
|
19
|
+
attr_accessor :success_callback_url,
|
21
20
|
:failure_callback_url,
|
22
21
|
:serializer_class
|
23
22
|
|
@@ -37,8 +36,8 @@ module ClickSession
|
|
37
36
|
@model_class = klass.to_s
|
38
37
|
end
|
39
38
|
|
40
|
-
def
|
41
|
-
@
|
39
|
+
def runner_class
|
40
|
+
@runner_class ||=
|
42
41
|
begin
|
43
42
|
if Kernel.const_defined?(:ClickSessionRunner)
|
44
43
|
"ClickSessionRunner"
|
@@ -51,11 +50,11 @@ module ClickSession
|
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
|
-
@
|
53
|
+
@runner_class.constantize
|
55
54
|
end
|
56
55
|
|
57
|
-
def
|
58
|
-
@
|
56
|
+
def runner_class=(klass)
|
57
|
+
@runner_class = klass.to_s
|
59
58
|
end
|
60
59
|
|
61
60
|
def serializer_class
|
data/lib/click_session/sync.rb
CHANGED
@@ -32,7 +32,7 @@ module ClickSession
|
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
-
delegate :
|
35
|
+
delegate :notifier_class, to: :clicksession_configuration
|
36
36
|
|
37
37
|
def serialize_success_response
|
38
38
|
serializer.serialize_success(click_session)
|
@@ -43,11 +43,7 @@ module ClickSession
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def processor
|
46
|
-
@processor ||= ClickSession::WebRunnerProcessor.new
|
47
|
-
end
|
48
|
-
|
49
|
-
def configured_web_runner
|
50
|
-
@web_runner ||= processor_class.new
|
46
|
+
@processor ||= ClickSession::WebRunnerProcessor.new
|
51
47
|
end
|
52
48
|
|
53
49
|
def configured_notifier
|
@@ -9,11 +9,14 @@ module ClickSession
|
|
9
9
|
class WebRunner
|
10
10
|
include Capybara::DSL
|
11
11
|
|
12
|
-
|
12
|
+
attr_reader :processor
|
13
|
+
|
14
|
+
def initialize(processor)
|
13
15
|
Capybara.default_driver = ClickSession.configuration.driver_client
|
14
16
|
Capybara.javascript_driver = ClickSession.configuration.driver_client
|
15
17
|
Capybara.run_server = false
|
16
18
|
page = Capybara::Session.new(ClickSession.configuration.driver_client)
|
19
|
+
@processor = processor
|
17
20
|
end
|
18
21
|
|
19
22
|
def run(model)
|
@@ -31,6 +34,10 @@ module ClickSession
|
|
31
34
|
S3FileUploader.new.upload_file(@file_name)
|
32
35
|
end
|
33
36
|
|
37
|
+
def point_of_no_return
|
38
|
+
processor.stop_processing
|
39
|
+
end
|
40
|
+
|
34
41
|
private
|
35
42
|
def clear_cookies
|
36
43
|
browser = Capybara.current_session.driver.browser
|
@@ -2,13 +2,12 @@ require_relative "./exceptions"
|
|
2
2
|
|
3
3
|
module ClickSession
|
4
4
|
class WebRunnerProcessor
|
5
|
-
def initialize
|
6
|
-
@web_runner = web_runner
|
5
|
+
def initialize
|
7
6
|
@retries_made = 0
|
8
7
|
@making_requests = true
|
9
8
|
end
|
10
9
|
|
11
|
-
delegate :notifier_class, to: :clicksession_configuration
|
10
|
+
delegate :runner_class, :notifier_class, to: :clicksession_configuration
|
12
11
|
|
13
12
|
def process(model)
|
14
13
|
while can_make_requests?
|
@@ -26,23 +25,22 @@ module ClickSession
|
|
26
25
|
model
|
27
26
|
end
|
28
27
|
|
28
|
+
def stop_processing
|
29
|
+
@making_requests = false
|
30
|
+
end
|
31
|
+
|
29
32
|
delegate :save_screenshot, to: :web_runner
|
30
33
|
|
31
34
|
private
|
32
|
-
attr_reader :web_runner
|
33
35
|
|
34
36
|
def can_make_requests?
|
35
37
|
@making_requests
|
36
38
|
end
|
37
39
|
|
38
|
-
def stop_making_requests
|
39
|
-
@making_requests = false
|
40
|
-
end
|
41
|
-
|
42
40
|
def run_steps_in_browser_with(model)
|
43
41
|
web_runner.reset
|
44
42
|
web_runner.run(model)
|
45
|
-
|
43
|
+
stop_processing
|
46
44
|
end
|
47
45
|
|
48
46
|
def make_note_of_error(error)
|
@@ -54,6 +52,10 @@ module ClickSession
|
|
54
52
|
@retries_made > 2
|
55
53
|
end
|
56
54
|
|
55
|
+
def web_runner
|
56
|
+
@web_runner ||= runner_class.new(self)
|
57
|
+
end
|
58
|
+
|
57
59
|
def notifier
|
58
60
|
@notifier ||= notifier_class.new
|
59
61
|
end
|
@@ -6,16 +6,12 @@ namespace :click_session do
|
|
6
6
|
def processor_for(session_state)
|
7
7
|
ClickSession::ClickSessionProcessor.new(
|
8
8
|
session_state,
|
9
|
-
ClickSession::WebRunnerProcessor.new
|
9
|
+
ClickSession::WebRunnerProcessor.new,
|
10
10
|
ClickSession.configuration.notifier_class.new,
|
11
11
|
processor_options
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
def configured_web_runner
|
16
|
-
ClickSession.configuration.processor_class.new
|
17
|
-
end
|
18
|
-
|
19
15
|
def processor_options
|
20
16
|
if ClickSession.configuration.screenshot_enabled?
|
21
17
|
{
|
@@ -226,8 +226,7 @@ describe ClickSession::ClickSessionProcessor do
|
|
226
226
|
end
|
227
227
|
|
228
228
|
def mock_succesful_web_runner_processor
|
229
|
-
|
230
|
-
web_runner_processor_mock = ClickSession::WebRunnerProcessor.new(processor_stub)
|
229
|
+
web_runner_processor_mock = ClickSession::WebRunnerProcessor.new
|
231
230
|
|
232
231
|
allow(web_runner_processor_mock).
|
233
232
|
to receive(:process).
|
@@ -246,8 +245,7 @@ describe ClickSession::ClickSessionProcessor do
|
|
246
245
|
end
|
247
246
|
|
248
247
|
def mock_failing_web_runner_processor
|
249
|
-
|
250
|
-
web_runner_processor_mock = ClickSession::WebRunnerProcessor.new(processor_stub)
|
248
|
+
web_runner_processor_mock = ClickSession::WebRunnerProcessor.new
|
251
249
|
|
252
250
|
allow(web_runner_processor_mock).
|
253
251
|
to receive(:process).
|
@@ -8,7 +8,7 @@ describe ClickSession::Configuration do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'provides defaults' do
|
11
|
-
expect(ClickSession.configuration.
|
11
|
+
expect(ClickSession.configuration.runner_class).to eq(ClickSessionRunner)
|
12
12
|
expect(ClickSession.configuration.serializer_class).to eq(ClickSession::WebhookModelSerializer)
|
13
13
|
expect(ClickSession.configuration.notifier_class).to eq(ClickSession::Notifier)
|
14
14
|
expect(ClickSession.configuration.driver_client).to eq(:poltergeist)
|
@@ -24,7 +24,7 @@ describe ClickSession::Configuration do
|
|
24
24
|
it 'raises a helpful error if ClickSessionRunner is undefined' do
|
25
25
|
allow(Kernel).to receive_messages(const_defined?: false)
|
26
26
|
|
27
|
-
expect { ClickSession.configuration.
|
27
|
+
expect { ClickSession.configuration.runner_class }.
|
28
28
|
to raise_error(NameError, %r{https://github\.com/talltorp/click_session})
|
29
29
|
end
|
30
30
|
end
|
@@ -45,15 +45,15 @@ describe ClickSession::Configuration do
|
|
45
45
|
expect(ClickSession.configuration.model_class).to eq(DummyModelClass)
|
46
46
|
end
|
47
47
|
|
48
|
-
it "stores the
|
48
|
+
it "stores the runner_class" do
|
49
49
|
class DummyProcessorClass
|
50
50
|
end
|
51
51
|
|
52
52
|
ClickSession.configure do | config |
|
53
|
-
config.
|
53
|
+
config.runner_class = DummyProcessorClass
|
54
54
|
end
|
55
55
|
|
56
|
-
expect(ClickSession.configuration.
|
56
|
+
expect(ClickSession.configuration.runner_class).to eq(DummyProcessorClass)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "stores the serializer_class" do
|
@@ -11,9 +11,7 @@ describe ClickSession::Sync do
|
|
11
11
|
@notifier_stub = stub_notifier_in_configuration
|
12
12
|
mock_configuration_model_class_with(model)
|
13
13
|
|
14
|
-
|
15
|
-
mock_configuration_processor_class_with(processor_stub)
|
16
|
-
@web_runner_processor_stub = stub_web_runner_processor_with( processor_stub )
|
14
|
+
@web_runner_processor_stub = stub_web_runner_processor
|
17
15
|
end
|
18
16
|
|
19
17
|
context 'when processing is successful' do
|
@@ -85,13 +83,12 @@ describe ClickSession::Sync do
|
|
85
83
|
end
|
86
84
|
end
|
87
85
|
|
88
|
-
it "uses the
|
86
|
+
it "uses the notifier from the configuration" do
|
89
87
|
sync_click_session = ClickSession::Sync.new(model)
|
90
88
|
|
91
89
|
sync_click_session.run
|
92
90
|
|
93
91
|
expect(ClickSession.configuration).to have_received(:notifier_class)
|
94
|
-
expect(ClickSession.configuration).to have_received(:processor_class)
|
95
92
|
end
|
96
93
|
|
97
94
|
it "changes the state of the click_session to 'success_reported'" do
|
@@ -160,7 +157,7 @@ describe ClickSession::Sync do
|
|
160
157
|
and_return(processor_stub)
|
161
158
|
|
162
159
|
allow(ClickSession.configuration).
|
163
|
-
to receive(:
|
160
|
+
to receive(:web_ruunner_class).
|
164
161
|
and_return(processor_double)
|
165
162
|
end
|
166
163
|
|
@@ -171,7 +168,7 @@ describe ClickSession::Sync do
|
|
171
168
|
and_return(notifier_mock)
|
172
169
|
|
173
170
|
allow(ClickSession.configuration).
|
174
|
-
to receive(:
|
171
|
+
to receive(:runner_class).
|
175
172
|
and_return(notifier_double)
|
176
173
|
|
177
174
|
notifier_mock
|
@@ -184,8 +181,8 @@ describe ClickSession::Sync do
|
|
184
181
|
end
|
185
182
|
|
186
183
|
|
187
|
-
def
|
188
|
-
web_runner_processor_stub = ClickSession::WebRunnerProcessor.new
|
184
|
+
def stub_web_runner_processor
|
185
|
+
web_runner_processor_stub = ClickSession::WebRunnerProcessor.new
|
189
186
|
|
190
187
|
allow(web_runner_processor_stub).
|
191
188
|
to receive(:process).
|
@@ -14,29 +14,14 @@ describe ClickSession::WebRunnerProcessor do
|
|
14
14
|
|
15
15
|
context "when all requests are ok" do
|
16
16
|
it "returns the enriched model" do
|
17
|
-
|
18
|
-
|
17
|
+
web_runner_processor = ClickSession::WebRunnerProcessor.new
|
18
|
+
web_runner = ok_web_runner_stub(model, web_runner_processor)
|
19
|
+
stub_web_runner_in_configuration_with(web_runner)
|
19
20
|
|
20
21
|
enriched_model = web_runner_processor.process(model)
|
21
22
|
|
22
23
|
expect(enriched_model).to be_a(TestUnitModel)
|
23
24
|
end
|
24
|
-
|
25
|
-
def ok_web_runner_stub(model)
|
26
|
-
web_runner = ClickSessionRunner.new
|
27
|
-
allow(web_runner).
|
28
|
-
to receive(:run).
|
29
|
-
with(model)
|
30
|
-
|
31
|
-
allow(web_runner).
|
32
|
-
to receive(:reset)
|
33
|
-
|
34
|
-
allow(web_runner).
|
35
|
-
to receive(:save_screenshot).
|
36
|
-
and_return("a_file_name")
|
37
|
-
|
38
|
-
web_runner
|
39
|
-
end
|
40
25
|
end
|
41
26
|
|
42
27
|
context "when the placing of the order fails" do
|
@@ -46,8 +31,10 @@ describe ClickSession::WebRunnerProcessor do
|
|
46
31
|
|
47
32
|
describe "but third retry succeeds" do
|
48
33
|
it "the state has changed to 'processed'" do
|
49
|
-
|
50
|
-
|
34
|
+
web_runner_processor = ClickSession::WebRunnerProcessor.new
|
35
|
+
web_runner = third_time_ok_web_runner_stub(model, web_runner_processor)
|
36
|
+
stub_web_runner_in_configuration_with(web_runner)
|
37
|
+
|
51
38
|
|
52
39
|
enriched_model = web_runner_processor.process(model)
|
53
40
|
|
@@ -55,16 +42,18 @@ describe ClickSession::WebRunnerProcessor do
|
|
55
42
|
end
|
56
43
|
|
57
44
|
it "notifies about the rescued error" do
|
58
|
-
|
59
|
-
|
45
|
+
web_runner_processor = ClickSession::WebRunnerProcessor.new
|
46
|
+
web_runner = third_time_ok_web_runner_stub(model, web_runner_processor)
|
47
|
+
stub_web_runner_in_configuration_with(web_runner)
|
48
|
+
|
60
49
|
|
61
50
|
web_runner_processor.process(model)
|
62
51
|
|
63
52
|
expect(@notifier_stub).to have_received(:rescued_error).twice
|
64
53
|
end
|
65
54
|
|
66
|
-
def third_time_ok_web_runner_stub(model)
|
67
|
-
web_runner = ClickSessionRunner.new
|
55
|
+
def third_time_ok_web_runner_stub(model, processor)
|
56
|
+
web_runner = ClickSessionRunner.new(processor)
|
68
57
|
allow(web_runner).
|
69
58
|
to receive(:run).
|
70
59
|
with(model) do | args |
|
@@ -81,8 +70,10 @@ describe ClickSession::WebRunnerProcessor do
|
|
81
70
|
|
82
71
|
describe "when all retry attempts fail" do
|
83
72
|
it "raises an error and notifies the status_notifier of each error" do
|
84
|
-
|
85
|
-
|
73
|
+
web_runner_processor = ClickSession::WebRunnerProcessor.new
|
74
|
+
web_runner = all_requests_fail_web_runner_stub(model, web_runner_processor)
|
75
|
+
stub_web_runner_in_configuration_with(web_runner)
|
76
|
+
|
86
77
|
|
87
78
|
expect { web_runner_processor.process(model) }.
|
88
79
|
to raise_error(ClickSession::TooManyRetriesError)
|
@@ -90,54 +81,101 @@ describe ClickSession::WebRunnerProcessor do
|
|
90
81
|
to have_received(:rescued_error).
|
91
82
|
exactly(3).times
|
92
83
|
end
|
84
|
+
end
|
93
85
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
with(model).
|
100
|
-
and_raise(StandardError.new)
|
86
|
+
context "when further retries have been explicitly canceled" do
|
87
|
+
it "no more requests are made" do
|
88
|
+
web_runner_processor = ClickSession::WebRunnerProcessor.new
|
89
|
+
web_runner = ok_web_runner_stub(model, web_runner_processor)
|
90
|
+
stub_web_runner_in_configuration_with(web_runner)
|
101
91
|
|
102
|
-
|
103
|
-
|
92
|
+
web_runner_processor.stop_processing
|
93
|
+
enriched_model = web_runner_processor.process(model)
|
104
94
|
|
105
|
-
web_runner
|
95
|
+
expect(web_runner).not_to receive(:run)
|
106
96
|
end
|
107
97
|
end
|
108
98
|
end
|
109
|
-
|
110
|
-
def stub_notifier_in_configuration
|
111
|
-
notifier_double = class_double(ClickSession::Notifier)
|
112
|
-
notifier_stub = ClickSession::Notifier.new
|
113
|
-
|
114
|
-
# Stub the methods
|
115
|
-
allow(notifier_stub).
|
116
|
-
to receive(:rescued_error)
|
117
|
-
|
118
|
-
# Add the stub to the double
|
119
|
-
allow(notifier_double).
|
120
|
-
to receive(:new).
|
121
|
-
and_return(notifier_stub)
|
122
|
-
|
123
|
-
# Make the configuration return our double
|
124
|
-
allow(ClickSession.configuration).
|
125
|
-
to receive(:notifier_class).
|
126
|
-
and_return(notifier_double)
|
127
|
-
|
128
|
-
notifier_stub
|
129
|
-
end
|
130
99
|
end
|
131
100
|
|
132
101
|
describe "#save_screenshot_for" do
|
133
102
|
it "delegates :save_screenshot to WebRunner" do
|
134
|
-
|
135
|
-
|
136
|
-
|
103
|
+
web_runner_processor = ClickSession::WebRunnerProcessor.new
|
104
|
+
model = create(:test_unit_model)
|
105
|
+
web_runner = ok_web_runner_stub(model, web_runner_processor)
|
106
|
+
stub_web_runner_in_configuration_with(web_runner)
|
107
|
+
|
137
108
|
|
138
109
|
web_runner_processor.save_screenshot("a_unique_name")
|
139
110
|
|
140
111
|
expect(web_runner).to have_received(:save_screenshot).with("a_unique_name")
|
141
112
|
end
|
142
113
|
end
|
114
|
+
|
115
|
+
def stub_web_runner_in_configuration_with(web_runner_stub)
|
116
|
+
web_runner_double = class_double(ClickSession::WebRunner)
|
117
|
+
|
118
|
+
# Add the stub to the double
|
119
|
+
allow(web_runner_double).
|
120
|
+
to receive(:new).
|
121
|
+
and_return(web_runner_stub)
|
122
|
+
|
123
|
+
# Make the configuration return our double
|
124
|
+
allow(ClickSession.configuration).
|
125
|
+
to receive(:runner_class).
|
126
|
+
and_return(web_runner_double)
|
127
|
+
|
128
|
+
web_runner_stub
|
129
|
+
end
|
130
|
+
|
131
|
+
def stub_notifier_in_configuration
|
132
|
+
notifier_double = class_double(ClickSession::Notifier)
|
133
|
+
notifier_stub = ClickSession::Notifier.new
|
134
|
+
|
135
|
+
# Stub the methods
|
136
|
+
allow(notifier_stub).
|
137
|
+
to receive(:rescued_error)
|
138
|
+
|
139
|
+
# Add the stub to the double
|
140
|
+
allow(notifier_double).
|
141
|
+
to receive(:new).
|
142
|
+
and_return(notifier_stub)
|
143
|
+
|
144
|
+
# Make the configuration return our double
|
145
|
+
allow(ClickSession.configuration).
|
146
|
+
to receive(:notifier_class).
|
147
|
+
and_return(notifier_double)
|
148
|
+
|
149
|
+
notifier_stub
|
150
|
+
end
|
151
|
+
|
152
|
+
def ok_web_runner_stub(model, processor)
|
153
|
+
web_runner = ClickSessionRunner.new(processor)
|
154
|
+
allow(web_runner).
|
155
|
+
to receive(:run).
|
156
|
+
with(model)
|
157
|
+
|
158
|
+
allow(web_runner).
|
159
|
+
to receive(:reset)
|
160
|
+
|
161
|
+
allow(web_runner).
|
162
|
+
to receive(:save_screenshot).
|
163
|
+
and_return("a_file_name")
|
164
|
+
|
165
|
+
web_runner
|
166
|
+
end
|
167
|
+
|
168
|
+
def all_requests_fail_web_runner_stub(model, processor)
|
169
|
+
web_runner = ClickSessionRunner.new(processor)
|
170
|
+
|
171
|
+
allow(web_runner).
|
172
|
+
to receive(:run).
|
173
|
+
with(model).
|
174
|
+
and_raise(StandardError.new)
|
175
|
+
|
176
|
+
allow(web_runner).
|
177
|
+
to receive(:reset)
|
178
|
+
|
179
|
+
web_runner
|
180
|
+
end
|
143
181
|
end
|
@@ -2,6 +2,18 @@ require "spec_helper"
|
|
2
2
|
require "click_session/configuration"
|
3
3
|
|
4
4
|
describe ClickSession::WebRunner do
|
5
|
+
describe "#point_of_no_return" do
|
6
|
+
it "tells its processor it should stop retrying errors" do
|
7
|
+
processor = ClickSession::WebRunnerProcessor.new
|
8
|
+
allow(processor).to receive(:stop_processing)
|
9
|
+
web_runner = ClickSession::WebRunner.new(processor)
|
10
|
+
|
11
|
+
web_runner.point_of_no_return
|
12
|
+
|
13
|
+
expect(processor).to have_received(:stop_processing).once
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
5
17
|
describe "#save_screenshot" do
|
6
18
|
context 'when screenshot was successful' do
|
7
19
|
before :each do
|
@@ -27,7 +39,8 @@ describe ClickSession::WebRunner do
|
|
27
39
|
end
|
28
40
|
|
29
41
|
it "saves the screenshot in an s3 bucket" do
|
30
|
-
|
42
|
+
processor = ClickSession::WebRunnerProcessor.new
|
43
|
+
runner = ClickSession::WebRunner.new(processor)
|
31
44
|
stub_capybara
|
32
45
|
stub_s3
|
33
46
|
|
@@ -35,7 +48,8 @@ describe ClickSession::WebRunner do
|
|
35
48
|
end
|
36
49
|
|
37
50
|
it "returns the url to the saved screenshot" do
|
38
|
-
|
51
|
+
processor = ClickSession::WebRunnerProcessor.new
|
52
|
+
runner = ClickSession::WebRunner.new(processor)
|
39
53
|
stub_capybara
|
40
54
|
stub_s3
|
41
55
|
|
@@ -59,7 +73,8 @@ describe ClickSession::WebRunner do
|
|
59
73
|
|
60
74
|
context 'when the screenshot fails' do
|
61
75
|
it "does not try to save anything" do
|
62
|
-
|
76
|
+
processor = ClickSession::WebRunnerProcessor.new
|
77
|
+
runner = ClickSession::WebRunner.new(processor)
|
63
78
|
|
64
79
|
allow_any_instance_of(Capybara::Session).
|
65
80
|
to receive(:save_screenshot).
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: click_session
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Talltorp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -263,7 +263,7 @@ files:
|
|
263
263
|
- spec/support/dummy_web_runner.rb
|
264
264
|
- spec/support/schema.rb
|
265
265
|
- spec/support/test_unit_model.rb
|
266
|
-
homepage:
|
266
|
+
homepage: https://github.com/talltorp/click_session
|
267
267
|
licenses:
|
268
268
|
- MIT
|
269
269
|
metadata: {}
|