page_magic 1.2.1 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d60246721a5c12200d50850da023c0c0baba852f
4
- data.tar.gz: f130471a70f308b33d0e0495daf03ac7eee41393
3
+ metadata.gz: f73c42fab4dedc07b8f403de27bbafb7f06beda6
4
+ data.tar.gz: 6bb45f94bf3cebc7da9678dd29b4ec135c4899be
5
5
  SHA512:
6
- metadata.gz: a02f4e1c4fab88c1892547f57549c42a2542f2fa4f505e162746670918a999fc20fbfd06c92692a78d56a9e219e80ecb58eb14ee1632e1366e14cef45827aaad
7
- data.tar.gz: 7549756b08f6c79bf276786bb09ff12f02696385c83149aa7e03e177070c192a6bb1f6ff82581e2e758b552cd17e06c7850ce08b4a4438c563d3735e0b3d162d
6
+ metadata.gz: 6ca98987cf3ba24618714325f42b5b3567389f06dd4d67348a75fb22ac941f3e1d88250e373ec94397cfb2d93f6e484166824f319f4ffc92d75d5392efe3c862
7
+ data.tar.gz: 3cc31ae2222b73a2ad710595c2e16c4716cc8fba1b4ffd09132af280fbbe25406ec18a48c000dabad31d6369a2fd07fe0d09fbea4e772d23767ee0070d73412c
data/.rubocop.yml CHANGED
@@ -2,6 +2,7 @@ Metrics/LineLength:
2
2
  Max: 120
3
3
 
4
4
  AllCops:
5
+ TargetRubyVersion: 2.1
5
6
  Exclude:
6
7
  - 'pkg/**/*'
7
8
  - 'vendor/**/*'
data/Gemfile CHANGED
@@ -11,7 +11,6 @@ group :test do
11
11
  gem 'poltergeist'
12
12
  gem 'codeclimate-test-reporter', group: :test, require: nil
13
13
  gem 'pullreview-coverage', require: false
14
- gem 'cucumber'
15
14
  end
16
15
 
17
16
  group :development do
data/Gemfile.lock CHANGED
@@ -1,38 +1,28 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (4.2.5)
4
+ activesupport (4.2.6)
5
5
  i18n (~> 0.7)
6
6
  json (~> 1.7, >= 1.7.7)
7
7
  minitest (~> 5.1)
8
8
  thread_safe (~> 0.3, >= 0.3.4)
9
9
  tzinfo (~> 1.1)
10
- addressable (2.3.8)
11
- ast (2.1.0)
12
- astrolabe (1.3.1)
13
- parser (~> 2.2)
10
+ addressable (2.4.0)
11
+ ast (2.2.0)
14
12
  builder (3.2.2)
15
- capybara (2.5.0)
13
+ capybara (2.7.1)
14
+ addressable
16
15
  mime-types (>= 1.16)
17
16
  nokogiri (>= 1.3.3)
18
17
  rack (>= 1.0.0)
19
18
  rack-test (>= 0.5.4)
20
19
  xpath (~> 2.0)
21
- certifi (2015.11.20)
22
- childprocess (0.5.8)
20
+ certifi (2016.02.28)
21
+ childprocess (0.5.9)
23
22
  ffi (~> 1.0, >= 1.0.11)
24
23
  cliver (0.3.2)
25
- codeclimate-test-reporter (0.4.8)
24
+ codeclimate-test-reporter (0.5.0)
26
25
  simplecov (>= 0.7.1, < 1.0.0)
27
- cucumber (2.1.0)
28
- builder (>= 2.1.2)
29
- cucumber-core (~> 1.3.0)
30
- diff-lcs (>= 1.1.3)
31
- gherkin3 (~> 3.1.0)
32
- multi_json (>= 1.7.5, < 2.0)
33
- multi_test (>= 0.1.2)
34
- cucumber-core (1.3.0)
35
- gherkin3 (~> 3.1.0)
36
26
  descendants_tracker (0.0.4)
37
27
  thread_safe (~> 0.3, >= 0.3.1)
38
28
  diff-lcs (1.2.5)
