crabfarm 0.2.5 → 0.3.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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/crabfarm.rb +17 -18
  3. data/lib/crabfarm/adapters/browser/abstract_webdriver.rb +60 -0
  4. data/lib/crabfarm/adapters/browser/chrome.rb +24 -0
  5. data/lib/crabfarm/adapters/browser/firefox.rb +26 -0
  6. data/lib/crabfarm/adapters/browser/noop.rb +25 -0
  7. data/lib/crabfarm/adapters/browser/phantom_js.rb +59 -0
  8. data/lib/crabfarm/adapters/browser/remote_webdriver.rb +31 -0
  9. data/lib/crabfarm/adapters/driver_wrapper/capybara.rb +11 -0
  10. data/lib/crabfarm/adapters/driver_wrapper/surfer.rb +13 -0
  11. data/lib/crabfarm/adapters/{browser → driver_wrapper}/watir.rb +7 -3
  12. data/lib/crabfarm/adapters/parser/nokogiri.rb +17 -15
  13. data/lib/crabfarm/adapters/parser/pdf_reader.rb +14 -12
  14. data/lib/crabfarm/assertion/fields.rb +85 -0
  15. data/lib/crabfarm/base_navigator.rb +78 -0
  16. data/lib/crabfarm/base_reducer.rb +68 -0
  17. data/lib/crabfarm/base_struct.rb +17 -0
  18. data/lib/crabfarm/cli.rb +18 -8
  19. data/lib/crabfarm/configuration.rb +24 -51
  20. data/lib/crabfarm/context.rb +19 -43
  21. data/lib/crabfarm/crabtrap_context.rb +4 -11
  22. data/lib/crabfarm/driver_pool.rb +32 -0
  23. data/lib/crabfarm/dsl/surfer/surf_context.rb +5 -25
  24. data/lib/crabfarm/engines/async_state_manager.rb +1 -1
  25. data/lib/crabfarm/engines/sync_state_manager.rb +1 -1
  26. data/lib/crabfarm/forked_navigator.rb +31 -0
  27. data/lib/crabfarm/modes/console.rb +4 -4
  28. data/lib/crabfarm/modes/generator.rb +24 -11
  29. data/lib/crabfarm/rspec.rb +26 -24
  30. data/lib/crabfarm/strategies.rb +15 -9
  31. data/lib/crabfarm/templates/Crabfile.erb +21 -26
  32. data/lib/crabfarm/templates/Gemfile.erb +6 -0
  33. data/lib/crabfarm/templates/navigator.rb.erb +20 -0
  34. data/lib/crabfarm/templates/{state_spec.rb.erb → navigator_spec.rb.erb} +1 -1
  35. data/lib/crabfarm/templates/{parser.rb.erb → reducer.rb.erb} +4 -4
  36. data/lib/crabfarm/templates/{parser_spec.rb.erb → reducer_spec.rb.erb} +1 -1
  37. data/lib/crabfarm/templates/struct.rb.erb +12 -0
  38. data/lib/crabfarm/transition_service.rb +20 -7
  39. data/lib/crabfarm/version.rb +1 -1
  40. metadata +50 -48
  41. data/lib/crabfarm/adapters/browser/capybara.rb +0 -7
  42. data/lib/crabfarm/adapters/browser/surfer.rb +0 -9
  43. data/lib/crabfarm/adapters/output/hash.rb +0 -11
  44. data/lib/crabfarm/adapters/output/jbuilder.rb +0 -11
  45. data/lib/crabfarm/adapters/output/ostruct.rb +0 -14
  46. data/lib/crabfarm/base_parser.rb +0 -59
  47. data/lib/crabfarm/base_state.rb +0 -112
  48. data/lib/crabfarm/default_driver_factory.rb +0 -86
  49. data/lib/crabfarm/driver_bucket.rb +0 -42
  50. data/lib/crabfarm/driver_bucket_pool.rb +0 -26
  51. data/lib/crabfarm/forked_state.rb +0 -38
  52. data/lib/crabfarm/mocks/noop_driver.rb +0 -6
  53. data/lib/crabfarm/phantom_driver_factory.rb +0 -33
  54. data/lib/crabfarm/templates/state.rb.erb +0 -8
