capybara-widgets 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/capybara/widgets/core/page.rb +10 -1
- data/lib/capybara/widgets/core/page_collection.rb +6 -2
- data/lib/capybara/widgets/core/widget.rb +4 -2
- data/lib/capybara/widgets/cucumber/page_steps.rb +13 -3
- data/lib/capybara/widgets/cucumber/widget_steps.rb +13 -7
- data/lib/capybara/widgets/helpers/async_helper.rb +1 -1
- data/lib/capybara/widgets/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e98613481eaf9e01a0d306a6be1bfe3cbb9a5ebb
|
4
|
+
data.tar.gz: 5e0a51ef2c632f47fed8f3314524b6223231783e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcbf75f3df259f41e0c0c3f5da5b9d9cbde2fb58c8777a3f9cb26add867ca519d9a7e3c3729d6c7f03f74751a29ce842e01517f62781d1a2736e3c46166cef87
|
7
|
+
data.tar.gz: 9b029d11cdfe3f98c90c7efaeef5ec0840c16e44aa2855b3bfe33e801165611fd66fa546bfa48e6eb38fa1bd046e4fb601222fc4a4e9826aaceee96a24ccdc65
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require_relative 'widget'
|
2
2
|
require_relative 'page_collection'
|
3
|
+
require_relative '../helpers/async_helper'
|
3
4
|
require 'active_support/core_ext/class/attribute'
|
4
5
|
|
5
6
|
module Capybara
|
6
7
|
module Widgets
|
7
8
|
class Page < Widget
|
8
9
|
|
10
|
+
include Capybara::Widgets::AsyncHelper
|
11
|
+
|
9
12
|
class_attribute :path
|
10
13
|
class_attribute :path_matcher
|
11
14
|
|
@@ -26,7 +29,13 @@ module Capybara
|
|
26
29
|
end
|
27
30
|
|
28
31
|
def opened?
|
29
|
-
|
32
|
+
eventually do
|
33
|
+
result = self.path_matcher? ?
|
34
|
+
current_path =~ self.path_matcher :
|
35
|
+
current_path =~ %r{#{Regexp.quote(self.path)}}
|
36
|
+
raise "#{self.class.name} is not opened" unless result
|
37
|
+
result
|
38
|
+
end
|
30
39
|
end
|
31
40
|
|
32
41
|
def reload!
|
@@ -18,14 +18,18 @@ module Capybara
|
|
18
18
|
def current_page_class
|
19
19
|
load_classes unless @loaded
|
20
20
|
klass = registry.detect do |page_class|
|
21
|
-
if page_class.path_matcher
|
21
|
+
if page_class.path_matcher?
|
22
22
|
if page_class.path_matcher.is_a?(Regexp)
|
23
23
|
Capybara.current_path =~ page_class.path_matcher
|
24
24
|
elsif page_class.path_matcher.is_a?(String)
|
25
25
|
Capybara.current_path.include?(page_class.path_matcher)
|
26
26
|
end
|
27
27
|
else
|
28
|
-
|
28
|
+
if page_class.path?
|
29
|
+
Capybara.current_path.include?(page_class.path)
|
30
|
+
else
|
31
|
+
false
|
32
|
+
end
|
29
33
|
end
|
30
34
|
end
|
31
35
|
raise "Not found" if klass.nil?
|
@@ -50,12 +50,14 @@ module Capybara
|
|
50
50
|
|
51
51
|
def element(name, *query)
|
52
52
|
define_method("#{name}!") { root.find(*query).click }
|
53
|
+
define_method(name) { root.find(*query) }
|
53
54
|
define_method("#{name}=") { |arg| root.find(*query).set(arg) }
|
54
|
-
define_method("has_#{name}?")
|
55
|
+
define_method("has_#{name}?"){|*args| root.has_selector?(*query, *args) }
|
56
|
+
define_method("has_no_#{name}?"){|*args| root.has_no_selector?(*query, *args) }
|
55
57
|
end
|
56
58
|
|
57
59
|
def required_element(*element_names)
|
58
|
-
define_method(:elements_loaded?) { element_names.
|
60
|
+
define_method(:elements_loaded?) { element_names.map {|name| self.send("has_#{name}?")}.count(false) == 0 }
|
59
61
|
end
|
60
62
|
|
61
63
|
alias_method :required_elements, :required_element
|
@@ -7,19 +7,19 @@ World Capybara::Widgets::StringHelpers
|
|
7
7
|
World Capybara::Widgets::AsyncHelper
|
8
8
|
World Capybara::Widgets::DSL
|
9
9
|
|
10
|
-
Given(/^I am on a
|
10
|
+
Given(/^I am on (?:a\s|an\s)?(.* page)/) do |page_name|
|
11
11
|
within_widget(to_widget_class(page_name)) do |page|
|
12
12
|
page.open!
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
When(/^I navigate to a
|
16
|
+
When(/^I navigate to (?:a\s|an\s)?(.* page)/) do |page_name|
|
17
17
|
within_widget(to_widget_class(page_name)) do |page|
|
18
18
|
page.open!
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
Then(/^I should be on a
|
22
|
+
Then(/^I should be on (?:a\s|an\s)?(.* page)/) do |page_name|
|
23
23
|
within_widget(to_widget_class(page_name)) do |page|
|
24
24
|
eventually { expect(page).to be_loaded }
|
25
25
|
end
|
@@ -33,3 +33,13 @@ When(/^I set "([^"]*)" to "([^"]*)"$/) do |field_name, value|
|
|
33
33
|
current_page.send(to_widget_action(field_name, '='), value)
|
34
34
|
end
|
35
35
|
|
36
|
+
And(/^I should( not)? see( \d+)? "([^"]*)" ([^"]*s?)$/) do |negated, count, content, widget_action|
|
37
|
+
negation_prefix = (negated && negated.length > 0) ? 'no_' : ''
|
38
|
+
expected_count = (count && count.length > 0) ? count.strip.to_i : 1
|
39
|
+
if expected_count > 1
|
40
|
+
expect(current_page).to send("have_#{negation_prefix}#{to_widget_action(widget_action)}", content, count)
|
41
|
+
else
|
42
|
+
expect(current_page).to send("have_#{negation_prefix}#{to_widget_action(widget_action)}", content)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -37,9 +37,9 @@ end
|
|
37
37
|
# I open "My Report" from a "Reports page"
|
38
38
|
# is mapped to:
|
39
39
|
# ReportsPage.new.open!("My Report")
|
40
|
-
When(/^I
|
40
|
+
When(/^I open "([^"]*)" from a "([^"]*)"$/) do |action_param, widget_path|
|
41
41
|
target_widget = resolve_widget(widget_path)
|
42
|
-
target_widget.
|
42
|
+
target_widget.open!(action_param)
|
43
43
|
end
|
44
44
|
|
45
45
|
|
@@ -57,8 +57,9 @@ end
|
|
57
57
|
# is mapped to: expect(MyWidget.new).to have_no_action("Do it")
|
58
58
|
# I should see "Do it" value in a "My page -> page component"
|
59
59
|
# is mapped to: expect(MyPage.new.page_component).to have_value("Do it")
|
60
|
-
And(/^I should( not)? see "([^"]*)" (.*) (?:in|on) a "([^"]*)"$/) do |negated, content, widget_action, widget_path|
|
60
|
+
And(/^I should( not)? see( \d+)? "([^"]*)" (.*) (?:in|on) a "([^"]*)"$/) do |negated, count, content, widget_action, widget_path|
|
61
61
|
negation_prefix = (negated && negated.length > 0) ? 'no_' : ''
|
62
|
+
expected_count = (count && count.length > 0) ? count.strip.to_i : 1
|
62
63
|
target_widget = resolve_widget(widget_path)
|
63
64
|
expect(target_widget).to send("have_#{negation_prefix}#{to_widget_action(widget_action)}", content)
|
64
65
|
end
|
@@ -72,14 +73,19 @@ When(/^I fill in the following in a "([^"]*)"$/) do |widget_name, table|
|
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
|
-
And(/^the "([^"]*)" should be "([^"]*)" in a "([^"]*)"$/) do |field_name, expected, widget_name|
|
76
|
+
And(/^the "([^"]*)" should( not)? be "([^"]*)" in a "([^"]*)"$/) do |field_name, negated, expected, widget_name|
|
76
77
|
within_widget(to_widget_class(widget_name)) do |widget|
|
77
78
|
action = to_widget_action(field_name)
|
78
|
-
|
79
|
-
|
79
|
+
negation_prefix = (negated && negated.length > 0) ? 'no_' : ''
|
80
|
+
if widget.respond_to? "has_#{negation_prefix}#{action}?"
|
81
|
+
expect(widget.send("has_#{negation_prefix}#{action}?", expected)).to be_truthy
|
80
82
|
else
|
81
83
|
actual = widget.send(action)
|
82
|
-
|
84
|
+
if (negated && negated.length > 0)
|
85
|
+
expect(actual).not_to eq(expected)
|
86
|
+
else
|
87
|
+
expect(actual).to eq(expected)
|
88
|
+
end
|
83
89
|
end
|
84
90
|
end
|
85
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-widgets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitalii Grygoruk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|