@@ -40,21 +30,19 @@ GEM
40
30
  faraday (0.9.2)
41
31
  multipart-post (>= 1.2, < 3)
42
32
  ffi (1.9.10)
43
- gherkin3 (3.1.2)
44
- git (1.2.9.1)
33
+ git (1.3.0)
45
34
  github-markup (1.4.0)
46
- github_api (0.13.0)
47
- addressable (~> 2.3)
35
+ github_api (0.13.1)
36
+ addressable (~> 2.4.0)
48
37
  descendants_tracker (~> 0.0.4)
49
38
  faraday (~> 0.8, < 0.10)
50
39
  hashie (>= 3.4)
51
40
  multi_json (>= 1.7.5, < 2.0)
52
- nokogiri (~> 1.6.6)
53
41
  oauth2
54
- hashie (3.4.3)
42
+ hashie (3.4.4)
55
43
  highline (1.7.8)
56
44
  i18n (0.7.0)
57
- jeweler (2.0.1)
45
+ jeweler (2.1.1)
58
46
  builder
59
47
  bundler (>= 1.0)
60
48
  git (>= 1.2.5)
@@ -63,28 +51,28 @@ GEM
63
51
  nokogiri (>= 1.5.10)
64
52
  rake
65
53
  rdoc
54
+ semver
66
55
  json (1.8.3)
67
- jwt (1.5.2)
56
+ jwt (1.5.1)
68
57
  mime-types (3.0)
69
58
  mime-types-data (~> 3.2015)
70
- mime-types-data (3.2015.1120)
59
+ mime-types-data (3.2016.0221)
71
60
  mini_portile2 (2.0.0)
72
- minitest (5.8.3)
73
- multi_json (1.11.2)
74
- multi_test (0.1.2)
61
+ minitest (5.8.4)
62
+ multi_json (1.12.0)
75
63
  multi_xml (0.5.5)
76
64
  multipart-post (2.0.0)
77
- nokogiri (1.6.7.1)
65
+ nokogiri (1.6.7.2)
78
66
  mini_portile2 (~> 2.0.0.rc2)
79
- oauth2 (1.0.0)
67
+ oauth2 (1.1.0)
80
68
  faraday (>= 0.8, < 0.10)
81
- jwt (~> 1.0)
69
+ jwt (~> 1.0, < 1.5.2)
82
70
  multi_json (~> 1.3)
83
71
  multi_xml (~> 0.5)
84
- rack (~> 1.2)
85
- parser (2.2.3.0)
86
- ast (>= 1.1, < 3.0)
87
- poltergeist (1.8.1)
72
+ rack (>= 1.2, < 3)
73
+ parser (2.3.1.0)
74
+ ast (~> 2.2)
75
+ poltergeist (1.9.0)
88
76
  capybara (~> 2.1)
89
77
  cliver (~> 0.3.1)
90
78
  multi_json (~> 1.0)
@@ -98,55 +86,54 @@ GEM
98
86
  rack
99
87
  rack-test (0.6.3)
100
88
  rack (>= 1.0)
101
- rainbow (2.0.0)
102
- rake (10.4.2)
103
- rdoc (4.2.0)
89
+ rainbow (2.1.0)
90
+ rake (11.1.2)
91
+ rdoc (4.2.2)
104
92
  json (~> 1.4)
105
- redcarpet (3.3.3)
93
+ redcarpet (3.3.4)
106
94
  rspec (3.4.0)
107
95
  rspec-core (~> 3.4.0)
108
96
  rspec-expectations (~> 3.4.0)
109
97
  rspec-mocks (~> 3.4.0)
110
- rspec-core (3.4.1)
98
+ rspec-core (3.4.4)
111
99
  rspec-support (~> 3.4.0)
112
100
  rspec-expectations (3.4.0)
113
101
  diff-lcs (>= 1.2.0, < 2.0)
114
102
  rspec-support (~> 3.4.0)
115
- rspec-mocks (3.4.0)
103
+ rspec-mocks (3.4.1)
116
104
  diff-lcs (>= 1.2.0, < 2.0)
117
105
  rspec-support (~> 3.4.0)
