prismatic 0.0.1 → 0.0.2

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: 3b860f32694f2a039255b65d1501f23ede0ddc1e
4
- data.tar.gz: 313576b87a882d84baa3e9afce81b9a9e82799cd
3
+ metadata.gz: 8f0581313ae448d49bcb2922bc29dde490719734
4
+ data.tar.gz: 2a4cc58f82cf3e92d2cfe4d60421f31e6434004c
5
5
  SHA512:
6
- metadata.gz: 868108bfccf0444c6533c20deeeb45af88fc0608f5eb7f5ce7e8072f7319c8d41efc4c773eafa585f51287666faa09f121b0ca0672de98e1efa08d70211cb187
7
- data.tar.gz: 3bf56cee6ce21f8b8b7e5938b78e7fbd6f65c61b8cab9ce3234c2a06b9c977efd20d3ae841cb731f49f7ecd9712d6f3cd44b11a273ba0944ed26dfd30c49d432
6
+ metadata.gz: c8b506871ce9d027a3b92cbe4672d72bdd2095f02a0953a44aa9b8a6f4ec9af609fe9796f37da3b34ac49ffb6adb7d78c0922c260ee531052988d47d7169cdab
7
+ data.tar.gz: 37999d4ff131a9df65259ca01e6955b4a85ff15ae84d4e44fbe521577f9eb1f05f277ce7756d4200e42032a2613c0ea8a4ac800e6c81d005b88b5e09feb3a2b6
data/README.md CHANGED
@@ -36,17 +36,40 @@ $ gem install prismatic
36
36
 
37
37
  ## Usage
38
38
 
39
- Given a page containing this:
39
+ Add the following attributes to your HTML markup:
40
+
41
+ * data-prism-element
42
+ * data-prism-elements
43
+ * data-prism-section
44
+ * data-prism-sections
45
+
46
+ Given a 'search#index' page containing this:
40
47
 
41
48
  ```html
42
49
  ...
43
50
  <form data-prism-section="search" method="get" action="search">
44
51
  <input type="text" data-prism-element="query">
45
- <input type="submit" data-prism-element="start">
52
+ <input type="submit" data-prism-element="start" value="Search">
46
53
  </form>
47
54
  ...
48
55
  ```
49
56
 
57
+ Create a page class:
58
+
59
+ ```ruby
60
+ class SearchIndexPage < Prismatic::Page
61
+ set_url '/search'
62
+ end
63
+ ```
64
+
65
+ When you load the page, the sections and elements are defined:
66
+
67
+ ```ruby
68
+ search_page = SearchIndexPage.new
69
+ search_page.load
70
+ expect(search_page.search.start.text).to eq('Search')
71
+ ```
72
+
50
73
  ## Configuration
51
74
 
52
75
  In your test setup, do this:
@@ -1,7 +1,8 @@
1
1
  class Prismatic::Page < SitePrism::Page
2
2
  include Prismatic::ElementContainer
3
3
 
4
- def initialize
4
+ def load
5
+ super
5
6
  create_elements
6
7
  end
7
8
  end
@@ -1,6 +1,6 @@
1
1
  module Prismatic
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- REVISION = 1
4
+ REVISION = 2
5
5
  VERSION = [MAJOR, MINOR, REVISION].join('.')
6
6
  end
@@ -1,3 +1,7 @@
1
+ class MyPage < Prismatic::Page
2
+ set_url '/'
3
+ end
4
+
1
5
  describe Prismatic::Page do
2
6
  def make_element(name, attribute)
3
7
  el = double(Capybara::Node::Element)
@@ -11,7 +15,7 @@ describe Prismatic::Page do
11
15
  el
12
16
  end
13
17
 
14
- let(:page) { double(Capybara::Session) }
18
+ let(:page) { double(Capybara::Session, visit: nil) }
15
19
  let(:page_element_array) { [] }
16
20
  let(:page_elements_array) { [] }
17
21
  let(:page_section_array) { [] }
@@ -21,115 +25,123 @@ describe Prismatic::Page do
21
25
 
22
26
  specify { expect(subject).to be_a(SitePrism::Page) }
23
27
 
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')
28
+ describe '#load' do
29
+ subject do
30
+ page = MyPage.new
31
+ page.load
32
+ page
37
33
  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
34
 
44
35
  before do
45
- allow(page).to receive(:all).with('[data-prism-elements="bar"]').and_return(bar_elements_array)
36
+ allow(Capybara).to receive(:current_session).and_return(page)
37
+ allow(page).to receive(:all).with('[data-prism-element]').and_return(page_element_array)
38
+ allow(page).to receive(:all).with('[data-prism-elements]').and_return(page_elements_array)
39
+ allow(page).to receive(:all).with('[data-prism-section]').and_return(page_section_array)
40
+ allow(page).to receive(:all).with('[data-prism-sections]').and_return(page_sections_array)
46
41
  end
47
42
 
48
- it "creates an arrays of elements" do
49
- expect(subject.bar).to be_a(Array)
43
+ context "for 'data-prism-element' attributes" do
44
+ let(:page_element_array) { [singleton_element] }
45
+
46
+ it "creates a single element" do
47
+ expect(subject).to respond_to('foo')
48
+ end
50
49
  end
51
- end
52
50
 
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) { [] }
51
+ context "for 'data-prism-elements' attributes" do
52
+ let(:page_elements_array) { [collection_element] }
53
+ let(:bar_elements_array) { page_elements_array }
62
54
 
63
55
  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)
56
+ allow(page).to receive(:all).with('[data-prism-elements="bar"]').and_return(bar_elements_array)
70
57
  end
71
58
 
72
- it "creates a single section" do
73
- expect(subject).to respond_to(section_name)
59
+ it "creates an arrays of elements" do
60
+ expect(subject.bar).to be_a(Array)
74
61
  end
62
+ end
75
63
 
76
- context "with contained 'data-prism-element' attributes" do
77
- let(:foo_element_array) { [singleton_element] }
64
+ context 'sections' do
65
+ context "for 'data-prism-section' attributes" do
66
+ let(:section_name) { 'singleton-section' }
67
+ let(:singleton_section) { make_section(section_name, 'data-prism-section') }
68
+ let(:page_section_array) { [singleton_section] }
69
+ let(:foo_element_array) { [] }
70
+ let(:bar_elements_array) { [] }
71
+ let(:nested_section_array) { [] }
72
+ let(:nested_sections_array) { [] }
78
73
 
79
74
  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([])
75
+ allow(page).to receive(:all).with("[data-prism-section=\"#{section_name}\"]").and_return([singleton_section])
76
+ allow(page).to receive(:find).with("[data-prism-section=\"#{section_name}\"]").and_return(singleton_section)
77
+ allow(singleton_section).to receive(:all).with('[data-prism-element]').and_return(foo_element_array)
78
+ allow(singleton_section).to receive(:all).with('[data-prism-elements]').and_return(bar_elements_array)
79
+ allow(singleton_section).to receive(:all).with('[data-prism-section]').and_return(nested_section_array)
80
+ allow(singleton_section).to receive(:all).with('[data-prism-sections]').and_return(nested_sections_array)
82
81
  end
83
82
 
84
- it 'creates an element' do
85
- expect(subject.send(section_name)).to respond_to(:foo)
83
+ it "creates a single section" do
84
+ expect(subject).to respond_to(section_name)
86
85
  end
87
- end
88
86
 
89
- context "with contained 'data-prism-elements' attributes" do
90
- let(:bar_elements_array) { [collection_element] }
87
+ context "with contained 'data-prism-element' attributes" do
88
+ let(:foo_element_array) { [singleton_element] }
91
89
 
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)
90
+ before do
91
+ allow(singleton_section).to receive(:find).with('[data-prism-element="foo"]').and_return(singleton_element)
92
+ allow(singleton_section).to receive(:find).with('[data-prism-elements="foo"]').and_return([])
93
+ end
94
+
95
+ it 'creates an element' do
96
+ expect(subject.send(section_name)).to respond_to(:foo)
97
+ end
97
98
  end
98
99
 
99
- it 'creates an element array' do
100
- expect(subject.send(section_name).foo).to be_a(Array)
100
+ context "with contained 'data-prism-elements' attributes" do
101
+ let(:bar_elements_array) { [collection_element] }
102
+
103
+ before do
104
+ allow(singleton_section).to receive(:all).with('[data-prism-element="foo"]').and_return(foo_element_array)
105
+ allow(singleton_section).to receive(:all).with('[data-prism-elements="foo"]').and_return(bar_elements_array)
106
+ allow(singleton_section).to receive(:find).with('[data-prism-element="foo"]').and_return([])
107
+ allow(singleton_section).to receive(:find).with('[data-prism-elements="foo"]').and_return(collection_element)
108
+ end
109
+
110
+ it 'creates an element array' do
111
+ expect(subject.send(section_name).foo).to be_a(Array)
112
+ end
101
113
  end
102
- end
103
114
 
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] }
115
+ context "for heirarchies of DOM elements with 'data-prism-section' attributes" do
116
+ let(:baz_section) { make_section('baz', 'data-prism-section') }
117
+ let(:nested_section_array) { [baz_section] }
107
118
 
108
- it "creates a heirarchy of sections containing elements" do
109
- expect(subject.send(section_name)).to respond_to(:baz)
119
+ it "creates a heirarchy of sections containing elements" do
120
+ expect(subject.send(section_name)).to respond_to(:baz)
121
+ end
110
122
  end
111
123
  end
112
- end
113
124
 
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) { [] }
125
+ context "for 'data-prism-sections' attributes" do
126
+ let(:collection_name) { 'collection' }
127
+ let(:section_collection_member) { make_section(collection_name, 'data-prism-sections') }
128
+ let(:page_sections_array) { [section_collection_member] }
129
+ let(:foo_element_array) { [] }
130
+ let(:bar_elements_array) { [] }
120
131
 
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
132
+ before do
133
+ allow(page).to receive(:all).with('[data-prism-section]').and_return([])
134
+ allow(page).to receive(:all).with("[data-prism-sections=\"#{collection_name}\"]").and_return(page_sections_array)
135
+ allow(page).to receive(:find).with("[data-prism-sections=\"#{collection_name}\"]").and_return(section_collection_member)
136
+ allow(section_collection_member).to receive(:all).with('[data-prism-element]').and_return(foo_element_array)
137
+ allow(section_collection_member).to receive(:all).with('[data-prism-elements]').and_return(bar_elements_array)
138
+ allow(section_collection_member).to receive(:all).with('[data-prism-section]').and_return([])
139
+ allow(section_collection_member).to receive(:all).with('[data-prism-sections]').and_return([])
140
+ end
130
141
 
131
- it "creates an array of sections" do
132
- expect(subject.send(collection_name)).to be_a(Array)
142
+ it "creates an array of sections" do
143
+ expect(subject.send(collection_name)).to be_a(Array)
144
+ end
133
145
  end
134
146
  end
135
147
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prismatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Yates