fracture 0.11.1 → 0.11.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.
- data/CHANGELOG.md +5 -0
- data/fracture.gemspec +1 -0
- data/lib/fracture/fracture.rb +32 -15
- data/lib/fracture/matchers/matcher.rb +16 -1
- data/lib/fracture/version.rb +1 -1
- data/spec/fracture_spec.rb +7 -0
- data/spec/matcher_spec.rb +47 -0
- metadata +18 -2
data/CHANGELOG.md
CHANGED
data/fracture.gemspec
CHANGED
data/lib/fracture/fracture.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
1
3
|
class Fracture
|
2
|
-
attr_accessor :label, :items, :is_text
|
4
|
+
attr_accessor :label, :items, :is_text, :is_path
|
3
5
|
|
4
|
-
def initialize label, items, is_text
|
6
|
+
def initialize label, items, is_text, is_path=false
|
5
7
|
self.label = label
|
6
8
|
self.items = Array(items)
|
7
9
|
self.is_text = is_text
|
10
|
+
self.is_path = is_path
|
8
11
|
end
|
9
12
|
|
10
13
|
def self.define_text label, *items
|
@@ -20,24 +23,25 @@ class Fracture
|
|
20
23
|
@all[label.to_s] = self.new(label, items.flatten, false)
|
21
24
|
end
|
22
25
|
|
26
|
+
def self.define_path label, *items
|
27
|
+
@all ||= {}
|
28
|
+
raise "#{label} has already been defined" if @all[label.to_s]
|
29
|
+
#items = ["##{label}"] if items.empty?
|
30
|
+
@all[label.to_s] = self.new(label, items.flatten, false, true)
|
31
|
+
end
|
32
|
+
|
23
33
|
def text?
|
24
34
|
!!is_text
|
25
35
|
end
|
26
36
|
|
37
|
+
def path?
|
38
|
+
!!is_path
|
39
|
+
end
|
40
|
+
|
27
41
|
def self.find label
|
28
|
-
|
29
|
-
|
30
|
-
#
|
31
|
-
# p label
|
32
|
-
# ret = all[label.to_s]
|
33
|
-
# raise "Fracture with Label of '#{label}' was not found" unless ret
|
34
|
-
# end
|
35
|
-
# p ret
|
36
|
-
#else
|
37
|
-
raise "No Fractures have been defined" if all.empty?
|
38
|
-
ret = all[label.to_s]
|
39
|
-
raise "Fracture with Label of '#{label}' was not found" unless ret
|
40
|
-
#end
|
42
|
+
raise 'No Fractures have been defined' if all.empty?
|
43
|
+
ret = all[label.to_s]
|
44
|
+
raise "Fracture with Label of '#{label}' was not found" unless ret
|
41
45
|
ret
|
42
46
|
end
|
43
47
|
|
@@ -75,6 +79,19 @@ class Fracture
|
|
75
79
|
end
|
76
80
|
end
|
77
81
|
|
82
|
+
def self.match_link page_parsed, link
|
83
|
+
items = link.split('_')
|
84
|
+
items.pop
|
85
|
+
case
|
86
|
+
when items.last.pluralize == items.last
|
87
|
+
items.join('\/d+\/')
|
88
|
+
page_parsed.css('a[href')
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
end
|
94
|
+
|
78
95
|
def self.test_fractures(page, is_not, fracture_labels, reverse_fracture_labels=[])
|
79
96
|
page = self.get_body(page)
|
80
97
|
failures = {}
|
@@ -28,6 +28,21 @@ RSpec::Matchers.define :have_all_fractures do
|
|
28
28
|
failure_message_for_should_not { |actual| common_error(actual, @results) }
|
29
29
|
end
|
30
30
|
|
31
|
+
RSpec::Matchers.define :have_no_fractures do
|
32
|
+
match do |page|
|
33
|
+
@results = Fracture.test_fractures page, false, nil, Fracture.all.keys
|
34
|
+
@results[:passed]
|
35
|
+
end
|
36
|
+
|
37
|
+
match_for_should_not do |page|
|
38
|
+
@results = Fracture.test_fractures page, true, nil, Fracture.all.keys
|
39
|
+
@results[:passed]
|
40
|
+
end
|
41
|
+
|
42
|
+
failure_message_for_should { |actual| common_error(actual, @results) }
|
43
|
+
failure_message_for_should_not { |actual| common_error(actual, @results) }
|
44
|
+
end
|
45
|
+
|
31
46
|
RSpec::Matchers.define :have_all_fractures_except do |*fracture_labels|
|
32
47
|
match do |page|
|
33
48
|
@results = Fracture.have_all_except_test(page, false, fracture_labels)
|
@@ -71,7 +86,7 @@ end
|
|
71
86
|
|
72
87
|
RSpec::Matchers.define :have_a_form do
|
73
88
|
match do |page|
|
74
|
-
page = Nokogiri::HTML.parse(page)
|
89
|
+
page = Nokogiri::HTML.parse(Fracture.get_body(page))
|
75
90
|
@edit_found = page.at("input[type='hidden'][name='_method'][value='put']")
|
76
91
|
@has_form = page.at("form[method='post']")
|
77
92
|
#TODO refactor this
|
data/lib/fracture/version.rb
CHANGED
data/spec/fracture_spec.rb
CHANGED
@@ -7,6 +7,13 @@ describe Fracture do
|
|
7
7
|
|
8
8
|
before { Fracture.clear }
|
9
9
|
|
10
|
+
context 'define_path' do
|
11
|
+
before { Fracture.define_path(:companies, 'companies_path') }
|
12
|
+
subject { Fracture.find(:companies) }
|
13
|
+
its(:items) { should == ['companies_path'] }
|
14
|
+
its(:path?) { should be_true }
|
15
|
+
end
|
16
|
+
|
10
17
|
context "without data" do
|
11
18
|
it("should be empty before use") { Fracture.all.should == {} }
|
12
19
|
it "should not fail when no data set" do
|
data/spec/matcher_spec.rb
CHANGED
@@ -4,6 +4,53 @@ require "fracture/fracture"
|
|
4
4
|
require "fracture/matchers/matcher"
|
5
5
|
|
6
6
|
describe Fracture do
|
7
|
+
context 'path' do
|
8
|
+
let (:body) {
|
9
|
+
<<BODY
|
10
|
+
<body>
|
11
|
+
<a href="/companies">Index</a>
|
12
|
+
<a href="/companies/12">Show</a>
|
13
|
+
<a href="/companies/12/edit">Edit</a>
|
14
|
+
<a href="/companies/new">New</a>
|
15
|
+
<a href="/companies/12" data-method="delete">Delete</a>
|
16
|
+
|
17
|
+
<a href="/companies/12/contacts">Index</a>
|
18
|
+
<a href="/companies/12/contacts/345">Show</a>
|
19
|
+
<a href="/companies/12/contacts/345/edit">Edit</a>
|
20
|
+
<a href="/companies/12/contacts/new">New</a>
|
21
|
+
<a href="/companies/12/contacts/345" data-method="delete">Delete</a>
|
22
|
+
</body>
|
23
|
+
|
24
|
+
BODY
|
25
|
+
}
|
26
|
+
=begin
|
27
|
+
# Examples
|
28
|
+
companies_link
|
29
|
+
company_link
|
30
|
+
edit_company_link
|
31
|
+
new_company_link
|
32
|
+
delete_company_link
|
33
|
+
=end
|
34
|
+
let(:page_parsed) { Nokogiri::HTML.parse(body) }
|
35
|
+
|
36
|
+
it 'concept 3' do
|
37
|
+
build = []
|
38
|
+
page_parsed.css('a[href]').map do |item|
|
39
|
+
build << item['href']+(item['data-method'] ? '/delete' :'')
|
40
|
+
end
|
41
|
+
# index
|
42
|
+
p build.grep /\/companies\/\d+\/contacts$/
|
43
|
+
# show
|
44
|
+
p build.grep /\/companies\/\d+\/contacts\/\d+$/
|
45
|
+
# edit
|
46
|
+
p build.grep /\/companies\/\d+\/contacts\/\d+\/edit$/
|
47
|
+
# new
|
48
|
+
p build.grep /\/companies\/\d+\/contacts\/new$/
|
49
|
+
# delete
|
50
|
+
p build.grep /\/companies\/\d+\/contacts\/\d+\/delete$/
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
7
54
|
context "form" do
|
8
55
|
context "when no form exists" do
|
9
56
|
before { @page = "<p>not a form</p>" }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fracture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: inflections
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rspec
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|