118
106
  rspec-support (3.4.1)
119
- rubocop (0.35.1)
120
- astrolabe (~> 1.3)
121
- parser (>= 2.2.3.0, < 3.0)
107
+ rubocop (0.40.0)
108
+ parser (>= 2.3.1.0, < 3.0)
122
109
  powerpack (~> 0.1)
123
110
  rainbow (>= 1.99.1, < 3.0)
124
111
  ruby-progressbar (~> 1.7)
125
- tins (<= 1.6.0)
126
- ruby-progressbar (1.7.5)
127
- rubyzip (1.1.7)
128
- selenium-webdriver (2.48.1)
112
+ unicode-display_width (~> 1.0, >= 1.0.1)
113
+ ruby-progressbar (1.8.1)
114
+ rubyzip (1.2.0)
115
+ selenium-webdriver (2.53.0)
129
116
  childprocess (~> 0.5)
130
- multi_json (~> 1.0)
131
117
  rubyzip (~> 1.0)
132
118
  websocket (~> 1.0)
133
- simplecov (0.10.0)
119
+ semver (1.0.1)
120
+ simplecov (0.11.2)
134
121
  docile (~> 1.1.0)
135
122
  json (~> 1.8)
136
123
  simplecov-html (~> 0.10.0)
137
124
  simplecov-html (0.10.0)
138
- sinatra (1.4.6)
139
- rack (~> 1.4)
125
+ sinatra (1.4.7)
126
+ rack (~> 1.5)
140
127
  rack-protection (~> 1.4)
141
128
  tilt (>= 1.3, < 3)
142
129
  thread_safe (0.3.5)
143
- tilt (2.0.1)
144
- tins (1.6.0)
130
+ tilt (2.0.3)
145
131
  tzinfo (1.2.2)
146
132
  thread_safe (~> 0.1)
133
+ unicode-display_width (1.0.5)
147
134
  watir-webdriver (0.9.1)
148
135
  selenium-webdriver (>= 2.46.2)
149
- websocket (1.2.2)
136
+ websocket (1.2.3)
150
137
  websocket-driver (0.6.3)
151
138
  websocket-extensions (>= 0.1.0)
152
139
  websocket-extensions (0.1.2)
@@ -161,7 +148,6 @@ DEPENDENCIES
161
148
  activesupport (~> 4)
162
149
  capybara (>= 2.5)
163
150
  codeclimate-test-reporter
164
- cucumber
165
151
  github-markup (~> 1.4)
166
152
  jeweler (~> 2.0)
167
153
  poltergeist
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.2.3
@@ -25,7 +25,7 @@ module PageMagic
25
25
  # @param [Symbol] browser name of required browser
26
26
  # @param [Hash] options driver specific options
27
27
  # @return [Object] Capybara compliant driver instance
28
- def build(app, browser:, options:{})
28
+ def build(app, browser:, options: {})
29
29
  handler.call(app, options, browser)
30
30
  end
31
31
 
@@ -4,7 +4,7 @@ module PageMagic
4
4
  # contains method for finding element definitions
5
5
  module Locators
6
6
  # message used when raising {ElementMissingException} from methods within this module
7
- ELEMENT_NOT_DEFINED_MSG = 'Element not defined: %s'
7
+ ELEMENT_NOT_DEFINED_MSG = 'Element not defined: %s'.freeze
8
8
 
9
9
  # find an element definition based on its name
10
10
  # @param [Symbol] name name of the element
@@ -12,7 +12,7 @@ module PageMagic
12
12
  # @raise [ElementMissingException] raised when element with the given name is not found
13
13
  def element_by_name(name, *args)
14
14
  defintion = element_definitions[name]
15
- fail ElementMissingException, (ELEMENT_NOT_DEFINED_MSG % name) unless defintion
15
+ raise ElementMissingException, (ELEMENT_NOT_DEFINED_MSG % name) unless defintion
16
16
  defintion.call(self, *args)
17
17
  end
18
18
 
@@ -11,7 +11,7 @@ module PageMagic
11
11
  # @param [Symbol] type the name of the required query in snakecase format
