Domino
View abstraction for integration testing
Usage
To create a basic Domino class, inherit from Domino and define a selector and attributes:
module Dom
class Post < Domino
selector '#posts .post'
attribute :title # selector defaults to .title
attribute :body, '.post-body' # example of selector override
# pass a block if you want to modify the value
attribute :comments do |text|
text.to_i
end
attribute :posted_at do |text|
Date.parse(text)
end
end
end
Now in your integration test you can use some of Domino's methods:
assert_equal 4, Dom::Post.count
refute_nil Dom::Post.find_by_title('First Post')
What makes it really powerful is defining scoped actions:
module Dom
class Post < Domino
def delete
within(id) { 'Delete' }
end
end
end
refute_nil Dom::Post.find_by_title('First Post')
Dom::Post.find_by_title('First Post').delete
assert_nil Dom::Post.find_by_title('First Post')
Integration with capybara
Domino uses capybara internally to search html for nodes and attributes. If you need to do something special, you can have direct access to the capybara node.
module Dom
class Account < Domino
selector "#accounts li"
# Returns this node text
def text
node.text
end
end
end
For more information about using Capybara nodes, check Capybara Documentation.
Integration with Cucumber
Add a features/support/dominos.rb file, in which you define your dominos.
Use them in your steps.
Integration with Test::Unit
Include "domino" in your Gemfile if using bundler, or simply
require 'domino'
If you're not using Bundler.
Now, define your Dominos anywhere you want. The easiest place to start is in your test_helper.rb (doesn't have to be inside a Rails test class).
Example
Check out Domino Example for an example of using Test::Unit and Cucumber with Domino.
Copyright
Copyright (c) 2011 Nick Gauthier, released under the MIT license