Module: Watir::RSpec::Helper

Extended by:
Forwardable
Defined in:
lib/watir/rspec/helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args)

Will dispatch all missing methods to the #browser instance.

Examples:

Makes it possible to use Watir::Browser methods without specifying the browser instance in the specs like this:

it "should do something" do
  # notice that we're calling Watir::Browser#text_field here directly
  text_field(:id => "foo").should be_present
end


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/watir/rspec/helper.rb', line 20

def method_missing(name, *args)
  if browser.respond_to?(name)
    Helper.module_eval %Q[
      def #{name}(*args)
        browser.send(:#{name}, *args) {yield}
      end
    ]
    self.send(name, *args) {yield}
  else
    super
  end
end

Instance Method Details

#browserWatir::Browser

Returns a current browser instance if it is initialized with @browser or $browser variable name.

Returns:

  • (Watir::Browser)

    a current browser instance if it is initialized with @browser or $browser variable name.



10
11
12
# File 'lib/watir/rspec/helper.rb', line 10

def browser
  @browser || $browser
end