12
12
  # @return [Query] returns the predefined query with the given name
13
13
  def find(type)
14
- query = constants.find { |constant| constant.to_s.downcase == type.to_s.downcase }
14
+ query = constants.find { |constant| constant.to_s.casecmp(type.to_s).zero? }
15
15
  return ELEMENT unless query
16
16
  const_get(query)
17
17
  end
@@ -8,8 +8,8 @@ module PageMagic
8
8
  # selectors
9
9
  # @return [Selector] returns the predefined selector with the given name
10
10
  def find(name)
11
- selector = constants.find { |constant| constant.to_s.downcase == name.to_s.downcase }
12
- fail UnsupportedCriteriaException unless selector
11
+ selector = constants.find { |constant| constant.to_s.casecmp(name.to_s).zero? }
12
+ raise UnsupportedCriteriaException unless selector
13
13
  const_get(selector)
14
14
  end
15
15
  end
@@ -6,8 +6,9 @@ require 'page_magic/element/query'
6
6
  module PageMagic
7
7
  # class Element - represents an element in a html page.
8
8
  class Element
9
- EVENT_TYPES = [:set, :select, :select_option, :unselect_option, :click]
9
+ EVENT_TYPES = [:set, :select, :select_option, :unselect_option, :click].freeze
10
10
  DEFAULT_HOOK = proc {}.freeze
11
+ EVENT_NOT_SUPPORTED_MSG = '%s event not supported'.freeze
11
12
 
12
13
  include SelectorMethods, Watchers, SessionMethods, WaitMethods, Locators
13
14
  extend Elements, SelectorMethods, Forwardable
@@ -68,12 +69,22 @@ module PageMagic
68
69
  wrap_events(browser_element)
69
70
  end
70
71
 
72
+ # @!method click
73
+ # @!method set
74
+ # @!method select
75
+ # @!method select_option
76
+ # @!method unselect_option
77
+ # calls method of the same name on the underlying Capybara element
78
+ # @raise [NotSupportedException] if the wrapped Capybara element does not support the method
71
79
  EVENT_TYPES.each do |method|
72
80
  define_method method do |*args|
81
+ unless browser_element.respond_to?(method)
82
+ raise NotSupportedException, EVENT_NOT_SUPPORTED_MSG % method
83
+ end
84
+
73
85
  browser_element.send(method, *args)
74
86
  end
75
87
  end
76
-
77
88
  def method_missing(method, *args, &block)
78
89
  ElementContext.new(self).send(method, *args, &block)
79
90
  rescue ElementMissingException
@@ -2,7 +2,7 @@ module PageMagic
2
2
  # class ElementContext - resolves which element definition to use when accessing the browser.
3
3
  class ElementContext
4
4
  # Message template for execptions raised as a result of calling method_missing
5
- ELEMENT_NOT_FOUND_MSG = 'Unable to find %s'
5
+ ELEMENT_NOT_FOUND_MSG = 'Unable to find %s'.freeze
6
6
 
7
7
  attr_reader :page_element
8
8
 
@@ -36,9 +36,9 @@ module PageMagic
36
36
  query_args = builder.build_query
37
37
  result = page_element.browser_element.all(*query_args)
38
38
 
39
- if result.size == 0
39
+ if result.empty?
40
40
  query = Capybara::Query.new(*query_args)
41
- fail ElementMissingException, ELEMENT_NOT_FOUND_MSG % query.description
41
+ raise ElementMissingException, ELEMENT_NOT_FOUND_MSG % query.description
42
42
  end
43
43
 
44
44
  result.to_a.collect { |e| builder.build(e) }
@@ -1,13 +1,13 @@
1
1
  module PageMagic
2
2
  # Builder for creating ElementDefinitions
3
3
  class ElementDefinitionBuilder
4
- INVALID_SELECTOR_MSG = 'Pass a locator/define one on the class'
4
+ INVALID_SELECTOR_MSG = 'Pass a locator/define one on the class'.freeze
5
5
  attr_reader :definition_class, :options, :selector, :type, :element
6
6
 
