[rspec-users] Is it possible to access Example scope from Formatter?

David Chelimsky dchelimsky at gmail.com
Sun Oct 18 18:18:38 EDT 2009


On Sun, Oct 18, 2009 at 1:36 PM, Jarmo Pertman <jarmo.p at gmail.com> wrote:

> Hello.
>
> I'm using Watir to perform some user interface tests. I've made my own
> custom html formatter to make a screenshot and capture html of the
> page, on which some spec fails.
>
> Now, the problem is simple - I have to access the browser object from
> my formatter to get window handle (for screenshot) and to get html of
> the page. I thought that maybe it's possible to access the Example
> object directly so I could get access to Example object instance
> variables and helper methods, but it seems that only Proxies are in
> use everywhere and they seem to be pretty limited.
>
> Currently I'm just using global variable $browser instead, so I can
> access it from the Formatter, but I'm not happy with global variables.
>
> After fiddling around a little I thought that maybe someone has better
> solution for the above mentioned problem.
>


# in the example
it "does something" do
  options[:browser] = Selenium.new(...)
  ...
end

# in the formatter
def example_started(example)
  example.options[:browser] # => same browser created in the example
end

HTH,
David



Jarmo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091018/49c6efa7/attachment.html>


More information about the rspec-users mailing list