@@ -1,86 +0,0 @@
1
- module Crabfarm
2
- class DefaultDriverFactory
3
-
4
- def initialize(_config={})
5
- @config = _config
6
- end
7
-
8
- def build_driver(_session_id)
9
-
10
- raise ConfigurationError.new 'must provide a webdriver type' unless config_present? :name
11
- driver_name = @config[:name].to_sym
12
-
13
- driver = case driver_name
14
- when :noop
15
- require "crabfarm/mocks/noop_driver"
16
- driver = Crabfarm::Mocks::NoopDriver.new # TODO: improve dummy driver...
17
- when :remote
18
- load_remote_driver
19
- when :firefox
20
- load_firefox_driver
21
- when :chrome
22
- load_chrome_driver
23
- else
24
- load_other_driver driver_name
25
- end
26
-
27
- # apply browser configuration to new driver
28
- driver.manage.window.resize_to(@config[:window_width], @config[:window_height]) rescue nil
29
-
30
- return driver
31
- end
32
-
33
- def load_remote_driver
34
- client = Selenium::WebDriver::Remote::Http::Default.new
35
- client.timeout = @config[:remote_timeout]
36
-
37
- if config_present? :proxy
38
- client.proxy = Selenium::WebDriver::Proxy.new({
39
- :http => @config[:proxy],
40
- :ssl => @config[:proxy]
41
- })
42
- end
43
-
44
- Selenium::WebDriver.for(:remote, {
45
- :url => @config[:remote_host],
46
- :http_client => client,
47
- :desired_capabilities => @config[:capabilities]
48
- })
49
- end
50
-
51
- def load_firefox_driver
52
- profile = Selenium::WebDriver::Firefox::Profile.new
53
-
54
- if config_present? :proxy
55
- profile.proxy = Selenium::WebDriver::Proxy.new({
56
- :http => @config[:proxy],
57
- :ssl => @config[:proxy]
58
- })
59
- end
60
-
61
- Selenium::WebDriver.for :firefox, :profile => profile
62
- end
63
-
64
- def load_chrome_driver
65
- switches = []
66
-
67
- if config_present? :proxy
68
- switches << "--proxy-server=#{@config[:proxy]}"
69
- switches << "--ignore-certificate-errors"
70
- end
71
-
72
- Selenium::WebDriver.for :chrome, :switches => switches
73
- end
74
-
75
- def load_other_driver(_name)
76
- raise ConfigurationError.new 'default driver does not support proxy' if config_present? :proxy
77
-
78
- Selenium::WebDriver.for _name.to_sym
79
- end
80
-
81
- def config_present?(_key)
82
- not (@config[_key].nil? or @config[_key].empty?)
83
- end
84
-
85
- end
86
- end
@@ -1,42 +0,0 @@
1
- module Crabfarm
2
- class DriverBucket
3
-
4
- attr_reader :session_id
5
-
6
- def initialize(_session_id, _factory)
7
- @session_id = _session_id
8
- @factory = _factory
9
- @driver = nil
10
- end
11
-
12
- def setup(_factory)
13
- reset
14
- @factory = _factory
15
- end
16
-
17
- def original
18
- @driver ||= @factory.build_driver(@session_id)
19
- end
20
-
21
- def reset
22
- if @driver
23
- @driver.quit rescue nil
24
- @driver = nil
25
- end
26
- self
27
- end
28
-
29
- # forward every missing method to actual driver
30
-
31
- def respond_to?(symbol, include_priv=false)
32
- original.respond_to?(symbol, include_priv)
33
- end
34
-
35
- private
36
-
37
- def method_missing(method, *args, &block)
38
- original.__send__(method, *args, &block)
39
- end
40
-
41
- end
42
- end
@@ -1,26 +0,0 @@
1
- module Crabfarm
2
- class DriverBucketPool
3
-
4
- def initialize(_factory=nil)
5
- @factory = _factory || DefaultDriverFactory.new(Crabfarm.config.driver_config)
6
- @buckets = Hash.new
7
- end
8
-
9
- def driver(_session_id=nil)
10
- _session_id ||= :default_driver
11
- bucket = @buckets[_session_id.to_sym]
12
- bucket = @buckets[_session_id.to_sym] = DriverBucket.new(_session_id, @factory) if bucket.nil?
13
- bucket
14
- end
15
-
16
- def reset
17
- @buckets.values.each(&:reset)
18
- @buckets = Hash.new
19
- end
20
-
21
- def release
22
- reset
23
- end
24
-
25
- end
26
- end
@@ -1,38 +0,0 @@
1
- module Crabfarm
2
- class ForkedState < Delegator
3
-
4
- def initialize(_state, _name, _mutex)
5
- @state = _state
6
- @name = _name
7
- @mutex = _mutex
8
-
9
- super @state
10
- end
11
-
12
- def driver
13
- @driver ||= @state.driver(@name)
14
- end
15
-
16
- def browser
17
- @browser ||= @state.browser(@name)
18
- end
19
-
20
- def output
21
- raise ScriptError.new 'Use lock_output to access output in forked states'
22
- end
23
-
24
- def lock_output
25
- @mutex.synchronize {
26
- yield @state.output
27
- }
28
- end
29
-
30
- def __getobj__
31
- @state
32
- end
33
-
34
- def __setobj__(obj)
35
- @state = obj
36
- end
37
- end
38
- end
@@ -1,6 +0,0 @@
1
- module Crabfarm
2
- module Mocks
3
- class NoopDriver
4
- end
5
- end
6
- end
@@ -1,33 +0,0 @@
1
- module Crabfarm
2
- class PhantomDriverFactory
3
-
4
- def initialize(_phantom, _config={})
5
- @phantom = _phantom
6
- @config = _config
7
- end
8
-
9
- def build_driver(_session_id)
10
-
11
- # setup a custom client to use longer timeouts
12
- client = Selenium::WebDriver::Remote::Http::Default.new
13
- client.timeout = @config[:remote_timeout]
14
-
15
- driver = Selenium::WebDriver.for :remote, {
16
- :url => phantom_url,
17
- :http_client => client,
18
- :desired_capabilities => @config[:capabilities]
19
- }
20
-
21
- driver.send(:bridge).setWindowSize(@config[:window_width], @config[:window_height])
22
-
23
- return driver
24
- end
25
-
26
- private
27
-
28
- def phantom_url
29
- "http://localhost:#{@phantom.port}"
30
- end
31
-
32
- end
33
- end
@@ -1,8 +0,0 @@
1
- class <%= state_class %> < Crabfarm::BaseState
2
-
3
- def crawl
4
- # Do some damage!
5
- end
6
-
7
- end
8
-