7
- def initialize(definition_class:, selector:, type:, options:{}, element: nil)
7
+ def initialize(definition_class:, selector:, type:, options: {}, element: nil)
8
8
  unless element
9
9
  selector ||= definition_class.selector
10
- fail UndefinedSelectorException, INVALID_SELECTOR_MSG if selector.nil? || selector.empty?
10
+ raise UndefinedSelectorException, INVALID_SELECTOR_MSG if selector.nil? || selector.empty?
11
11
  end
12
12
 
13
13
  @definition_class = definition_class
@@ -12,9 +12,9 @@ module PageMagic
12
12
  end
13
13
  end
14
14
 
15
- INVALID_METHOD_NAME_MSG = 'a method already exists with this method name'
15
+ INVALID_METHOD_NAME_MSG = 'a method already exists with this method name'.freeze
16
16
 
17
- TYPES = [:text_field, :button, :link, :checkbox, :select_list, :radios, :textarea]
17
+ TYPES = [:text_field, :button, :link, :checkbox, :select_list, :radios, :textarea].freeze
18
18
 
19
19
  class << self
20
20
  def extended(clazz)
@@ -59,7 +59,7 @@ module PageMagic
59
59
  add_element_definition(options.delete(:name)) do |parent_element, *e_args|
60
60
  definition_class = Class.new(section_class) do
61
61
  parent_element(parent_element)
62
- class_exec(*e_args, &(block))
62
+ class_exec(*e_args, &block)
63
63
  end
64
64
  ElementDefinitionBuilder.new(options.merge(definition_class: definition_class))
65
65
  end
@@ -85,10 +85,10 @@ module PageMagic
85
85
  end
86
86
 
87
87
  def add_element_definition(name, &block)
88
- fail InvalidElementNameException, 'duplicate page element defined' if element_definitions[name]
88
+ raise InvalidElementNameException, 'duplicate page element defined' if element_definitions[name]
89
89
 
90
90
  methods = respond_to?(:instance_methods) ? instance_methods : methods()
91
- fail InvalidElementNameException, INVALID_METHOD_NAME_MSG if methods.find { |method| method == name }
91
+ raise InvalidElementNameException, INVALID_METHOD_NAME_MSG if methods.find { |method| method == name }
92
92
 
93
93
  element_definitions[name] = block
94
94
  end
@@ -104,7 +104,7 @@ module PageMagic
104
104
  end
105
105
 
106
106
  def method_added(method)
107
- fail InvalidMethodNameException, 'method name matches element name' if element_definitions[method]
107
+ raise InvalidMethodNameException, 'method name matches element name' if element_definitions[method]
108
108
  end
109
109
 
110
110
  def compute_argument(args, clazz)
@@ -28,4 +28,7 @@ module PageMagic
28
28
 
29
29
  class UndefinedSelectorException < Exception
30
30
  end
31
+
32
+ class NotSupportedException < Exception
33
+ end
31
34
  end
@@ -6,7 +6,7 @@ module PageMagic
6
6
 
7
7
  # @raise [MatcherInvalidException] if at least one component is not specified
8
8
  def initialize(path = nil, parameters: nil, fragment: nil)
9
- fail MatcherInvalidException unless path || parameters || fragment
9
+ raise MatcherInvalidException unless path || parameters || fragment
10
10
  @path = path
11
11
  @parameters = parameters
12
12
  @fragment = fragment
@@ -19,7 +19,7 @@ module PageMagic
19
19
 
20
20
  # @return [String] uri represented by this mapping
21
21
  def compute_uri
22
- "#{path}".tap do |uri|
22
+ path.to_s.tap do |uri|
23
23
  uri << "?#{parameters.to_query}" if parameters
24
24
  uri << "##{fragment}" if fragment
25
25
  end
@@ -54,7 +54,7 @@ module PageMagic
54
54
  path == other.path && parameters == other.parameters && fragment == other.fragment
55
55
  end
56
56
 
57
- alias_method :eql?, :==
57
+ alias eql? ==
58
58
 
59
59
  private
60
60
 
@@ -3,9 +3,10 @@ require 'page_magic/matcher'
3
3
  module PageMagic
