crabfarm 0.4.2 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/live-tools/instructions.html +17 -0
- data/assets/live-tools/tools.css +16 -0
- data/assets/live-tools/tools.js +41 -47
- data/assets/live-tools/welcome.html +18 -0
- data/lib/crabfarm/adapters/browser/abstract_webdriver.rb +19 -16
- data/lib/crabfarm/adapters/browser/phantom_js.rb +11 -11
- data/lib/crabfarm/assertion/fields.rb +8 -0
- data/lib/crabfarm/base_navigator.rb +4 -11
- data/lib/crabfarm/base_reducer.rb +5 -1
- data/lib/crabfarm/cli.rb +13 -13
- data/lib/crabfarm/context.rb +15 -3
- data/lib/crabfarm/factories/context.rb +24 -0
- data/lib/crabfarm/factories/decorable.rb +71 -0
- data/lib/crabfarm/factories/navigator.rb +14 -0
- data/lib/crabfarm/factories/reducer.rb +14 -0
- data/lib/crabfarm/factories/snapshot_reducer.rb +14 -0
- data/lib/crabfarm/http_client.rb +2 -5
- data/lib/crabfarm/live/context.rb +21 -0
- data/lib/crabfarm/live/controller.rb +20 -72
- data/lib/crabfarm/live/interactable.rb +6 -2
- data/lib/crabfarm/live/manager.rb +90 -18
- data/lib/crabfarm/live/navigator_runner.rb +43 -13
- data/lib/crabfarm/live/navigator_runner_direct.rb +39 -0
- data/lib/crabfarm/live/navigator_runner_rspec.rb +111 -0
- data/lib/crabfarm/live/reducer_runner.rb +61 -10
- data/lib/crabfarm/live/reducer_runner_direct.rb +41 -0
- data/lib/crabfarm/live/reducer_runner_rspec.rb +23 -0
- data/lib/crabfarm/live/watcher.rb +21 -7
- data/lib/crabfarm/modes/console.rb +1 -1
- data/lib/crabfarm/modes/live.rb +7 -4
- data/lib/crabfarm/modes/recorder/memento.rb +1 -5
- data/lib/crabfarm/modes/recorder/snapshot.rb +2 -2
- data/lib/crabfarm/modes/shared/interactive_decorator.rb +0 -1
- data/lib/crabfarm/modes/shared/snapshot_decorator.rb +17 -22
- data/lib/crabfarm/rspec/navigator_spec_helpers.rb +56 -0
- data/lib/crabfarm/rspec/reducer_spec_helpers.rb +29 -0
- data/lib/crabfarm/rspec/reducer_spy.rb +36 -0
- data/lib/crabfarm/rspec/reducer_spy_manager.rb +38 -0
- data/lib/crabfarm/rspec.rb +22 -66
- data/lib/crabfarm/support/phantom_runner.rb +77 -0
- data/lib/crabfarm/templates/Gemfile.erb +1 -0
- data/lib/crabfarm/transition_service.rb +3 -48
- data/lib/crabfarm/utils/console.rb +77 -0
- data/lib/crabfarm/utils/naming.rb +4 -3
- data/lib/crabfarm/utils/resolve.rb +39 -0
- data/lib/crabfarm/utils/rspec_runner.rb +54 -0
- data/lib/crabfarm/{live/helpers.rb → utils/webdriver.rb} +3 -3
- data/lib/crabfarm/version.rb +1 -1
- data/lib/crabfarm.rb +24 -3
- metadata +23 -6
- data/lib/crabfarm/context_factory.rb +0 -32
- data/lib/crabfarm/global_state.rb +0 -22
- data/lib/crabfarm/phantom_runner.rb +0 -75
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'crabfarm/utils/webdriver'
|
2
|
+
|
3
|
+
module Crabfarm
|
4
|
+
module Live
|
5
|
+
class Context < Crabfarm::Context
|
6
|
+
|
7
|
+
def initialize(_manager)
|
8
|
+
@manager = _manager
|
9
|
+
end
|
10
|
+
|
11
|
+
def proxy
|
12
|
+
"127.0.0.1:#{@manager.proxy_port}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def viewer
|
16
|
+
@manager
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,35 +1,25 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require 'crabfarm/modes/console'
|
5
|
-
|
6
|
-
require 'crabfarm/support/webdriver_factory'
|
7
|
-
require 'crabfarm/crabtrap_runner'
|
8
|
-
|
9
|
-
require 'crabfarm/live/helpers.rb'
|
10
|
-
require 'crabfarm/live/navigator_runner.rb'
|
11
|
-
require 'crabfarm/live/reducer_runner.rb'
|
1
|
+
require 'crabfarm/utils/console'
|
2
|
+
require 'crabfarm/live/navigator_runner'
|
3
|
+
require 'crabfarm/live/reducer_runner'
|
12
4
|
|
13
5
|
module Crabfarm
|
14
6
|
module Live
|
15
7
|
class Controller
|
16
8
|
|
17
|
-
Colors = Crabfarm::Modes::Console::Colors
|
18
|
-
|
19
|
-
class LiveWarning < StandardError; end
|
20
|
-
|
21
9
|
def initialize(_manager)
|
22
10
|
@manager = _manager
|
23
11
|
end
|
24
12
|
|
13
|
+
def display_external_error(_exc)
|
14
|
+
@manager.reset_driver_status
|
15
|
+
display_error_feedback _exc
|
16
|
+
end
|
17
|
+
|
25
18
|
def execute_live(_class)
|
26
19
|
begin
|
27
20
|
runner = build_runner_for _class
|
28
21
|
prepare_session_for runner
|
29
|
-
|
30
|
-
display_feedback runner, elapsed
|
31
|
-
rescue LiveWarning => exc
|
32
|
-
display_warning_feedback exc
|
22
|
+
runner.execute
|
33
23
|
rescue Exception => exc
|
34
24
|
display_error_feedback exc
|
35
25
|
ensure
|
@@ -40,9 +30,9 @@ module Crabfarm
|
|
40
30
|
private
|
41
31
|
|
42
32
|
def build_runner_for(_class)
|
43
|
-
raise
|
33
|
+
raise ArgumentError.new "'#{_class.to_s} is not Interactable" unless _class < Interactable
|
44
34
|
|
45
|
-
|
35
|
+
Utils::Console.operation "Launching #{_class.to_s}"
|
46
36
|
|
47
37
|
runner = if _class.live_delegate
|
48
38
|
build_runner_for _class.live_delegate
|
@@ -52,8 +42,8 @@ module Crabfarm
|
|
52
42
|
elsif _class < BaseReducer
|
53
43
|
ReducerRunner
|
54
44
|
else
|
55
|
-
raise
|
56
|
-
end.new _class
|
45
|
+
raise ConfigurationError.new "Don't know how to run #{_class.to_s}, you should provide a navigator or reducer as delegate."
|
46
|
+
end.new @manager, _class
|
57
47
|
end
|
58
48
|
|
59
49
|
runner.dsl.instance_eval(&_class.live_setup) if _class.live_setup
|
@@ -61,65 +51,23 @@ module Crabfarm
|
|
61
51
|
end
|
62
52
|
|
63
53
|
def prepare_session_for(_runner)
|
64
|
-
@manager.
|
65
|
-
if _runner.memento
|
66
|
-
@manager.start_crabtrap :replay, memento_path(_runner.memento)
|
67
|
-
else
|
68
|
-
@manager.start_crabtrap :pass
|
69
|
-
end
|
54
|
+
@manager.reset_driver_status
|
70
55
|
end
|
71
56
|
|
72
57
|
def clean_up_session
|
73
58
|
# leave crabtrap running for debugging purposes.
|
74
59
|
end
|
75
60
|
|
76
|
-
def display_feedback(_runner, _elapsed)
|
77
|
-
load_web_ui
|
78
|
-
|
79
|
-
@manager.primary_driver.execute_script(
|
80
|
-
"window.crabfarm.showResults(arguments[0], arguments[1]);",
|
81
|
-
_runner.output,
|
82
|
-
_elapsed.real
|
83
|
-
);
|
84
|
-
|
85
|
-
puts _runner.output.to_s.color Colors::RESULT
|
86
|
-
puts "Completed in #{_elapsed.real} s".color Colors::NOTICE
|
87
|
-
end
|
88
|
-
|
89
61
|
def display_error_feedback(_exc)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
62
|
+
@manager.inject_web_tools
|
63
|
+
@manager.show_dialog(
|
64
|
+
:error,
|
65
|
+
'Crawler error!',
|
94
66
|
"#{_exc.class.to_s}: #{_exc.to_s}",
|
95
67
|
_exc.backtrace.join("\n")
|
96
|
-
)
|
97
|
-
|
98
|
-
puts "#{_exc.class.to_s}: #{_exc.to_s}".color Colors::ERROR
|
99
|
-
puts _exc.backtrace
|
100
|
-
end
|
101
|
-
|
102
|
-
def display_warning_feedback(_exc)
|
103
|
-
load_web_ui
|
104
|
-
puts "Warning: #{_exc.to_s}".color Colors::WARNING
|
105
|
-
end
|
106
|
-
|
107
|
-
def load_web_ui
|
108
|
-
Helpers.inject_style @manager.primary_driver, 'https://www.crabtrap.io/selectorgadget_combined.css'
|
109
|
-
Helpers.inject_style @manager.primary_driver, 'https://www.crabtrap.io/tools.css'
|
110
|
-
Helpers.inject_script @manager.primary_driver, 'https://www.crabtrap.io/selectorgadget_combined.js'
|
111
|
-
Helpers.inject_script @manager.primary_driver, 'https://www.crabtrap.io/tools.js'
|
112
|
-
wait_for_injection
|
113
|
-
end
|
114
|
-
|
115
|
-
def wait_for_injection
|
116
|
-
while @manager.primary_driver.execute_script "return (typeof window.crabfarm === 'undefined');"
|
117
|
-
sleep 1.0
|
118
|
-
end
|
119
|
-
end
|
68
|
+
)
|
120
69
|
|
121
|
-
|
122
|
-
File.join(GlobalState.mementos_path, _name + '.json.gz')
|
70
|
+
Utils::Console.exception _exc
|
123
71
|
end
|
124
72
|
|
125
73
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'crabfarm/
|
1
|
+
require 'crabfarm/utils/webdriver'
|
2
2
|
|
3
3
|
module Crabfarm
|
4
4
|
module Live
|
@@ -15,6 +15,10 @@ module Crabfarm
|
|
15
15
|
@setup = _setup
|
16
16
|
end
|
17
17
|
|
18
|
+
def live_rspec?
|
19
|
+
@setup.nil?
|
20
|
+
end
|
21
|
+
|
18
22
|
def live_delegate
|
19
23
|
@delegate
|
20
24
|
end
|
@@ -37,7 +41,7 @@ module Crabfarm
|
|
37
41
|
_elements = Crabfarm.live.primary_driver.find_elements(css: _elements)
|
38
42
|
end
|
39
43
|
|
40
|
-
|
44
|
+
Utils::Webdriver.set_style _elements, "border: 3px solid yellow;"
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
require 'crabfarm/utils/console'
|
3
|
+
require 'crabfarm/utils/webdriver'
|
1
4
|
require 'crabfarm/support/webdriver_factory'
|
2
5
|
require 'crabfarm/crabtrap_runner'
|
3
6
|
|
@@ -5,9 +8,11 @@ module Crabfarm
|
|
5
8
|
module Live
|
6
9
|
class Manager
|
7
10
|
|
11
|
+
INJECTION_TM = 5 # seconds
|
12
|
+
|
8
13
|
def initialize
|
9
14
|
@port = Utils::PortDiscovery.find_available_port
|
10
|
-
@
|
15
|
+
@driver_name = Crabfarm.config.recorder_driver
|
11
16
|
end
|
12
17
|
|
13
18
|
def proxy_port
|
@@ -15,6 +20,7 @@ module Crabfarm
|
|
15
20
|
end
|
16
21
|
|
17
22
|
def start
|
23
|
+
set_memento
|
18
24
|
load_primary_driver
|
19
25
|
end
|
20
26
|
|
@@ -27,26 +33,39 @@ module Crabfarm
|
|
27
33
|
@driver
|
28
34
|
end
|
29
35
|
|
30
|
-
def
|
31
|
-
# TODO:
|
32
|
-
|
36
|
+
def reset_driver_status
|
37
|
+
# TODO: manage driver handles and recreate driver if needed
|
38
|
+
primary_driver.get('https://www.crabtrap.io/instructions.html')
|
33
39
|
end
|
34
40
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
41
|
+
def block_requests
|
42
|
+
begin
|
43
|
+
stop_crabtrap
|
44
|
+
return yield
|
45
|
+
ensure
|
46
|
+
set_memento nil
|
47
|
+
end
|
48
|
+
end
|
38
49
|
|
39
|
-
|
40
|
-
options = {
|
41
|
-
mode: _mode,
|
42
|
-
bucket_path: _memento_path,
|
43
|
-
port: @port,
|
44
|
-
virtual: File.expand_path('./assets/live-tools', Crabfarm.root)
|
45
|
-
}
|
50
|
+
def set_memento(_memento=nil)
|
46
51
|
|
47
|
-
|
48
|
-
|
52
|
+
options = if _memento
|
53
|
+
path = Utils::Resolve.memento_path _memento
|
54
|
+
raise ConfigurationError.new "No memento found at #{path}" unless File.exists? path
|
55
|
+
{ mode: :replay, bucket_path: path }
|
56
|
+
else
|
57
|
+
{ mode: :pass }
|
49
58
|
end
|
59
|
+
|
60
|
+
options.merge!({
|
61
|
+
port: @port,
|
62
|
+
virtual: File.expand_path('./assets/live-tools', Crabfarm.root)
|
63
|
+
})
|
64
|
+
|
65
|
+
stop_crabtrap
|
66
|
+
@crabtrap = CrabtrapRunner.new config.crabtrap_config.merge(options)
|
67
|
+
@crabtrap.start
|
68
|
+
|
50
69
|
end
|
51
70
|
|
52
71
|
def stop_crabtrap
|
@@ -56,18 +75,65 @@ module Crabfarm
|
|
56
75
|
else nil end
|
57
76
|
end
|
58
77
|
|
78
|
+
def inject_web_tools
|
79
|
+
Utils::Console.trap_errors 'injecting web tools' do
|
80
|
+
Utils::Webdriver.inject_style primary_driver, 'https://www.crabtrap.io/selectorgadget_combined.css'
|
81
|
+
Utils::Webdriver.inject_style primary_driver, 'https://www.crabtrap.io/tools.css'
|
82
|
+
Utils::Webdriver.inject_script primary_driver, 'https://www.crabtrap.io/selectorgadget_combined.js'
|
83
|
+
Utils::Webdriver.inject_script primary_driver, 'https://www.crabtrap.io/tools.js'
|
84
|
+
Timeout::timeout(INJECTION_TM) { wait_for_injection }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def show_dialog(_status, _title, _subtitle, _content=nil, _content_type=:text)
|
89
|
+
Utils::Console.trap_errors 'loading web dialog' do
|
90
|
+
primary_driver.execute_script(
|
91
|
+
"window.crabfarm.showDialog.apply(null, arguments);",
|
92
|
+
_status.to_s,
|
93
|
+
_title,
|
94
|
+
_subtitle,
|
95
|
+
_content,
|
96
|
+
_content_type.to_s
|
97
|
+
);
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def show_selector_gadget()
|
102
|
+
Utils::Console.trap_errors 'loading selector gadget' do
|
103
|
+
primary_driver.execute_script(
|
104
|
+
'window.crabfarm.showSelectorGadget();'
|
105
|
+
)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Viewer implementation
|
110
|
+
|
111
|
+
def attach(_primary=true)
|
112
|
+
if _primary then primary_driver else build_driver end
|
113
|
+
end
|
114
|
+
|
115
|
+
def detach(_driver)
|
116
|
+
if _driver != primary_driver
|
117
|
+
_driver.quit rescue nil
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
59
121
|
private
|
60
122
|
|
61
123
|
def load_primary_driver
|
62
124
|
@driver = build_driver
|
125
|
+
@driver.get('https://www.crabtrap.io/welcome.html')
|
63
126
|
end
|
64
127
|
|
65
128
|
def release_primary_driver
|
66
|
-
|
129
|
+
unless @driver.nil?
|
130
|
+
@driver.quit rescue nil
|
131
|
+
@driver = nil
|
132
|
+
end
|
67
133
|
end
|
68
134
|
|
69
135
|
def build_driver
|
70
|
-
case @
|
136
|
+
case @driver_name
|
71
137
|
when :firefox
|
72
138
|
Crabfarm::Support::WebdriverFactory.build_firefox_driver driver_config
|
73
139
|
when :chrome
|
@@ -85,6 +151,12 @@ module Crabfarm
|
|
85
151
|
Crabfarm.config
|
86
152
|
end
|
87
153
|
|
154
|
+
def wait_for_injection
|
155
|
+
while primary_driver.execute_script "return (typeof window.crabfarm === 'undefined');"
|
156
|
+
sleep 1.0
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
88
160
|
end
|
89
161
|
end
|
90
162
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'crabfarm/live/context'
|
2
|
+
require 'crabfarm/live/navigator_runner_direct'
|
3
|
+
require 'crabfarm/live/navigator_runner_rspec'
|
2
4
|
|
3
5
|
module Crabfarm
|
4
6
|
module Live
|
@@ -11,11 +13,13 @@ module Crabfarm
|
|
11
13
|
@runner = _runner
|
12
14
|
end
|
13
15
|
|
14
|
-
def_delegators :@runner, :use_memento, :use_params, :clear_params, :navigate_to
|
16
|
+
def_delegators :@runner, :use_memento, :use_params, :clear_params, :use_rspec, :navigate_to
|
15
17
|
end
|
16
18
|
|
17
|
-
def initialize(_target)
|
19
|
+
def initialize(_manager, _target)
|
20
|
+
@manager = _manager
|
18
21
|
@target = _target
|
22
|
+
@rspec = true
|
19
23
|
@params = {}
|
20
24
|
end
|
21
25
|
|
@@ -29,32 +33,44 @@ module Crabfarm
|
|
29
33
|
|
30
34
|
def use_memento(_memento)
|
31
35
|
@memento = _memento
|
36
|
+
@rspec = false
|
32
37
|
end
|
33
38
|
|
34
39
|
def use_params(_params={})
|
35
40
|
@params = @params.merge _params
|
41
|
+
@rspec = false
|
36
42
|
end
|
37
43
|
|
38
44
|
def clear_params
|
39
45
|
@params = {}
|
46
|
+
@rspec = false
|
47
|
+
end
|
48
|
+
|
49
|
+
def use_rspec
|
50
|
+
@rspec = true
|
40
51
|
end
|
41
52
|
|
42
53
|
def navigate_to(_navigator, _params={})
|
54
|
+
# TODO.
|
55
|
+
end
|
56
|
+
|
57
|
+
def prepare(_memento) # decorator
|
58
|
+
@manager.set_memento _memento
|
59
|
+
Context.new @manager
|
43
60
|
end
|
44
61
|
|
45
62
|
def execute
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
ensure
|
51
|
-
context.release
|
63
|
+
strategy = if @rspec
|
64
|
+
NavigatorRunnerRSpec.new @manager, @target
|
65
|
+
else
|
66
|
+
NavigatorRunnerDirect.new @manager, memento, @target, @params
|
52
67
|
end
|
53
|
-
end
|
54
68
|
|
55
|
-
|
56
|
-
|
57
|
-
|
69
|
+
Factories::Context.with_decorator self do
|
70
|
+
strategy.execute
|
71
|
+
end
|
72
|
+
|
73
|
+
strategy.show_results
|
58
74
|
end
|
59
75
|
|
60
76
|
private
|
@@ -63,6 +79,20 @@ module Crabfarm
|
|
63
79
|
Utils::Naming.route_from_constant(_class.to_s).join(File::SEPARATOR)
|
64
80
|
end
|
65
81
|
|
82
|
+
def show_result
|
83
|
+
@manager.inject_web_tools
|
84
|
+
@manager.show_dialog(
|
85
|
+
:neutral,
|
86
|
+
'Navigation completed!',
|
87
|
+
"The page was scrapped in #{@elapsed.real} seconds",
|
88
|
+
@transition.document.to_json,
|
89
|
+
:json
|
90
|
+
)
|
91
|
+
|
92
|
+
Utils::Console.json_result @transition.document
|
93
|
+
Utils::Console.info "Completed in #{@elapsed.real} s"
|
94
|
+
end
|
95
|
+
|
66
96
|
end
|
67
97
|
end
|
68
98
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'crabfarm/utils/console'
|
3
|
+
|
4
|
+
module Crabfarm
|
5
|
+
module Live
|
6
|
+
class NavigatorRunnerDirect
|
7
|
+
|
8
|
+
def initialize(_manager, _memento, _target, _params)
|
9
|
+
@manager = _manager
|
10
|
+
@memento = _memento
|
11
|
+
@target = _target
|
12
|
+
@params = _params
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute
|
16
|
+
Crabfarm.with_context @memento do |ctx|
|
17
|
+
@elapsed = Benchmark.measure do
|
18
|
+
@transition = TransitionService.transition ctx, @target, (@params || {})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def show_results
|
24
|
+
@manager.inject_web_tools
|
25
|
+
@manager.show_dialog(
|
26
|
+
:neutral,
|
27
|
+
'Navigation completed!',
|
28
|
+
"The page was scrapped in #{@elapsed.real} seconds",
|
29
|
+
@transition.document.to_json,
|
30
|
+
:json
|
31
|
+
)
|
32
|
+
|
33
|
+
Utils::Console.json_result @transition.document
|
34
|
+
Utils::Console.info "Completed in #{@elapsed.real} s"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'crabfarm/utils/console'
|
2
|
+
require 'crabfarm/utils/rspec_runner'
|
3
|
+
|
4
|
+
module Crabfarm
|
5
|
+
module Live
|
6
|
+
class NavigatorRunnerRSpec
|
7
|
+
|
8
|
+
def initialize(_manager, _target)
|
9
|
+
@manager = _manager
|
10
|
+
@target = _target
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute
|
14
|
+
@examples = Factories::Context.with_decorator self do
|
15
|
+
Utils::RSpecRunner.run_spec_for spec_for(@target), live: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def show_results
|
20
|
+
@manager.inject_web_tools
|
21
|
+
if @examples.count == 0
|
22
|
+
show_empty_warning
|
23
|
+
elsif @examples.count == 1
|
24
|
+
show_example_output @examples.first
|
25
|
+
else
|
26
|
+
show_example_summary @examples
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def spec_for(_class)
|
33
|
+
route = Utils::Naming.route_from_constant(_class.to_s)
|
34
|
+
route = route.join(File::SEPARATOR)
|
35
|
+
route = route + '_spec.rb'
|
36
|
+
File.join('spec','navigators', route)
|
37
|
+
end
|
38
|
+
|
39
|
+
def show_empty_warning
|
40
|
+
@manager.show_dialog(
|
41
|
+
:warning,
|
42
|
+
'No examples were found!',
|
43
|
+
'Make sure you have tagged some specs with live: true'
|
44
|
+
)
|
45
|
+
|
46
|
+
Utils::Console.warning 'No examples were found!'
|
47
|
+
end
|
48
|
+
|
49
|
+
def show_example_summary(_examples)
|
50
|
+
total = _examples.count
|
51
|
+
error = _examples.select { |e| !e.exception.nil? }.count
|
52
|
+
errored = (error > 0)
|
53
|
+
|
54
|
+
if error > 0
|
55
|
+
@manager.show_dialog(
|
56
|
+
:error,
|
57
|
+
'FAILED',
|
58
|
+
"#{error} of #{total} tests failed"
|
59
|
+
)
|
60
|
+
|
61
|
+
Utils::Console.error "#{total} examples, #{error} failures"
|
62
|
+
else
|
63
|
+
@manager.show_dialog(
|
64
|
+
:success,
|
65
|
+
'SUCCESS',
|
66
|
+
"All #{total} tests passed!"
|
67
|
+
)
|
68
|
+
|
69
|
+
Utils::Console.result "#{total} examples, 0 failures"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def show_example_output(_example)
|
74
|
+
|
75
|
+
handle_standard_errors _example
|
76
|
+
|
77
|
+
if _example.exception
|
78
|
+
@manager.show_dialog(
|
79
|
+
:error,
|
80
|
+
'FAILED',
|
81
|
+
_example.exception.to_s,
|
82
|
+
_example.metadata[:result].to_json,
|
83
|
+
:json
|
84
|
+
)
|
85
|
+
|
86
|
+
Utils::Console.error "1 example, 1 failure"
|
87
|
+
Utils::Console.error _example.exception.to_s
|
88
|
+
Utils::Console.json_result _example.metadata[:result]
|
89
|
+
else
|
90
|
+
@manager.show_dialog(
|
91
|
+
:success,
|
92
|
+
'SUCCESS',
|
93
|
+
"\"#{_example.full_description}\"",
|
94
|
+
_example.metadata[:result].to_json,
|
95
|
+
:json
|
96
|
+
)
|
97
|
+
|
98
|
+
Utils::Console.result "1 example, 0 failures"
|
99
|
+
Utils::Console.json_result _example.metadata[:result]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def handle_standard_errors(_example)
|
104
|
+
if _example.exception and not _example.exception.is_a? ::RSpec::Expectations::ExpectationNotMetError
|
105
|
+
raise _example.exception
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -1,20 +1,71 @@
|
|
1
|
+
require 'crabfarm/live/reducer_runner_direct'
|
2
|
+
require 'crabfarm/live/reducer_runner_rspec'
|
3
|
+
|
1
4
|
module Crabfarm
|
2
5
|
module Live
|
3
|
-
class ReducerRunner
|
6
|
+
class ReducerRunner
|
7
|
+
|
8
|
+
class Dsl
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
def initialize(_runner)
|
12
|
+
@runner = _runner
|
13
|
+
end
|
14
|
+
|
15
|
+
def_delegators :@runner, :use_snapshot, :use_params, :clear_params, :use_rspec
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(_manager, _target)
|
19
|
+
@manager = _manager
|
20
|
+
@target = _target
|
21
|
+
@rspec = true
|
22
|
+
@params = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def dsl
|
26
|
+
@dsl ||= Dsl.new self
|
27
|
+
end
|
28
|
+
|
29
|
+
def snapshot
|
30
|
+
if @snapshot.nil? then snapshot_for(@target) else @snapshot end
|
31
|
+
end
|
32
|
+
|
33
|
+
def use_snapshot(_snapshot)
|
34
|
+
@snapshot = _snapshot
|
35
|
+
@rspec = false
|
36
|
+
end
|
4
37
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
38
|
+
def use_params(_params={})
|
39
|
+
@params = @params.merge _params
|
40
|
+
@rspec = false
|
8
41
|
end
|
9
42
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
43
|
+
def clear_params
|
44
|
+
@params = {}
|
45
|
+
@rspec = false
|
46
|
+
end
|
47
|
+
|
48
|
+
def use_rspec
|
49
|
+
@rspec = true
|
50
|
+
end
|
51
|
+
|
52
|
+
def prepare(_class, _path, _params) # decorator
|
53
|
+
@manager.primary_driver.get("file://#{_path}")
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def execute
|
58
|
+
strategy = if @rspec
|
59
|
+
ReducerRunnerRSpec.new @manager, @target
|
60
|
+
else
|
61
|
+
ReducerRunnerDirect.new @manager, snapshot, @target, @params
|
62
|
+
end
|
63
|
+
|
64
|
+
Factories::SnapshotReducer.with_decorator self do
|
65
|
+
@manager.block_requests { strategy.execute }
|
15
66
|
end
|
16
67
|
|
17
|
-
|
68
|
+
strategy.show_results
|
18
69
|
end
|
19
70
|
|
20
71
|
end
|