capybara-widgets 0.0.2 → 0.1.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.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/README.md +2 -0
- data/capybara-widgets.gemspec +3 -3
- data/lib/capybara/widgets/core/dsl.rb +10 -0
- data/lib/capybara/widgets/core/page.rb +15 -1
- data/lib/capybara/widgets/core/page_collection.rb +47 -0
- data/lib/capybara/widgets/core/widget.rb +6 -0
- data/lib/capybara/widgets/cucumber/page_steps.rb +26 -13
- data/lib/capybara/widgets/cucumber/widget_steps.rb +3 -6
- data/lib/capybara/widgets/helpers/async_helper.rb +20 -0
- data/lib/capybara/widgets/rspec.rb +1 -0
- data/lib/capybara/widgets/version.rb +1 -1
- data/lib/capybara/widgets.rb +1 -0
- data/spec/features/widget_spec.rb +2 -2
- metadata +14 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e196b230cb55720ba9f662b0c2b8ee8d6a18971e
|
4
|
+
data.tar.gz: 63b356fc9d51fa05057123d99285935910d090f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42fe69573483dee2b0b15d4ed193a3dd8ae1230c5f672c453963eeef6f4cb124cd5eb1e9b8b77c67a723059d547906c2cb0aa230a5716b30892350bd7183a51e
|
7
|
+
data.tar.gz: 0a92d4cb0a543b119b0c664b9cf009137264fb187989a503d531c0f0e82fce047ec0bf355922783868ebd0d6a62b80ae96316e11ace9e3c0355421c73b27e15e
|
data/.travis.yml
ADDED
data/README.md
CHANGED
data/capybara-widgets.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Capybara::Widgets::VERSION
|
9
9
|
spec.authors = ["Vitalii Grygoruk"]
|
10
10
|
spec.email = ["vitalii[dot]grygoruk[at]gmail[dot]com"]
|
11
|
-
spec.summary = %q{Page
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{Page objects and page components for Capybara}
|
12
|
+
spec.description = %q{Easily create well-structured page and ui component classes in your Capybara + Cucumber or Rspec tests}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
24
24
|
spec.add_development_dependency "cucumber"
|
25
25
|
|
26
26
|
spec.add_dependency "capybara", "~> 2.0"
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'widget'
|
2
|
+
require_relative 'page_collection'
|
2
3
|
require 'active_support/core_ext/class/attribute'
|
3
4
|
|
4
5
|
module Capybara
|
@@ -6,13 +7,26 @@ module Capybara
|
|
6
7
|
class Page < Widget
|
7
8
|
|
8
9
|
class_attribute :path
|
10
|
+
class_attribute :path_matcher
|
11
|
+
|
12
|
+
def self.inherited(subclass)
|
13
|
+
PageCollection.instance.registry << subclass
|
14
|
+
end
|
9
15
|
|
10
16
|
def initialize
|
11
17
|
super(page)
|
12
18
|
end
|
13
19
|
|
14
20
|
def loaded?
|
15
|
-
|
21
|
+
result = opened?
|
22
|
+
if self.respond_to?(:elements_loaded?)
|
23
|
+
result = result && elements_loaded?
|
24
|
+
end
|
25
|
+
result
|
26
|
+
end
|
27
|
+
|
28
|
+
def opened?
|
29
|
+
current_path =~ %r{#{Regexp.quote(self.path)}}
|
16
30
|
end
|
17
31
|
|
18
32
|
def reload!
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'active_support/core_ext/class/attribute'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module Capybara
|
5
|
+
module Widgets
|
6
|
+
class PageCollection
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
attr_accessor :registry
|
10
|
+
|
11
|
+
class_attribute :load_path
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
self.registry = Array.new
|
15
|
+
@loaded = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def current_page_class
|
19
|
+
load_classes unless @loaded
|
20
|
+
klass = registry.detect do |page_class|
|
21
|
+
if page_class.path_matcher
|
22
|
+
if page_class.path_matcher.is_a?(Regexp)
|
23
|
+
Capybara.current_path =~ page_class.path_matcher
|
24
|
+
elsif page_class.path_matcher.is_a?(String)
|
25
|
+
Capybara.current_path.include?(page_class.path_matcher)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
Capybara.current_path.include?(page_class.path)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
raise "Not found" if klass.nil?
|
32
|
+
klass
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def load_classes
|
38
|
+
Dir[File.join(load_path, "**/*.rb")].each{|f| require f}
|
39
|
+
@loaded = true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def current_page
|
46
|
+
Capybara::Widgets::PageCollection.instance.current_page_class.new
|
47
|
+
end
|
@@ -53,6 +53,12 @@ module Capybara
|
|
53
53
|
define_method("#{name}=") { |arg| root.find(*query).set(arg) }
|
54
54
|
define_method("has_#{name}?") { root.has_selector?(*query) }
|
55
55
|
end
|
56
|
+
|
57
|
+
def required_element(*element_names)
|
58
|
+
define_method(:elements_loaded?) { element_names.each {|name| self.send("has_#{name}?")} }
|
59
|
+
end
|
60
|
+
|
61
|
+
alias_method :required_elements, :required_element
|
56
62
|
end
|
57
63
|
|
58
64
|
# delegate missing methods to the @root node
|
@@ -1,22 +1,35 @@
|
|
1
1
|
require 'cucumber'
|
2
2
|
require_relative '../helpers/string_helpers'
|
3
|
+
require_relative '../helpers/async_helper'
|
4
|
+
require_relative '../core/dsl'
|
3
5
|
|
4
|
-
|
6
|
+
World Capybara::Widgets::StringHelpers
|
7
|
+
World Capybara::Widgets::AsyncHelper
|
8
|
+
World Capybara::Widgets::DSL
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
+
Given(/^I am on a (.* page)/) do |page_name|
|
11
|
+
within_widget(to_widget_class(page_name)) do |page|
|
12
|
+
page.open!
|
10
13
|
end
|
14
|
+
end
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
+
When(/^I navigate to a (.* page)/) do |page_name|
|
17
|
+
within_widget(to_widget_class(page_name)) do |page|
|
18
|
+
page.open!
|
16
19
|
end
|
20
|
+
end
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
+
Then(/^I should be on a (.* page)/) do |page_name|
|
23
|
+
within_widget(to_widget_class(page_name)) do |page|
|
24
|
+
eventually { expect(page).to be_loaded }
|
22
25
|
end
|
26
|
+
end
|
27
|
+
|
28
|
+
When(/^I click "([^"]*)"$/) do |action|
|
29
|
+
current_page.send(to_widget_action(action, '!'))
|
30
|
+
end
|
31
|
+
|
32
|
+
When(/^I set "([^"]*)" to "([^"]*)"$/) do |field_name, value|
|
33
|
+
current_page.send(to_widget_action(field_name, '='), value)
|
34
|
+
end
|
35
|
+
|
@@ -1,12 +1,9 @@
|
|
1
1
|
require 'cucumber'
|
2
2
|
require_relative '../helpers/string_helpers'
|
3
|
+
require_relative '../core/dsl'
|
3
4
|
|
4
5
|
World Capybara::Widgets::StringHelpers
|
5
|
-
|
6
|
-
def within_widget(klass)
|
7
|
-
raise "#{klass.name} is not a subclass of Widget" unless klass < Capybara::Widgets::Widget
|
8
|
-
yield klass.new
|
9
|
-
end
|
6
|
+
World Capybara::Widgets::DSL
|
10
7
|
|
11
8
|
def resolve_widget(widget_chain)
|
12
9
|
elements = widget_chain.split('->')
|
@@ -17,7 +14,7 @@ def resolve_widget(widget_chain)
|
|
17
14
|
apply_action_chain(top_widget, action_chain)
|
18
15
|
end
|
19
16
|
|
20
|
-
When(/^I click "([^"]*)"
|
17
|
+
When(/^I click "([^"]*)" [o|i]n a "([^"]*)"$/) do |action, widget_path|
|
21
18
|
target_widget = resolve_widget(widget_path)
|
22
19
|
target_widget.send(to_widget_action(action, '!'))
|
23
20
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Capybara
|
2
|
+
module Widgets
|
3
|
+
module AsyncHelper
|
4
|
+
def eventually(options = {})
|
5
|
+
timeout = options[:timeout] || 10
|
6
|
+
interval = options[:interval] || 0.1
|
7
|
+
time_limit = Time.now + timeout
|
8
|
+
loop do
|
9
|
+
begin
|
10
|
+
result = yield
|
11
|
+
rescue => error
|
12
|
+
end
|
13
|
+
return result if error.nil?
|
14
|
+
raise error if Time.now >= time_limit
|
15
|
+
sleep interval
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'core/dsl'
|
data/lib/capybara/widgets.rb
CHANGED
@@ -33,8 +33,8 @@ describe Capybara::Widgets::Widget do
|
|
33
33
|
end
|
34
34
|
# Act and Assert
|
35
35
|
widget = MyWidget.new
|
36
|
-
expect(widget.loaded).to
|
36
|
+
expect(widget.loaded).to be false
|
37
37
|
widget.root
|
38
|
-
expect(widget.loaded).to
|
38
|
+
expect(widget.loaded).to be true
|
39
39
|
end
|
40
40
|
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.0
|
4
|
+
version: 0.1.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-
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: cucumber
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,7 +94,8 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
97
|
+
description: Easily create well-structured page and ui component classes in your Capybara
|
98
|
+
+ Cucumber or Rspec tests
|
98
99
|
email:
|
99
100
|
- vitalii[dot]grygoruk[at]gmail[dot]com
|
100
101
|
executables: []
|
@@ -102,18 +103,23 @@ extensions: []
|
|
102
103
|
extra_rdoc_files: []
|
103
104
|
files:
|
104
105
|
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
105
107
|
- Gemfile
|
106
108
|
- LICENSE.txt
|
107
109
|
- README.md
|
108
110
|
- Rakefile
|
109
111
|
- capybara-widgets.gemspec
|
110
112
|
- lib/capybara/widgets.rb
|
113
|
+
- lib/capybara/widgets/core/dsl.rb
|
111
114
|
- lib/capybara/widgets/core/page.rb
|
115
|
+
- lib/capybara/widgets/core/page_collection.rb
|
112
116
|
- lib/capybara/widgets/core/widget.rb
|
113
117
|
- lib/capybara/widgets/cucumber.rb
|
114
118
|
- lib/capybara/widgets/cucumber/page_steps.rb
|
115
119
|
- lib/capybara/widgets/cucumber/widget_steps.rb
|
120
|
+
- lib/capybara/widgets/helpers/async_helper.rb
|
116
121
|
- lib/capybara/widgets/helpers/string_helpers.rb
|
122
|
+
- lib/capybara/widgets/rspec.rb
|
117
123
|
- lib/capybara/widgets/version.rb
|
118
124
|
- spec/features/page_spec.rb
|
119
125
|
- spec/features/widget_spec.rb
|
@@ -141,7 +147,7 @@ rubyforge_project:
|
|
141
147
|
rubygems_version: 2.2.2
|
142
148
|
signing_key:
|
143
149
|
specification_version: 4
|
144
|
-
summary: Page
|
150
|
+
summary: Page objects and page components for Capybara
|
145
151
|
test_files:
|
146
152
|
- spec/features/page_spec.rb
|
147
153
|
- spec/features/widget_spec.rb
|