4
4
  # class Session - coordinates access to the browser though page objects.
5
5
  class Session
6
- URL_MISSING_MSG = 'a path must be mapped or a url supplied'
7
- REGEXP_MAPPING_MSG = 'URL could not be derived because mapping contains Regexps'
8
- INVALID_MAPPING_MSG = 'mapping must be a string or regexp'
6
+ URL_MISSING_MSG = 'a path must be mapped or a url supplied'.freeze
7
+ REGEXP_MAPPING_MSG = 'URL could not be derived because mapping contains Regexps'.freeze
8
+ INVALID_MAPPING_MSG = 'mapping must be a string or regexp'.freeze
9
+ UNSUPPORTED_OPERATION_MSG = 'execute_script not supported by driver'.freeze
9
10
 
10
11
  extend Forwardable
11
12
 
@@ -54,11 +55,15 @@ module PageMagic
54
55
  end.to_h
55
56
  end
56
57
 
57
- # @!method execute_script
58
58
  # execute javascript on the browser
59
59
  # @param [String] script the script to be executed
60
60
  # @return [Object] object returned by the capybara execute_script method
61
- def_delegator :raw_session, :execute_script
61
+ # @raise [NotSupportedException] if the capybara driver in use does not support execute script
62
+ def execute_script(script)
63
+ raw_session.execute_script(script)
64
+ rescue Capybara::NotSupportedByDriverError
65
+ raise NotSupportedException, UNSUPPORTED_OPERATION_MSG
66
+ end
62
67
 
63
68
  # proxies unknown method calls to the currently loaded page object
64
69
  # @return [Object] returned object from the page object method call
@@ -86,14 +91,16 @@ module PageMagic
86
91
  # @raise [InvalidURLException] if neither a page or url are supplied
87
92
  # @raise [InvalidURLException] if the mapped path for a page is a Regexp
88
93
  def visit(page = nil, url: nil)
89
- if url
90
- raw_session.visit(url)
91
- elsif (mapping = transitions.key(page))
92
- fail InvalidURLException, REGEXP_MAPPING_MSG unless mapping.can_compute_uri?
93
- raw_session.visit(url(base_url, mapping.compute_uri))
94
- else
95
- fail InvalidURLException, URL_MISSING_MSG
94
+ target_url = url || begin
95
+ if (mapping = transitions.key(page))
96
+ raise InvalidURLException, REGEXP_MAPPING_MSG unless mapping.can_compute_uri?
97
+ url(base_url, mapping.compute_uri)
98
+ end
96
99
  end
100
+
101
+ raise InvalidURLException, URL_MISSING_MSG unless target_url
102
+
103
+ raw_session.visit(target_url)
97
104
  @current_page = initialize_page(page) if page
98
105
  self
99
106
  end
@@ -6,13 +6,13 @@ module PageMagic
6
6
  # wait_until do
7
7
  # (rand % 2) == 0
8
8
  # end
9
- def wait_until(timeout_after: 5, retry_every: 1, &block)
9
+ def wait_until(timeout_after: 5, retry_every: 1, &_block)
10
10
  start_time = Time.now
11
11
  until Time.now > start_time + timeout_after
12
- return true if block.call == true
12
+ return true if yield == true
13
13
  sleep retry_every
14
14
  end
15
- fail TimeoutException, 'Action took to long'
15
+ raise TimeoutException, 'Action took to long'
16
16
  end
17
17
  end
18
18
  end
@@ -3,7 +3,7 @@ require 'page_magic/watcher'
3
3
  module PageMagic
4
4
  # module Watchers - contains methods for adding watchers and checking them
5
5
  module Watchers
6
- ELEMENT_MISSING_MSG = 'Unable to defined watcher: Element or method with the name %s can not be found'
6
+ ELEMENT_MISSING_MSG = 'Unable to defined watcher: Element or method with the name %s can not be found'.freeze
7
7
 
8
8
  # @param [Symbol] name - the name of the watcher
9
9
  # @return [Boolean] true if a change is detected
@@ -23,7 +23,7 @@ module PageMagic
23
23
  # # more complicated code to get value
