domino 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/{MIT-LICENSE → LICENSE.txt} +4 -2
- data/README.md +21 -2
- data/Rakefile +8 -0
- data/domino.gemspec +26 -0
- data/lib/domino.rb +15 -7
- data/lib/domino/version.rb +3 -0
- data/test/domino_test.rb +128 -0
- metadata +97 -66
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/{MIT-LICENSE → LICENSE.txt}
RENAMED
@@ -1,4 +1,6 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2012 Nick Gauthier
|
2
|
+
|
3
|
+
MIT License
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
6
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Domino
|
1
|
+
# Domino [![Build Status](http://travis-ci.org/ngauthier/domino.png)](http://travis-ci.org/ngauthier/domino)
|
2
2
|
|
3
3
|
View abstraction for integration testing
|
4
4
|
|
@@ -34,6 +34,25 @@ What makes it really powerful is defining scoped actions:
|
|
34
34
|
Dom::Post.find_by_title('First Post').delete
|
35
35
|
assert_nil Dom::Post.find_by_title('First Post')
|
36
36
|
|
37
|
+
## Integration with capybara
|
38
|
+
|
39
|
+
Domino uses capybara internally to search html for nodes and
|
40
|
+
attributes. If you need to do something special, you can have direct
|
41
|
+
access to the capybara node.
|
42
|
+
|
43
|
+
module Dom
|
44
|
+
class Account < Domino
|
45
|
+
selector "#accounts li"
|
46
|
+
# Returns this node text
|
47
|
+
def text
|
48
|
+
node.text
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
For more information about using Capybara nodes, check [Capybara Documentation](https://github.com/jnicklas/capybara/blob/master/README.rdoc).
|
54
|
+
|
55
|
+
|
37
56
|
## Integration with Cucumber
|
38
57
|
|
39
58
|
Add a features/support/dominos.rb file, in which you define your dominos.
|
@@ -53,7 +72,7 @@ in your test\_helper.rb (doesn't have to be inside a Rails test class).
|
|
53
72
|
|
54
73
|
## Example
|
55
74
|
|
56
|
-
Check out [Domino Example](http://github.com/ngauthier/domino_example) for an
|
75
|
+
Check out [Domino Example](http://github.com/ngauthier/domino_example) for an
|
57
76
|
example of using Test::Unit and Cucumber with Domino.
|
58
77
|
|
59
78
|
## Copyright
|
data/Rakefile
ADDED
data/domino.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.name = "domino"
|
4
|
+
gem.version = "0.3.1"
|
5
|
+
gem.platform = Gem::Platform::RUBY
|
6
|
+
gem.authors = ["Nick Gauthier"]
|
7
|
+
gem.email = ["ngauthier@gmail.com"]
|
8
|
+
gem.homepage = "http://github.com/ngauthier/domino"
|
9
|
+
gem.summary = "View abstraction for integration testing"
|
10
|
+
gem.description = %{
|
11
|
+
Make it easier to deal with UI elements by providing an
|
12
|
+
interface that decouples your tests from your views.
|
13
|
+
}
|
14
|
+
gem.rubygems_version = '>= 1.3.6'
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.extra_rdoc_files = ['README.md']
|
19
|
+
gem.license = 'MIT'
|
20
|
+
|
21
|
+
gem.add_dependency('capybara', '>= 0.4.0')
|
22
|
+
gem.add_development_dependency('minitest')
|
23
|
+
gem.add_development_dependency('rake')
|
24
|
+
gem.add_development_dependency('simplecov')
|
25
|
+
end
|
26
|
+
|
data/lib/domino.rb
CHANGED
@@ -65,6 +65,10 @@ class Domino
|
|
65
65
|
@selector = s
|
66
66
|
end
|
67
67
|
|
68
|
+
def attributes
|
69
|
+
@attributes ||= []
|
70
|
+
end
|
71
|
+
|
68
72
|
# Define an attribute for this Domino
|
69
73
|
#
|
70
74
|
# module Dom
|
@@ -81,6 +85,8 @@ class Domino
|
|
81
85
|
# Dom::Post.find_by_title("First Post")
|
82
86
|
# Dom::Post.find_by_title(/^First/)
|
83
87
|
def attribute(attribute, selector = nil)
|
88
|
+
attributes << attribute.to_sym
|
89
|
+
|
84
90
|
selector ||= %{.#{attribute.to_s}}
|
85
91
|
|
86
92
|
class_eval %{
|
@@ -103,14 +109,9 @@ class Domino
|
|
103
109
|
Capybara.current_session.all(@selector)
|
104
110
|
end
|
105
111
|
|
106
|
-
# Internal method for finding nodes by a selector
|
112
|
+
# Internal method for finding nodes by a selector
|
107
113
|
def find_by_attribute(selector, value)
|
108
|
-
|
109
|
-
when Regexp
|
110
|
-
detect{|node| node.attribute(selector) =~ value }
|
111
|
-
else
|
112
|
-
detect{|node| node.attribute(selector) == value }
|
113
|
-
end
|
114
|
+
detect{|node| value === node.attribute(selector) }
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
@@ -128,6 +129,13 @@ class Domino
|
|
128
129
|
@node['id'].nil? ? nil : %{##{@node['id']}}
|
129
130
|
end
|
130
131
|
|
132
|
+
def attributes
|
133
|
+
self.class.attributes.inject({}) do |memo, attribute|
|
134
|
+
memo[attribute] = send(attribute)
|
135
|
+
memo
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
131
139
|
private
|
132
140
|
# Store the capybara node internally
|
133
141
|
def initialize(node)
|
data/test/domino_test.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
unless ENV['CI']
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
end
|
6
|
+
Bundler.require
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'minitest/mock'
|
9
|
+
|
10
|
+
class TestApplication
|
11
|
+
def call(env)
|
12
|
+
[200, {"Content-Type" => "text/plain"}, [%{
|
13
|
+
<html>
|
14
|
+
<body>
|
15
|
+
<h1>Here are people and animals</h1>
|
16
|
+
<div id='people'>
|
17
|
+
<div class='person'>
|
18
|
+
<h2 class='name'>Alice</h2>
|
19
|
+
<p class='bio'>Alice is fun</p>
|
20
|
+
<p class='fav-color'>Blue</p>
|
21
|
+
</div>
|
22
|
+
<div class='person'>
|
23
|
+
<h2 class='name'>Bob</h2>
|
24
|
+
<p class='bio'>Bob is smart</p>
|
25
|
+
<p class='fav-color'>Red</p>
|
26
|
+
</div>
|
27
|
+
<div class='person'>
|
28
|
+
<h2 class='name'>Charlie</h2>
|
29
|
+
<p class='bio'>Charlie is wild</p>
|
30
|
+
<p class='fav-color'>Red</p>
|
31
|
+
</div>
|
32
|
+
<div class='person'>
|
33
|
+
<h2 class='name'>Donna</h2>
|
34
|
+
<p class='bio'>Donna is quiet</p>
|
35
|
+
</div>
|
36
|
+
</div>
|
37
|
+
<div id='animals'></div>
|
38
|
+
<div id='receipts'>
|
39
|
+
<div class='receipt' id='receipt-72' data-store='ACME'></div>
|
40
|
+
</div>
|
41
|
+
</body>
|
42
|
+
</html>
|
43
|
+
}]]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Capybara.app = TestApplication.new
|
48
|
+
|
49
|
+
|
50
|
+
class DominoTest < MiniTest::Unit::TestCase
|
51
|
+
include Capybara::DSL
|
52
|
+
module Dom
|
53
|
+
class Person < Domino
|
54
|
+
selector '#people .person'
|
55
|
+
attribute :name
|
56
|
+
attribute :biography, '.bio'
|
57
|
+
attribute :favorite_color, '.fav-color'
|
58
|
+
end
|
59
|
+
|
60
|
+
class Animal < Domino
|
61
|
+
selector '#animals .animal'
|
62
|
+
attribute :name
|
63
|
+
end
|
64
|
+
|
65
|
+
class Car < Domino
|
66
|
+
selector '#cars .car'
|
67
|
+
end
|
68
|
+
|
69
|
+
class NoSelector < Domino
|
70
|
+
end
|
71
|
+
|
72
|
+
class Receipt < Domino
|
73
|
+
selector '#receipts .receipt'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def setup
|
78
|
+
visit '/'
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_enumerable
|
82
|
+
assert_equal 4, Dom::Person.count
|
83
|
+
assert_equal 0, Dom::Animal.count
|
84
|
+
assert_equal 0, Dom::Car.count
|
85
|
+
|
86
|
+
assert_equal 4, Dom::Person.all.size
|
87
|
+
|
88
|
+
red_people = Dom::Person.select{|p| p.favorite_color == 'Red'}
|
89
|
+
assert_equal 2, red_people.count
|
90
|
+
|
91
|
+
assert_equal(
|
92
|
+
%w(Donna Alice Bob Charlie),
|
93
|
+
Dom::Person.sort{|a,b|
|
94
|
+
a.favorite_color.to_s <=> b.favorite_color.to_s
|
95
|
+
}.map(&:name)
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_no_selector
|
100
|
+
assert_raises Domino::Error do
|
101
|
+
Dom::NoSelector.first
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_no_id
|
106
|
+
assert_nil Dom::Person.first.id
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_id
|
110
|
+
assert_equal '#receipt-72', Dom::Receipt.first.id
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_find_by_attribute_string
|
114
|
+
assert_equal 'Alice', Dom::Person.find_by_biography('Alice is fun').name
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_find_by_attribute_regex
|
118
|
+
assert_equal 'Charlie', Dom::Person.find_by_biography(/wild/).name
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_node_properties
|
122
|
+
assert_equal 'ACME', Dom::Receipt.first.node['data-store']
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_attributes
|
126
|
+
assert_equal({:name => 'Alice', :biography => 'Alice is fun', :favorite_color => 'Blue'}, Dom::Person.first.attributes)
|
127
|
+
end
|
128
|
+
end
|
metadata
CHANGED
@@ -1,98 +1,129 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: domino
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 1
|
10
|
-
version: 0.2.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Nick Gauthier
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: capybara
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 15
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 4
|
33
|
-
- 0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
34
21
|
version: 0.4.0
|
35
22
|
type: :runtime
|
36
|
-
|
37
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.4.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
38
31
|
name: minitest
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
39
|
prerelease: false
|
40
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
49
54
|
type: :development
|
50
|
-
|
51
|
-
|
52
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: simplecov
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: ! "\n Make it easier to deal with UI elements by providing an\n interface
|
79
|
+
that decouples your tests from your views.\n "
|
80
|
+
email:
|
81
|
+
- ngauthier@gmail.com
|
53
82
|
executables: []
|
54
|
-
|
55
83
|
extensions: []
|
56
|
-
|
57
|
-
extra_rdoc_files:
|
84
|
+
extra_rdoc_files:
|
58
85
|
- README.md
|
59
|
-
files:
|
60
|
-
-
|
61
|
-
-
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .travis.yml
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE.txt
|
62
91
|
- README.md
|
63
|
-
|
64
|
-
|
65
|
-
|
92
|
+
- Rakefile
|
93
|
+
- domino.gemspec
|
94
|
+
- lib/domino.rb
|
95
|
+
- lib/domino/version.rb
|
96
|
+
- test/domino_test.rb
|
97
|
+
homepage: http://github.com/ngauthier/domino
|
98
|
+
licenses:
|
66
99
|
- MIT
|
67
100
|
post_install_message:
|
68
101
|
rdoc_options: []
|
69
|
-
|
70
|
-
require_paths:
|
102
|
+
require_paths:
|
71
103
|
- lib
|
72
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
105
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
segments:
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
segments:
|
79
111
|
- 0
|
80
|
-
|
81
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
hash: 2315885640870791480
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
114
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
segments:
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
segments:
|
88
120
|
- 0
|
89
|
-
|
121
|
+
hash: 2315885640870791480
|
90
122
|
requirements: []
|
91
|
-
|
92
123
|
rubyforge_project:
|
93
|
-
rubygems_version: 1.
|
124
|
+
rubygems_version: 1.8.23
|
94
125
|
signing_key:
|
95
126
|
specification_version: 3
|
96
127
|
summary: View abstraction for integration testing
|
97
|
-
test_files:
|
98
|
-
|
128
|
+
test_files:
|
129
|
+
- test/domino_test.rb
|