capybara-widgets 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 243b219f6926b422cc9195f4aa9274dc814258e0
4
+ data.tar.gz: dc286684ad060709665a68e87debbd164a7d4421
5
+ SHA512:
6
+ metadata.gz: cc2e60040d367d6cd9188d032f2b85fe2359c8398e5ef2e8c1b0cabafde436ae885ede8b79a535933bd6f74cf80080045619df0e1dac5c8d11fa7aa6f141861c
7
+ data.tar.gz: b1a19e794f2a2476c306ecba086928408ef149b40f30150196e69a1e86fe50a50208101d439eb745e2a9a3b80157565d448d9cf676ffad8cb3ca06ff6e1a2a4d
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara-widgets.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Vitalii Grygoruk
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Capybara::Widgets
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'capybara-widgets'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install capybara-widgets
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/vgrigoruk/capybara-widgets/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capybara/widgets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capybara-widgets"
8
+ spec.version = Capybara::Widgets::VERSION
9
+ spec.authors = ["Vitalii Grygoruk"]
10
+ spec.email = ["vitalii[dot]grygoruk[at]gmail[dot]com"]
11
+ spec.summary = %q{Page object implementation for Capybara}
12
+ spec.description = %q{Another implementation of page object pattern for Capybara}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "cucumber"
25
+
26
+ spec.add_dependency "capybara", "~> 2.0"
27
+ spec.add_dependency "activesupport"
28
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'widget'
2
+ require 'active_support/core_ext/class/attribute'
3
+
4
+ module Capybara
5
+ module Widgets
6
+
7
+ class Page < Widget
8
+
9
+ class_attribute :path
10
+
11
+ def initialize
12
+ super(page)
13
+ end
14
+
15
+ def reload!
16
+ visit(current_url)
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,54 @@
1
+ require 'capybara/dsl'
2
+
3
+ module Capybara
4
+ module Widgets
5
+ class Widget
6
+ include Capybara::DSL
7
+
8
+ def initialize(*search_scope)
9
+ case search_scope.length
10
+ when 0
11
+ @root = page
12
+ when 1
13
+ @root = search_scope[0].respond_to?(:find) ? search_scope[0] : page.find(search_scope[0])
14
+ else
15
+ @root = page.find(*search_scope)
16
+ end
17
+ @narrowed = false
18
+ end
19
+
20
+ # running narrow only before a first call to root,
21
+ # useful when you want to call a method on widget that uses "page" and you don't want to run "narrow" during init
22
+ def root
23
+ unless @narrowed
24
+ @narrowed = true
25
+ @root = narrow
26
+ end
27
+ @root
28
+ end
29
+
30
+ # override this method if you need to narrow down search context for a particular UI widget / block
31
+ def narrow
32
+ @root
33
+ end
34
+
35
+ class << self
36
+ def component(name, klass, *query)
37
+ define_method name do
38
+ component_root = query.length > 0 ? root.find(*query) : root
39
+ klass.new(component_root)
40
+ end
41
+ end
42
+ end
43
+
44
+ # delegate missing methods to the @root node
45
+ def method_missing(method_sym, *arguments, &block)
46
+ if root.respond_to? method_sym
47
+ root.send(method_sym, *arguments, &block)
48
+ else
49
+ super
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,61 @@
1
+ module Capybara::Widgets::Cucumber
2
+
3
+ include Capybara::Widgets::StringHelpers
4
+
5
+ def within_widget(klass)
6
+ raise "#{klass.name} is not a subclass of Widget" unless klass < Capybara::Widgets::Widget
7
+ yield klass.new
8
+ end
9
+
10
+ When(/^I click "([^"]*)" in a "([^"]*)"$/) do |action, widget_name|
11
+ within_widget(to_widget_class(widget_name)) do |widget|
12
+ widget.send(to_widget_action(action, '!'))
13
+ end
14
+ end
15
+
16
+ Then(/^the "([^"]*)" should( not)? be displayed$/) do |widget_name, negated|
17
+ widget_class = to_widget_class(widget_name)
18
+ within_widget(widget_class) do |widget|
19
+ if negated
20
+ expect(widget).to be_not_displayed, "#{widget_class} should not be displayed"
21
+ else
22
+ expect(widget).to be_displayed, "#{widget_class} should be displayed"
23
+ end
24
+ end
25
+ end
26
+
27
+ When(/^I set "([^"]*)" to "([^"]*)" in a "([^"]*)"$/) do |field_name, value, widget_name|
28
+ within_widget(to_widget_class(widget_name)) do |widget|
29
+ widget.send(to_widget_action(field_name, '='), value)
30
+ end
31
+ end
32
+
33
+ And(/^I should see the following "([^"]*)" in a "([^"]*)"$/) do |field_name, widget_name, table|
34
+ expected_values = table.raw.flatten
35
+ within_widget(to_widget_class(widget_name)) do |widget|
36
+ actual_values = widget.send(to_widget_action(field_name))
37
+ expect(actual_values).to eq(expected_values)
38
+ end
39
+ end
40
+
41
+ When(/^I fill in the following in a "([^"]*)"$/) do |widget_name, table|
42
+ fields = table.rows_hash
43
+ within_widget(to_widget_class(widget_name)) do |widget|
44
+ fields.each do |k,v|
45
+ widget.send(to_widget_action(k, '='), v)
46
+ end
47
+ end
48
+ end
49
+
50
+ And(/^the "([^"]*)" should be "([^"]*)" in a "([^"]*)"$/) do |field_name, expected, widget_name|
51
+ within_widget(to_widget_class(widget_name)) do |widget|
52
+ action = to_widget_action(field_name)
53
+ if widget.respond_to? "has_#{action}?"
54
+ expect(widget.send("has_#{action}?", expected)).to be_true
55
+ else
56
+ actual = widget.send(action)
57
+ expect(actual).to eq(expected)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,9 @@
1
+ module Capybara::Widgets::StringHelpers
2
+ def to_widget_class(name)
3
+ name.to_s.gsub(' ','_').classify.constantize
4
+ end
5
+
6
+ def to_widget_action(name, suffix=nil)
7
+ "#{name.to_s.downcase.gsub(' ','_')}#{suffix}"
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Capybara
2
+ module Widgets
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "capybara/widgets/version"
2
+
3
+ module Capybara
4
+ module Widgets
5
+ autoload :Widget, 'capybara/widgets/core/widget'
6
+ autoload :Page, 'capybara/widgets/core/page'
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Capybara::Widgets::Page do
4
+ let(:klass) { Capybara::Widgets::Page }
5
+
6
+ it 'has page as a root' do
7
+ expect(klass.new.root).to eq(page)
8
+ end
9
+ end
@@ -0,0 +1,40 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Capybara::Widgets::Widget do
4
+ let(:klass) { Capybara::Widgets::Widget }
5
+ let(:stub_node) { Capybara::Node::Base.new(nil, nil) }
6
+
7
+ it 'has capybara page as a default root node' do
8
+ expect(subject.root).to eq(page)
9
+ end
10
+
11
+ it 'can be initialized with Capybara::Node::Base' do
12
+ expect(klass.new(stub_node).root).to eq(stub_node)
13
+ end
14
+
15
+ it 'can be initialized with string query' do
16
+ allow_any_instance_of(Capybara::Session).to receive(:driver).and_return(nil)
17
+ allow_any_instance_of(Capybara::Session).to receive(:find).with('.css-class').and_return(stub_node)
18
+ expect(klass.new('.css-class').root).to eq(stub_node)
19
+ end
20
+
21
+ it 'can be initialized with full query' do
22
+ allow_any_instance_of(Capybara::Session).to receive(:driver).and_return(nil)
23
+ allow_any_instance_of(Capybara::Session).to receive(:find).with(:xpath, '//somexpath', text: 'text', wait: 2).and_return(stub_node)
24
+ expect(klass.new(:xpath, '//somexpath', text: 'text', wait: 2).root).to eq(stub_node)
25
+ end
26
+
27
+ it 'can have lazy-initialized root node' do
28
+ # Arrange
29
+ class MyWidget < klass
30
+ attr_accessor :loaded
31
+ def initialize; self.loaded = false; end
32
+ def narrow; self.loaded = true; @root; end
33
+ end
34
+ # Act and Assert
35
+ widget = MyWidget.new
36
+ expect(widget.loaded).to be_false
37
+ widget.root
38
+ expect(widget.loaded).to be_true
39
+ end
40
+ end
@@ -0,0 +1,10 @@
1
+ require 'rspec'
2
+ require 'capybara/dsl'
3
+ require 'capybara/widgets'
4
+
5
+ Capybara.run_server = false
6
+
7
+ RSpec.configure do |c|
8
+ c.include Capybara::Widgets
9
+ c.include Capybara::DSL
10
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-widgets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vitalii Grygoruk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cucumber
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: capybara
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Another implementation of page object pattern for Capybara
98
+ email:
99
+ - vitalii[dot]grygoruk[at]gmail[dot]com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - capybara-widgets.gemspec
110
+ - lib/capybara/widgets.rb
111
+ - lib/capybara/widgets/core/page.rb
112
+ - lib/capybara/widgets/core/widget.rb
113
+ - lib/capybara/widgets/cucumber/widget_steps.rb
114
+ - lib/capybara/widgets/helpers/string_helpers.rb
115
+ - lib/capybara/widgets/version.rb
116
+ - spec/features/page_spec.rb
117
+ - spec/features/widget_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: ''
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.2
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Page object implementation for Capybara
143
+ test_files:
144
+ - spec/features/page_spec.rb
145
+ - spec/features/widget_spec.rb
146
+ - spec/spec_helper.rb