24
24
  # end
25
25
  def watch(name, method = nil, &block)
26
- fail ElementMissingException, (ELEMENT_MISSING_MSG % name) unless block || respond_to?(name)
26
+ raise ElementMissingException, (ELEMENT_MISSING_MSG % name) unless block || respond_to?(name)
27
27
  watched_element = block ? Watcher.new(name, &block) : Watcher.new(name, method)
28
28
  watchers.delete_if { |w| w.name == name }
29
29
  watchers << watched_element.check(self)
data/lib/page_magic.rb CHANGED
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__).to_s)
2
2
  require 'capybara'
3
3
  require 'page_magic/exceptions'
4
4
  require 'page_magic/wait_methods'
@@ -43,7 +43,7 @@ module PageMagic
43
43
  # @return [Session] configured sessoin
44
44
  def session(application: nil, browser: :rack_test, url:, options: {})
45
45
  driver = drivers.find(browser)
46
- fail UnspportedBrowserException unless driver
46
+ raise UnspportedBrowserException unless driver
47
47
 
48
48
  Capybara.register_driver browser do |app|
49
49
  driver.build(app, browser: browser, options: options)
data/page_magic.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: page_magic 1.2.1 ruby lib
5
+ # stub: page_magic 1.2.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "page_magic"
9
- s.version = "1.2.1"
9
+ s.version = "1.2.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Leon Davis"]
14
- s.date = "2016-01-15"
14
+ s.date = "2016-05-15"
15
15
  s.description = "Framework for modeling and interacting with webpages which wraps capybara"
16
16
  s.email = "info@lad-tech.com"
17
17
  s.extra_rdoc_files = [
data/spec/element_spec.rb CHANGED
@@ -126,6 +126,13 @@ module PageMagic
126
126
  subject.select :args
127
127
  end
128
128
  end
129
+
130
+ context 'Capybara element does not respond to the method' do
131
+ it 'raises an error' do
132
+ expected_message = (described_class::EVENT_NOT_SUPPORTED_MSG % 'click')
133
+ expect { subject.click }.to raise_error(NotSupportedException, expected_message)
134
+ end
135
+ end
129
136
  end
130
137
  end
131
138
 
@@ -8,7 +8,7 @@ module PageMagic
8
8
 
9
9
  describe '#build' do
10
10
  it 'returns the result of the block passed to the driver class constructor' do
11
- subject = described_class.new(:custom_browser)do
11
+ subject = described_class.new(:custom_browser) do
12
12
  :driver
13
13
  end
14
14
  expect(subject.build(:rack_app, browser: :custom_browser, options: :options)).to eq(:driver)
@@ -42,7 +42,7 @@ module PageMagic
42
42
  it 'does not evaluate any of the other definitions' do
43
43
  elements_page.class_eval do
44
44
  link(:another_link, :selector) do
45
- fail('should not have been evaluated')
45
+ raise('should not have been evaluated')
46
46
  end
47
47
  end
48
48
 
@@ -142,7 +142,7 @@ module PageMagic
142
142
  it 'should not evaluate the elements when applying naming checks' do
143
143
  subject.class_eval do
144
144
  link(:link1, :selector) do
145
- fail('should not have been evaluated')
145
+ raise('should not have been evaluated')
146
146
  end
147
147
  link(:link2, :selector)
148
148
  end
@@ -75,6 +75,14 @@ module PageMagic
75
75
  expect(browser).to receive(:execute_script).with(:script).and_return(:result)
76
76
  expect(subject.execute_script(:script)).to be(:result)
77
77
  end
78
+
79
+ context 'Capybara session does not support #execute_script' do
80
+ let(:browser) { Capybara::Driver::Base.new }
81
+ it 'raises an error' do
82
+ expected_message = described_class::UNSUPPORTED_OPERATION_MSG
83
+ expect { subject.execute_script(:script) }.to raise_error(NotSupportedException, expected_message)
84
+ end
85
+ end
78
86
  end
79
87
 
80
88
  describe '#find_mapped_page' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-15 00:00:00.000000000 Z
11
+ date: 2016-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara