prismatic 0.0.1 → 0.0.2
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/README.md +25 -2
- data/lib/prismatic/page.rb +2 -1
- data/lib/prismatic/version.rb +1 -1
- data/spec/unit/prismatic/page_spec.rb +92 -80
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f0581313ae448d49bcb2922bc29dde490719734
|
4
|
+
data.tar.gz: 2a4cc58f82cf3e92d2cfe4d60421f31e6434004c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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:
|
data/lib/prismatic/page.rb
CHANGED
data/lib/prismatic/version.rb
CHANGED
@@ -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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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(
|
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
|
-
|
49
|
-
|
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
|
-
|
54
|
-
|
55
|
-
let(:
|
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(
|
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
|
73
|
-
expect(subject).to
|
59
|
+
it "creates an arrays of elements" do
|
60
|
+
expect(subject.bar).to be_a(Array)
|
74
61
|
end
|
62
|
+
end
|
75
63
|
|
76
|
-
|
77
|
-
|
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(
|
81
|
-
allow(
|
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
|
85
|
-
expect(subject
|
83
|
+
it "creates a single section" do
|
84
|
+
expect(subject).to respond_to(section_name)
|
86
85
|
end
|
87
|
-
end
|
88
86
|
|
89
|
-
|
90
|
-
|
87
|
+
context "with contained 'data-prism-element' attributes" do
|
88
|
+
let(:foo_element_array) { [singleton_element] }
|
91
89
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
100
|
-
|
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
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
109
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
132
|
-
|
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
|