Skip to content

Commit

Permalink
Syntax sugar to define elements on a page. Closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Apr 18, 2012
1 parent 8c5b730 commit 136f5af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/capybara-page-object/node.rb
Expand Up @@ -20,5 +20,9 @@ def classes
def source
@source ||= Capybara.current_session
end

def self.element(name, &block)
define_method(name, &block)
end
end
end
9 changes: 9 additions & 0 deletions spec/node_spec.rb
Expand Up @@ -18,5 +18,14 @@
anchor = CapybaraPageObject::Anchor.from_string '<a/>', 'a'
anchor.classes.should be_empty
end

it "has a nice DSL" do
source = mock
source.should_receive(:find_button).with('place_order')
class Bar < CapybaraPageObject::Node
element(:place_order) { source.find_button('place_order') }
end
Bar.new(source).place_order
end
end
end

0 comments on commit 136f5af

Please sign in to comment.