1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

removed whitespace and added dsl shortcut to evaluate_script method

This commit is contained in:
Dennis Rogenius 2009-12-12 13:33:00 +01:00
parent 7867084063
commit 525ba2d654
8 changed files with 92 additions and 56 deletions

View file

@ -6,6 +6,7 @@ module Capybara
class CapybaraError < StandardError; end
class DriverNotFoundError < CapybaraError; end
class ElementNotFound < CapybaraError; end
class NotSupportedByDriverError < CapybaraError; end
class << self
attr_accessor :debug, :asset_root

View file

@ -50,7 +50,7 @@ module Capybara
:visit, :body, :click_link, :click_button, :fill_in, :choose, :has_xpath?, :has_css?,
:check, :uncheck, :attach_file, :select, :has_content?, :within, :within_fieldset,
:within_table, :save_and_open_page, :find, :find_field, :find_link, :find_button,
:field_labeled, :all
:field_labeled, :all, :evaluate_script
]
SESSION_METHODS.each do |method|
class_eval <<-RUBY, __FILE__, __LINE__+1

View file

@ -158,6 +158,14 @@ module Capybara
button || find("//button[@id='#{locator}' or @value='#{locator}' or contains(.,'#{locator}')]")
end
def evaluate_script(script)
begin
driver.evaluate_script(script)
rescue NoMethodError
raise NotSupportedByDriverError
end
end
private
def css_to_xpath(css)

View file

@ -114,6 +114,7 @@ describe Capybara do
end
it_should_behave_like "session"
it_should_behave_like "session without javascript driver"
it "should be possible to include it in another class" do
klass = Class.new do

View file

@ -19,5 +19,6 @@ describe Capybara::Session do
end
it_should_behave_like "session"
it_should_behave_like "session with javascript driver"
end
end

View file

@ -19,5 +19,6 @@ describe Capybara::Session do
end
it_should_behave_like "session"
it_should_behave_like "session without javascript driver"
end
end

View file

@ -19,5 +19,6 @@ describe Capybara::Session do
end
it_should_behave_like "session"
it_should_behave_like "session with javascript driver"
end
end

View file

@ -793,6 +793,28 @@ shared_examples_for "session" do
extract_results(@session)['villain_name'].should == 'Quantum'
end
end
end
shared_examples_for "session with javascript driver" do
describe "#evaluate_script" do
before{ @session.visit('/with_js') }
it "should return the evaluated script" do
@session.evaluate_script("1+3").should == 4
end
end
end
shared_examples_for "session without javascript driver" do
describe "#evaluate_script" do
before{ @session.visit('/with_js') }
it "should raise an error" do
running {
@session.evaluate_script("1+5")
}.should raise_error(Capybara::NotSupportedByDriverError)
end
end
end
describe Capybara::Session do
@ -804,3 +826,4 @@ describe Capybara::Session do
end
end
end