Discussion:
[Cucumber] [Ruby/Cucumber] Extend the visibility of objects to step definitions
(too old to reply)
Kruthi
2018-03-08 23:52:41 UTC
Permalink
Hi,

I am trying to include sql queries in my tests so I have written the below
code:








































*module Database_env class DAO attr_accessor :db def self.daos @@daos ||= Database_env::DAO.new() puts "in self" return @@daos end @@HOST = '...' @@SSH_USER = 'tester' @@DB_HOST = "...." @@PWD = "...." def initialize() gateway = Net::SSH::Gateway.new(@@HOST, @@SSH_USER, :password => @@PWD) port = gateway.open(@@DB_HOST,3306,3306) @db = Sequel.connect(:adapter => 'mysql2', :host => '127.0.0.1',:port => port, :user => 'tester', :password => @@PWD, :database => '...') #puts @db['select id from epms_placeholder'].count puts "in initialise" end def select_id() puts @db['select id from user'].count puts "in select" end puts "in class" ***@daos = Database_env::DAO.daos*

This file is placed in the support folder and Im trying to call the select method in the step definitions using the object @daos, but it seems like the object is not being recognised and hence the method is not called.


Can you please point me in the right direction of how to achieve what Im trying to do? I have tried googling for solutions was unable to find out.


I would really appreciate any help.


Thanks,

Kruthi
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Eric Kessler
2018-03-15 23:54:30 UTC
Permalink
Post by Kruthi
Hi,
I am trying to include sql queries in my tests so I have written the below
You appear to have declared an instance variable in a random Ruby file.
This makes it an instance variable on the top level runtime object. The
Ruby version of Cucumber maintains state throughout a test using a World
object. If you declare an instance variable inside of a hook or step
definition then it will be an instance variable of the World object and
thus be available to other steps and hooks.
Post by Kruthi
Can you please point me in the right direction of how to achieve what Im trying to do? I have tried googling for solutions was unable to find out.
I would really appreciate any help.
Thanks,
Kruthi
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andrew Premdas
2018-03-16 03:36:52 UTC
Permalink
Cucumber has a World which you can add modules too to make things available
in step definitions. Be aware that method names are global by design, so
using a method name like select is not a good idea. You could add your
module with the code

World(Database_env)

and that would mean that the select method would be available in your step
definitions.

I am not at all sure what you are trying to do with the DAO class or why
you want to add queries to your tests. Perhaps you could state your
intentions at a higher level. What do you need these queries for? Perhaps
give some examples of scenarios and stepdefs that would use this stuff.
Post by Eric Kessler
Post by Kruthi
Hi,
I am trying to include sql queries in my tests so I have written the
You appear to have declared an instance variable in a random Ruby file.
This makes it an instance variable on the top level runtime object. The
Ruby version of Cucumber maintains state throughout a test using a World
object. If you declare an instance variable inside of a hook or step
definition then it will be an instance variable of the World object and
thus be available to other steps and hooks.
Post by Kruthi
Can you please point me in the right direction of how to achieve what Im trying to do? I have tried googling for solutions was unable to find out.
I would really appreciate any help.
Thanks,
Kruthi
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
------------------------
Andrew Premdas
blog.andrew.premdas.org
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...