Use of capybara outside of any application

I’m trying to set up a cucumber/capybara test suite that I can use
outside of my rails app to drive testing from the outside in.

I’ve been reading through the capy README and thought I understood
this, but apparently I’m just missing something fundamental.

I am starting with just this simple file:

tamara@monovular Test/cukecapytest$ cat justtestit.rb
require ‘capybara’
require ‘capybara/dsl’
Capybara.default_driver = :selenium
Capybara.current_driver = :selenium
Capybara.run_server = false
Capybara.app_host = “http://www.google.com
module JustTestIt
include Capybara::DSL
def self.run
visit ‘/’
end
end

JustTestIt.run
tamara@monovular Test/cukecapytest$ ruby justtestit.rb
justtestit.rb:10:in run': undefined method visit’ for
JustTestIt:Module (NoMethodError)
from justtestit.rb:14:in `’

I thought doing the include would bring in the methods. When I do the
include and visit without the module warpper, I get a warning about
including Capybara::DSL in the global context, BUT, the visit works in
that case.

tamara@monovular Test/cukecapytest$ cat justtestitnomod.rb
require ‘capybara’
require ‘capybara/dsl’
Capybara.default_driver = :selenium
Capybara.current_driver = :selenium
Capybara.run_server = false
Capybara.app_host = “http://www.google.com
include Capybara::DSL
def run
visit ‘/’
end
run
tamara@monovular Test/cukecapytest$ ruby justtestitnomod.rb
including Capybara::DSL in the global scope is not recommended!

and it brings up a browser, goes to http://www.google.com/ as expected.

So there is something here I’m just not getting (not a capybara
problem, but a basic understanding of how the mixin works??)

halp?

Well, including module in module is a bit tricky. I think what you want
to do here is an extend, not an include.

include will put methods for instances of the class. Module’s instances
don’t exist, I don’t think that’s what you want to do.

On the other hand, extend will add methods in the singleton class of the
class (or here, the module) so that methods are accessible by the class
itself (or here, the module itself). So I guess you need to do this
instead :

module JustTestIt
extend Capybara::DSL
def self.run
visit ‘/’
end
end

Hope it helped !

tamouse mailing lists wrote in post #1111653:

I’m trying to set up a cucumber/capybara test suite that I can use
outside of my rails app to drive testing from the outside in.

I’ve been reading through the capy README and thought I understood
this, but apparently I’m just missing something fundamental.

I am starting with just this simple file:

tamara@monovular Test/cukecapytest$ cat justtestit.rb
require ‘capybara’
require ‘capybara/dsl’
Capybara.default_driver = :selenium
Capybara.current_driver = :selenium
Capybara.run_server = false
Capybara.app_host = “http://www.google.com
module JustTestIt
include Capybara::DSL
def self.run
visit ‘/’
end
end

JustTestIt.run
tamara@monovular Test/cukecapytest$ ruby justtestit.rb
justtestit.rb:10:in run': undefined method visit’ for
JustTestIt:Module (NoMethodError)
from justtestit.rb:14:in `’

I thought doing the include would bring in the methods. When I do the
include and visit without the module warpper, I get a warning about
including Capybara::DSL in the global context, BUT, the visit works in
that case.

tamara@monovular Test/cukecapytest$ cat justtestitnomod.rb
require ‘capybara’
require ‘capybara/dsl’
Capybara.default_driver = :selenium
Capybara.current_driver = :selenium
Capybara.run_server = false
Capybara.app_host = “http://www.google.com
include Capybara::DSL
def run
visit ‘/’
end
run
tamara@monovular Test/cukecapytest$ ruby justtestitnomod.rb
including Capybara::DSL in the global scope is not recommended!

and it brings up a browser, goes to http://www.google.com/ as expected.

So there is something here I’m just not getting (not a capybara
problem, but a basic understanding of how the mixin works??)

halp?

chloé r. [email protected] wrote:

module JustTestIt
extend Capybara::DSL
def self.run
visit ‘/’
end
end

Hope it helped !

Oh, yes, indeed! Dumb move, thinking include worked with module; I
know about extend!

Anyway, that did the trick, exactly. Thank you!