prismatic 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b860f32694f2a039255b65d1501f23ede0ddc1e
4
+ data.tar.gz: 313576b87a882d84baa3e9afce81b9a9e82799cd
5
+ SHA512:
6
+ metadata.gz: 868108bfccf0444c6533c20deeeb45af88fc0608f5eb7f5ce7e8072f7319c8d41efc4c773eafa585f51287666faa09f121b0ca0672de98e1efa08d70211cb187
7
+ data.tar.gz: 3bf56cee6ce21f8b8b7e5938b78e7fbd6f65c61b8cab9ce3234c2a06b9c977efd20d3ae841cb731f49f7ecd9712d6f3cd44b11a273ba0944ed26dfd30c49d432
@@ -0,0 +1,3 @@
1
+ /Gemfile.lock
2
+ /coverage/
3
+ /pkg/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -r spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in prismatic.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joe Yates
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.
@@ -0,0 +1,72 @@
1
+ # Prismatic
2
+
3
+ Use a naming convention inside your HTML to describe the DOM elements you
4
+ want to access during tests. Prismatic will set up your SitePrism::Pages
5
+ with the intended Sections and Elements.
6
+
7
+ ## Motivation
8
+
9
+ SitePrism is a wonderful tool for describing web pages in integration tests.
10
+ Unfortunately, it requires the creation of classes which use CSS selectors
11
+ (of XPath expressions) to indicate the elements of interest.
12
+
13
+ Prismatic aims to allow you skip the use of SitePrism's Page Object Model
14
+ by indicating in the web page itself which are the objects you want to access
15
+ in your tests thanks to [data attributes](http://www.w3.org/html/wg/drafts/html/master/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes).
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'prismatic'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ ```
28
+ $ bundle
29
+ ```
30
+
31
+ Or install it yourself as:
32
+
33
+ ```
34
+ $ gem install prismatic
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ Given a page containing this:
40
+
41
+ ```html
42
+ ...
43
+ <form data-prism-section="search" method="get" action="search">
44
+ <input type="text" data-prism-element="query">
45
+ <input type="submit" data-prism-element="start">
46
+ </form>
47
+ ...
48
+ ```
49
+
50
+ ## Configuration
51
+
52
+ In your test setup, do this:
53
+
54
+ ```ruby
55
+ Prismatic.configure do |conf|
56
+ conf.foo = :bar
57
+ end
58
+ ```
59
+
60
+ Configuration options:
61
+
62
+ * prefix: (default: 'prism'). By default, prismatic uses data attributes called
63
+ 'data-prism-*'. Set prefix to another value to allow data atributes to be
64
+ named differently.
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it ( https://github.com/[my-github-username]/prismatic/fork )
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task default: :spec
5
+
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.pattern = 'spec/**/*_spec.rb'
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'capybara'
2
+ require 'site_prism'
3
+
4
+ module Prismatic
5
+ end
6
+
7
+ require 'prismatic/element_container'
8
+ require 'prismatic/page'
9
+ require 'prismatic/section'
10
+ require 'prismatic/version'
@@ -0,0 +1,31 @@
1
+ module Prismatic::ElementContainer
2
+ private
3
+
4
+ def create_elements
5
+ find_matches 'element'
6
+ find_matches 'elements'
7
+ find_matches 'section'
8
+ find_matches 'sections'
9
+ end
10
+
11
+ def find_matches(type)
12
+ attribute = attribute_for(type)
13
+
14
+ find_all("[#{attribute}]").each do |el|
15
+ name = el[attribute]
16
+ if is_section?(type)
17
+ self.class.send type.intern, name, Prismatic::Section, "[#{attribute}=\"#{name}\"]"
18
+ else
19
+ self.class.send type.intern, name, "[#{attribute}=\"#{name}\"]"
20
+ end
21
+ end
22
+ end
23
+
24
+ def is_section?(type)
25
+ type.start_with?('section')
26
+ end
27
+
28
+ def attribute_for(type)
29
+ "data-prism-#{type}"
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ class Prismatic::Page < SitePrism::Page
2
+ include Prismatic::ElementContainer
3
+
4
+ def initialize
5
+ create_elements
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class Prismatic::Section < SitePrism::Section
2
+ include Prismatic::ElementContainer
3
+
4
+ def initialize(parent, root_element)
5
+ super
6
+ create_elements
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module Prismatic
2
+ MAJOR = 0
3
+ MINOR = 0
4
+ REVISION = 1
5
+ VERSION = [MAJOR, MINOR, REVISION].join('.')
6
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'prismatic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'prismatic'
8
+ spec.version = Prismatic::VERSION
9
+ spec.authors = ['Joe Yates']
10
+ spec.email = ['joe.g.yates@gmail.com']
11
+ spec.summary = "Automate SitePrism's access to DOM elements"
12
+ spec.description = <<-EOT.gsub(/^ +/, '').gsub(/\n/, ' ')
13
+ Thanks to a naming convention, Prismatic recognises the DOM elements in your
14
+ web pages that you intend to access during integration tests and automatically
15
+ creates the intended SitePrism sections and elements.
16
+ EOT
17
+ spec.homepage = 'https://github.com/joeyates/prismatic'
18
+ spec.license = 'MIT'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0")
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(spec)/})
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'site_prism', '~> 2.6'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.6'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+ spec_path = File.dirname(__FILE__)
3
+ $LOAD_PATH << File.expand_path('../lib', spec_path)
4
+
5
+ require 'prismatic'
@@ -0,0 +1,136 @@
1
+ describe Prismatic::Page do
2
+ def make_element(name, attribute)
3
+ el = double(Capybara::Node::Element)
4
+ allow(el).to receive(:[]).with(attribute).and_return(name)
5
+ el
6
+ end
7
+
8
+ def make_section(name, attribute)
9
+ el = double("Prismatic::Section, #{name}")
10
+ allow(el).to receive(:[]).with(attribute).and_return(name)
11
+ el
12
+ end
13
+
14
+ let(:page) { double(Capybara::Session) }
15
+ let(:page_element_array) { [] }
16
+ let(:page_elements_array) { [] }
17
+ let(:page_section_array) { [] }
18
+ let(:page_sections_array) { [] }
19
+ let(:singleton_element) { make_element('foo', 'data-prism-element') }
20
+ let(:collection_element) { make_element('bar', 'data-prism-elements') }
21
+
22
+ specify { expect(subject).to be_a(SitePrism::Page) }
23
+
24
+ before do
25
+ allow(Capybara).to receive(:current_session).and_return(page)
26
+ allow(page).to receive(:all).with('[data-prism-element]').and_return(page_element_array)
27
+ allow(page).to receive(:all).with('[data-prism-elements]').and_return(page_elements_array)
28
+ allow(page).to receive(:all).with('[data-prism-section]').and_return(page_section_array)
29
+ allow(page).to receive(:all).with('[data-prism-sections]').and_return(page_sections_array)
30
+ end
31
+
32
+ context "for 'data-prism-element' attributes" do
33
+ let(:page_element_array) { [singleton_element] }
34
+
35
+ it "creates a single element" do
36
+ expect(subject).to respond_to('foo')
37
+ end
38
+ end
39
+
40
+ context "for 'data-prism-elements' attributes" do
41
+ let(:page_elements_array) { [collection_element] }
42
+ let(:bar_elements_array) { page_elements_array }
43
+
44
+ before do
45
+ allow(page).to receive(:all).with('[data-prism-elements="bar"]').and_return(bar_elements_array)
46
+ end
47
+
48
+ it "creates an arrays of elements" do
49
+ expect(subject.bar).to be_a(Array)
50
+ end
51
+ end
52
+
53
+ context 'sections' do
54
+ context "for 'data-prism-section' attributes" do
55
+ let(:section_name) { 'singleton-section' }
56
+ let(:singleton_section) { make_section(section_name, 'data-prism-section') }
57
+ let(:page_section_array) { [singleton_section] }
58
+ let(:foo_element_array) { [] }
59
+ let(:bar_elements_array) { [] }
60
+ let(:nested_section_array) { [] }
61
+ let(:nested_sections_array) { [] }
62
+
63
+ before do
64
+ allow(page).to receive(:all).with("[data-prism-section=\"#{section_name}\"]").and_return([singleton_section])
65
+ allow(page).to receive(:find).with("[data-prism-section=\"#{section_name}\"]").and_return(singleton_section)
66
+ allow(singleton_section).to receive(:all).with('[data-prism-element]').and_return(foo_element_array)
67
+ allow(singleton_section).to receive(:all).with('[data-prism-elements]').and_return(bar_elements_array)
68
+ allow(singleton_section).to receive(:all).with('[data-prism-section]').and_return(nested_section_array)
69
+ allow(singleton_section).to receive(:all).with('[data-prism-sections]').and_return(nested_sections_array)
70
+ end
71
+
72
+ it "creates a single section" do
73
+ expect(subject).to respond_to(section_name)
74
+ end
75
+
76
+ context "with contained 'data-prism-element' attributes" do
77
+ let(:foo_element_array) { [singleton_element] }
78
+
79
+ before do
80
+ allow(singleton_section).to receive(:find).with('[data-prism-element="foo"]').and_return(singleton_element)
81
+ allow(singleton_section).to receive(:find).with('[data-prism-elements="foo"]').and_return([])
82
+ end
83
+
84
+ it 'creates an element' do
85
+ expect(subject.send(section_name)).to respond_to(:foo)
86
+ end
87
+ end
88
+
89
+ context "with contained 'data-prism-elements' attributes" do
90
+ let(:bar_elements_array) { [collection_element] }
91
+
92
+ before do
93
+ allow(singleton_section).to receive(:all).with('[data-prism-element="foo"]').and_return(foo_element_array)
94
+ allow(singleton_section).to receive(:all).with('[data-prism-elements="foo"]').and_return(bar_elements_array)
95
+ allow(singleton_section).to receive(:find).with('[data-prism-element="foo"]').and_return([])
96
+ allow(singleton_section).to receive(:find).with('[data-prism-elements="foo"]').and_return(collection_element)
97
+ end
98
+
99
+ it 'creates an element array' do
100
+ expect(subject.send(section_name).foo).to be_a(Array)
101
+ end
102
+ end
103
+
104
+ context "for heirarchies of DOM elements with 'data-prism-section' attributes" do
105
+ let(:baz_section) { make_section('baz', 'data-prism-section') }
106
+ let(:nested_section_array) { [baz_section] }
107
+
108
+ it "creates a heirarchy of sections containing elements" do
109
+ expect(subject.send(section_name)).to respond_to(:baz)
110
+ end
111
+ end
112
+ end
113
+
114
+ context "for 'data-prism-sections' attributes" do
115
+ let(:collection_name) { 'collection' }
116
+ let(:section_collection_member) { make_section(collection_name, 'data-prism-sections') }
117
+ let(:page_sections_array) { [section_collection_member] }
118
+ let(:foo_element_array) { [] }
119
+ let(:bar_elements_array) { [] }
120
+
121
+ before do
122
+ allow(page).to receive(:all).with('[data-prism-section]').and_return([])
123
+ allow(page).to receive(:all).with("[data-prism-sections=\"#{collection_name}\"]").and_return(page_sections_array)
124
+ allow(page).to receive(:find).with("[data-prism-sections=\"#{collection_name}\"]").and_return(section_collection_member)
125
+ allow(section_collection_member).to receive(:all).with('[data-prism-element]').and_return(foo_element_array)
126
+ allow(section_collection_member).to receive(:all).with('[data-prism-elements]').and_return(bar_elements_array)
127
+ allow(section_collection_member).to receive(:all).with('[data-prism-section]').and_return([])
128
+ allow(section_collection_member).to receive(:all).with('[data-prism-sections]').and_return([])
129
+ end
130
+
131
+ it "creates an array of sections" do
132
+ expect(subject.send(collection_name)).to be_a(Array)
133
+ end
134
+ end
135
+ end
136
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prismatic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joe Yates
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: site_prism
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: 'Thanks to a naming convention, Prismatic recognises the DOM elements
70
+ in your web pages that you intend to access during integration tests and automatically
71
+ creates the intended SitePrism sections and elements. '
72
+ email:
73
+ - joe.g.yates@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/prismatic.rb
85
+ - lib/prismatic/element_container.rb
86
+ - lib/prismatic/page.rb
87
+ - lib/prismatic/section.rb
88
+ - lib/prismatic/version.rb
89
+ - prismatic.gemspec
90
+ - spec/spec_helper.rb
91
+ - spec/unit/prismatic/page_spec.rb
92
+ homepage: https://github.com/joeyates/prismatic
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Automate SitePrism's access to DOM elements
116
+ test_files:
117
+ - spec/spec_helper.rb
118
+ - spec/unit/prismatic/page_spec.rb
119
+ has_rdoc: