Skip to content

Commit

Permalink
WIP - added methods to define actions -- they still need a way to be …
Browse files Browse the repository at this point in the history
…declared in modules
  • Loading branch information
Luke Cunningham committed Apr 23, 2010
1 parent 0051aaa commit 3a2051a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
3 changes: 2 additions & 1 deletion features/step_definitions/github_example_steps.rb
Expand Up @@ -20,7 +20,8 @@

Then /^the user is on a github repository details page$/ do
on_page_with :github_repo_details do |page|
page.should be_valid
# page.should be_valid
page.perform :login, 'email', 'password'
end
end

Expand Down
2 changes: 1 addition & 1 deletion features/support/pages/page_with_github_repo_details.rb
Expand Up @@ -11,4 +11,4 @@ def repo_details
end
end

end
end
4 changes: 4 additions & 0 deletions features/support/pages/page_with_github_search.rb
Expand Up @@ -13,4 +13,8 @@ def search_form
end
end

define_action :search do |query|
fill_in search_form.input.attr('name').value, :with => query
end

end
14 changes: 13 additions & 1 deletion lib/gizmo/page.rb
Expand Up @@ -29,14 +29,26 @@ def has_selector? css_selector
@document.css(css_selector).length > 0
end

private
def perform action_name, *params
self.send("#{action_name.to_s}_action", *params)
end

def method_missing name, *args
method_name = name.to_sym
@browser.send(method_name, *args) if @browser.respond_to?(method_name)
end

private
def element_struct
open_struct = OpenStruct.new
yield open_struct if block_given?
open_struct
end

def define_action action_name, &block
self.class.send(:define_method, "#{action_name.to_s}_action".to_sym, &block)
end

end

end
2 changes: 1 addition & 1 deletion spec/github_site_example_spec.rb
Expand Up @@ -25,7 +25,7 @@

it "should have a text input which accepts a search query" do
on_page_with :github_search do |page|
fill_in page.search_form.input.attr('name').value, :with => 'gizmo'
page.perform :search, 'gizmo'
end
end

Expand Down
33 changes: 28 additions & 5 deletions spec/gizmo/page_spec.rb
Expand Up @@ -48,12 +48,14 @@ def current_url
end
end


describe "@url" do
it "should return the expected string" do
@page.instance_variable_get(:@url).should == "http://www.example.com"
end
end


describe "@mixins" do
it "should be accessible with .mixins" do
@page.mixins.should equal @page.instance_variable_get(:@mixins)
Expand Down Expand Up @@ -96,18 +98,41 @@ def current_url

end

describe "#extended_with" do

describe "#extended_with" do
it "should add the mixin name to the Page's @mixin instance attribute" do
on_page_with(:my_mixin, :my_other_mixin) do |page|
[:my_mixin, :my_other_mixin].each { |m| page.mixins.should include Object.const_get("PageWith#{m.to_s.camelize}") }
end
end
end


describe "#define_action" do

it "should be a private method" do
@page.should_not respond_to :define_action
end

it "should define a new action within page" do
@page.send(:define_action, :tell) { |message| message }
@page.should respond_to :tell_action
end
end

describe "#has_selector?" do

it "should provide a :perform method" do
@page.should respond_to :perform
end

describe "#perform" do
it "should call a defined action" do
@page.send(:define_action, :tell) { |message| message }
@page.perform(:tell, "hello world").should == "hello world"
end
end

describe "#has_selector?" do
it "should return true if @document contains one or more elements matching the selector" do
@page.has_selector?('p.one_of_these').should be_true
@page.has_selector?('p.two_of_these').should be_true
Expand All @@ -116,19 +141,17 @@ def current_url
it "should return false if @document does not contain one or more elements matching the selector" do
@page.has_selector?('p.does_not_exist').should be_false
end

end

describe "#element_struct" do

describe "#element_struct" do
it "should provide an override for OpenStruct to make it yield to a block" do
@page.send(:element_struct) { |o| o.should be_an OpenStruct }
end

it "should return an OpenStruct if not given a block" do
@page.send(:element_struct).should be_an OpenStruct
end

end

end
Expand Down

0 comments on commit 3a2051a

Please sign in to comment.