In my previous Watir question I was making a module with session_FF
accepting a block.
Now I want to make the same but via RSpec. Here is my try:
require "rspec"
require "watir"
module Session_FF
def method_missing m, *args, &block
@browser.send m, *args, &block
end
def element *args
elements = @browser.elements *args
case elements.size
when 1 ; elements.first
when 0 ; raise "found no nodes using search args: #{args}"
else ; raise "found #{es.size} nodes -- use #elements method or improve args"
end
end
end
RSpec.configure do |config|
config.include Session_FF
config.before{ @browser ||= Watir::Browser.new :ff}
config.after{ @browser.quit }
end
describe "it" do
it "is alive" do
goto "http://example.com/"
element(class: "userpanel").click
end
end
I see a problem, that previously I was defining method_missing
in my own module but now include
may redefine RSpec::Core::ExampleGroup
or smth's #method_missing
if it already exists or may appear in RSpec implementation. What is a better way for method_missing
approach to forward browser interaction methods into @browser
?