S Ahmed
2012-Sep-27 02:25 UTC
[rspec-users] load global variable so I can access in spec files
In my spec_helper, I want to load yaml file to a variable, and then be able to use that in my tests. spec_helper.rb: RSpec.configure do |config| end config = YAML::Load(......) some_spec.rb describe ''blah'' do it "should be...." do MyClass.new( config[''test''] ) end end How can I do this? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120926/e456e4de/attachment.html>
Andy Lindeman
2012-Sep-27 03:17 UTC
[rspec-users] load global variable so I can access in spec files
On Wed, Sep 26, 2012 at 10:25 PM, S Ahmed <sahmed1020 at gmail.com> wrote:> How can I do this?If it''s truly something that just needs to be loaded once and then is used without mutation in any number of tests, you might just set it to a constant in spec_helper.rb: CONFIG = YAML.load("...") MyClass.new(CONFIG) -- Andy Lindeman http://www.andylindeman.com/
S Ahmed
2012-Sep-28 02:16 UTC
[rspec-users] load global variable so I can access in spec files
I do have it in my spec_helper, does it have to be inside the RSpec.config block? On Wed, Sep 26, 2012 at 11:17 PM, Andy Lindeman <alindeman at gmail.com> wrote:> On Wed, Sep 26, 2012 at 10:25 PM, S Ahmed <sahmed1020 at gmail.com> wrote: > > How can I do this? > > If it''s truly something that just needs to be loaded once and then is > used without mutation in any number of tests, you might just set it to > a constant in spec_helper.rb: > > CONFIG = YAML.load("...") > > MyClass.new(CONFIG) > > -- > Andy Lindeman > http://www.andylindeman.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120927/eed10879/attachment.html>
Andy Lindeman
2012-Sep-28 02:39 UTC
[rspec-users] load global variable so I can access in spec files
Not if it''s a constant. You''ll need to make sure it starts with a capital letter for it to be interpreted as such by Ruby; otherwise it''s just a local variable. On Thursday, September 27, 2012, S Ahmed wrote:> I do have it in my spec_helper, does it have to be inside the RSpec.config > block? > > On Wed, Sep 26, 2012 at 11:17 PM, Andy Lindeman <alindeman at gmail.com<javascript:_e({}, ''cvml'', ''alindeman at gmail.com'');> > > wrote: > >> On Wed, Sep 26, 2012 at 10:25 PM, S Ahmed <sahmed1020 at gmail.com<javascript:_e({}, ''cvml'', ''sahmed1020 at gmail.com'');>> >> wrote: >> > How can I do this? >> >> If it''s truly something that just needs to be loaded once and then is >> used without mutation in any number of tests, you might just set it to >> a constant in spec_helper.rb: >> >> CONFIG = YAML.load("...") >> >> MyClass.new(CONFIG) >> >> -- >> Andy Lindeman >> http://www.andylindeman.com/ >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org <javascript:_e({}, ''cvml'', >> ''rspec-users at rubyforge.org'');> >> http://rubyforge.org/mailman/listinfo/rspec-users >> > >-- Sent from a mobile device. Please excuse the brevity and top reply. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120927/dd257539/attachment-0001.html>