From dbatshaw at gmail.com Mon Mar 1 15:32:35 2010
From: dbatshaw at gmail.com (drewB)
Date: Mon, 1 Mar 2010 12:32:35 -0800 (PST)
Subject: [rspec-users] Integration testing without cucumber
Message-ID: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
I need to create some integration tests without cucumber. Can anyone
point me in the right direction for how to do that in rails? I tried
creating specs under 'spec/integration/' but no matchers are being
included. I also tried rspec_integration plugin (http://github.com/
tricycle/rspec-integration) but that only defines a few matchers and
response.should be_success doesn't work properly.
Any help you can provide would be much appreciated!
From joe at josephwilk.net Mon Mar 1 16:27:39 2010
From: joe at josephwilk.net (Joseph Wilk)
Date: Mon, 01 Mar 2010 21:27:39 +0000
Subject: [rspec-users] Integration testing without cucumber
In-Reply-To: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
Message-ID: <4B8C314B.6070604@josephwilk.net>
drewB wrote:
> I need to create some integration tests without cucumber. Can anyone
> point me in the right direction for how to do that in rails? I tried
> creating specs under 'spec/integration/' but no matchers are being
> included. I also tried rspec_integration plugin (http://github.com/
> tricycle/rspec-integration) but that only defines a few matchers and
> response.should be_success doesn't work properly.
>
> Any help you can provide would be much appreciated!
>
You should not need any magic to get rspec working.
In order to run integration specs I've been using a very simple
spec_helper.rb.
Maybe this can be some help to you;
http://gist.github.com/318821
--
Joseph Wilk
http://blog.josephwilk.net
http://www.songkick.com
mob: +44(0)7812816431
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
>
From win at wincent.com Mon Mar 1 16:54:02 2010
From: win at wincent.com (Wincent Colaiuta)
Date: Mon, 1 Mar 2010 22:54:02 +0100
Subject: [rspec-users] Integration testing without cucumber
In-Reply-To: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
Message-ID: <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com>
El 01/03/2010, a las 21:32, drewB escribi?:
> I need to create some integration tests without cucumber. Can anyone
> point me in the right direction for how to do that in rails? I tried
> creating specs under 'spec/integration/' but no matchers are being
> included. I also tried rspec_integration plugin (http://github.com/
> tricycle/rspec-integration) but that only defines a few matchers and
> response.should be_success doesn't work properly.
>
> Any help you can provide would be much appreciated!
You could try Steak:
http://github.com/cavalle/steak
Cheers,
Wincent
From dansteinicke at gmail.com Mon Mar 1 17:24:53 2010
From: dansteinicke at gmail.com (DanS)
Date: Mon, 1 Mar 2010 14:24:53 -0800 (PST)
Subject: [rspec-users] Can have_selector Match Only Part of an Elements
Class String?
Message-ID: <41173af8-9d63-4f05-9eb0-8da38e3a6ffe@l12g2000prg.googlegroups.com>
I would like to find a way to check for the existence of a class on a
element in a calendar. The | s are the days of the calendar
and can have various classes assigned. I want to test if a day has
the 'past' class and don't care (in this test) if other classes
(weekend, today, etc) are present. So far I've only been able to use
have_selector('td', :class=>'some class') if the class string matches
exactly. Is there an easy way to match if the class 'past' is just
present in the string? (wildcards, regex, whatever)
Making the test match the string exactly feels like it makes the test
too complicated and loose its focus on the single thing I want to
test.
Thanks to anyone who can offer advice on this.
Dan Steinicke
From dchelimsky at gmail.com Mon Mar 1 17:26:39 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Mon, 1 Mar 2010 16:26:39 -0600
Subject: [rspec-users] Can have_selector Match Only Part of an Elements
Class String?
In-Reply-To: <41173af8-9d63-4f05-9eb0-8da38e3a6ffe@l12g2000prg.googlegroups.com>
References: <41173af8-9d63-4f05-9eb0-8da38e3a6ffe@l12g2000prg.googlegroups.com>
Message-ID: <57c63afe1003011426m405b6275tfa45dd3dacec6715@mail.gmail.com>
On Mon, Mar 1, 2010 at 4:24 PM, DanS wrote:
> I would like to find a way to check for the existence of a class on a
> | element in a calendar. ?The | s are the days of the calendar
> and can have various classes assigned. ?I want to test if a day has
> the 'past' class and don't care (in this test) if other classes
> (weekend, today, etc) are present. ?So far I've only been able to use
> have_selector('td', :class=>'some class') if the class string matches
> exactly. ?Is there an easy way to match if the class 'past' is just
> present in the string? (wildcards, regex, whatever)
>
> Making the test match the string exactly feels like it makes the test
> too complicated and loose its focus on the single thing I want to
> test.
>
> Thanks to anyone who can offer advice on this.
This is a webrat question. If nobody answers you here, check the
webrat group: http://groups.google.com/group/webrat.
HTH,
David
From dbatshaw at gmail.com Mon Mar 1 17:59:56 2010
From: dbatshaw at gmail.com (drewB)
Date: Mon, 1 Mar 2010 14:59:56 -0800 (PST)
Subject: [rspec-users] Integration testing without cucumber
In-Reply-To: <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com>
References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
<0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com>
Message-ID: <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com>
Belwo is a spec that when used with the default spec_helper fails
with:
NoMethodError in 'test matchers should be able to find be_success'
undefined method `be_success' for
#
----------
require 'spec_helper'
describe "test matchers" do
it "should be able to find be_success" do
get '/'
response.should be_success
end
end
-------------
From dchelimsky at gmail.com Mon Mar 1 18:04:06 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Mon, 1 Mar 2010 17:04:06 -0600
Subject: [rspec-users] Integration testing without cucumber
In-Reply-To: <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com>
References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
<0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com>
<28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com>
Message-ID: <57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com>
On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote:
> Belwo is a spec that when used with the default spec_helper fails
> with:
>
> NoMethodError in 'test matchers should be able to find be_success'
> undefined method `be_success' for
> #
>
> ----------
>
> require 'spec_helper'
>
> describe "test matchers" do
> ?it "should be able to find be_success" do
> ? ?get '/'
> ? ?response.should be_success
> ?end
>
> end
Try adding this to spec/spec_helper.rb
Spec::Runner.configure {|c| c.include Spec::Matchers}
From dbatshaw at gmail.com Mon Mar 1 19:06:29 2010
From: dbatshaw at gmail.com (drewB)
Date: Mon, 1 Mar 2010 16:06:29 -0800 (PST)
Subject: [rspec-users] Integration testing without cucumber
In-Reply-To: <57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com>
References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
<0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com>
<28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com>
<57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com>
Message-ID: <8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com>
That fixed it! Thanks!
Any idea why that was needed for integration specs and not MVCs?
On Mar 1, 3:04?pm, David Chelimsky wrote:
> On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote:
> > Belwo is a spec that when used with the default spec_helper fails
> > with:
>
> > NoMethodError in 'test matchers should be able to find be_success'
> > undefined method `be_success' for
> > #
>
> > ----------
>
> > require 'spec_helper'
>
> > describe "test matchers" do
> > ?it "should be able to find be_success" do
> > ? ?get '/'
> > ? ?response.should be_success
> > ?end
>
> > end
>
> Try adding this to spec/spec_helper.rb
>
> Spec::Runner.configure {|c| c.include Spec::Matchers}
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
From dansteinicke at gmail.com Tue Mar 2 00:15:12 2010
From: dansteinicke at gmail.com (DanS)
Date: Mon, 1 Mar 2010 21:15:12 -0800 (PST)
Subject: [rspec-users] Can have_selector Match Only Part of an Elements
Class String?
In-Reply-To: <57c63afe1003011426m405b6275tfa45dd3dacec6715@mail.gmail.com>
References: <41173af8-9d63-4f05-9eb0-8da38e3a6ffe@l12g2000prg.googlegroups.com>
<57c63afe1003011426m405b6275tfa45dd3dacec6715@mail.gmail.com>
Message-ID: <4b2944ff-962c-4845-ba69-2006e4c35fee@b9g2000pri.googlegroups.com>
On Mar 1, 2:26?pm, David Chelimsky wrote:
> On Mon, Mar 1, 2010 at 4:24 PM, DanS wrote:
> > I would like to find a way to check for the existence of a class on a
> > | element in a calendar. ?The | s are the days of the calendar
> > and can have various classes assigned. ?I want to test if a day has
> > the 'past' class and don't care (in this test) if other classes
> > (weekend, today, etc) are present. ?So far I've only been able to use
> > have_selector('td', :class=>'some class') if the class string matches
> > exactly. ?Is there an easy way to match if the class 'past' is just
> > present in the string? (wildcards, regex, whatever)
>
> > Making the test match the string exactly feels like it makes the test
> > too complicated and loose its focus on the single thing I want to
> > test.
>
> > Thanks to anyone who can offer advice on this.
>
> This is a webrat question. If nobody answers you here, check the
> webrat group:http://groups.google.com/group/webrat.
>
> HTH,
> David
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Thanks David.
Sorry for posting to wrong place. Posted on webrat group here:
http://groups.google.com/group/webrat/browse_thread/thread/ac30dec93f842316
From lists at ruby-forum.com Tue Mar 2 03:39:03 2010
From: lists at ruby-forum.com (Zhenning Guan)
Date: Tue, 2 Mar 2010 09:39:03 +0100
Subject: [rspec-users] how to mock a Net::Http object?
Message-ID:
one_data = Net::HTTP.post_form(URI.parse(country_site), {'country' =>
"american"})
two_data = Net::HTTP.post_form(URI.parse(visit_site), {'country' =>
"english"})
I have a code similar like above code in my application, so how to mock
a a object like above? if only post_from once, I just need to stub
post_form, but now, it has different parameter, how to do it?
Net::HTTP.stub!(:post_form).and_return('my_data')
--
Posted via http://www.ruby-forum.com/.
From aslak.hellesoy at gmail.com Tue Mar 2 03:49:36 2010
From: aslak.hellesoy at gmail.com (aslak hellesoy)
Date: Tue, 2 Mar 2010 09:49:36 +0100
Subject: [rspec-users] how to mock a Net::Http object?
In-Reply-To:
References:
Message-ID: <8d961d901003020049s1a2eaad9m17ea31eab981473e@mail.gmail.com>
On Tue, Mar 2, 2010 at 9:39 AM, Zhenning Guan wrote:
> one_data = Net::HTTP.post_form(URI.parse(country_site), {'country' =>
> "american"})
> two_data = Net::HTTP.post_form(URI.parse(visit_site), {'country' =>
> "english"})
>
> I have a code similar like above code in my application, so how to mock
> a a object like above? if only post_from once, I just need to stub
> post_form, but now, it has different parameter, how to do it?
>
>
http://github.com/blaine/fakeweb
Aslak
> Net::HTTP.stub!(:post_form).and_return('my_data')
> --
> Posted via http://www.ruby-forum.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:
From kmandrup at gmail.com Tue Mar 2 08:42:28 2010
From: kmandrup at gmail.com (Kristian Mandrup)
Date: Tue, 2 Mar 2010 05:42:28 -0800 (PST)
Subject: [rspec-users] Configuring RSpec 2
Message-ID: <6674f783-a431-4acb-8cca-30777246c817@z11g2000yqz.googlegroups.com>
# spec_helper.rb
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require '...
require 'rspec'
require 'rspec/autorun'
# doesn't work: just remove it and it works.
# But how would you configure the RSpec Runner in RSpec 2 then?
Rspec::Runner.configure do |config|
# config here
end
Then I found this:
Rspec::Core.configure do |c|
# config here
end
Which works :)
From dchelimsky at gmail.com Tue Mar 2 08:59:25 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Tue, 2 Mar 2010 07:59:25 -0600
Subject: [rspec-users] Configuring RSpec 2
In-Reply-To: <6674f783-a431-4acb-8cca-30777246c817@z11g2000yqz.googlegroups.com>
References: <6674f783-a431-4acb-8cca-30777246c817@z11g2000yqz.googlegroups.com>
Message-ID: <57c63afe1003020559n127802odc743b30bddc8c3c@mail.gmail.com>
On Tue, Mar 2, 2010 at 7:42 AM, Kristian Mandrup wrote:
> # spec_helper.rb
>
> $LOAD_PATH.unshift(File.dirname(__FILE__))
> $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
> require '...
> require 'rspec'
> require 'rspec/autorun'
>
> # doesn't work: just remove it and it works.
> # But how would you configure the RSpec Runner in RSpec 2 then?
> Rspec::Runner.configure do |config|
> ?# config here
> end
>
> Then I found this:
>
> Rspec::Core.configure do |c|
> ?# config here
> end
>
> Which works :)
And is deprecated :) Use this:
Rspec.configure do |c|
# config here
end
From dchelimsky at gmail.com Tue Mar 2 09:51:22 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Tue, 2 Mar 2010 08:51:22 -0600
Subject: [rspec-users] RSpec-2 and The RSpec Book
Message-ID: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com>
Hey all,
I'm happy to announce that The RSpec Book will be updated for RSpec-2
and Rails-3 before its final release. This, of course, means that the
print schedule will get pushed back, but we'll have a couple of more
beta releases of the book before we go to print. I don't know the
exact schedule right now, but I'll follow up as it shapes up.
Cheers,
David
From tom at experthuman.com Tue Mar 2 10:37:39 2010
From: tom at experthuman.com (Tom Stuart)
Date: Tue, 2 Mar 2010 15:37:39 +0000
Subject: [rspec-users] RSpec-2 and The RSpec Book
In-Reply-To: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com>
References: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com>
Message-ID: <8EB26CE1-ECCA-44D8-9E2A-B6055D71E6C1@experthuman.com>
On 2 Mar 2010, at 14:51, David Chelimsky wrote:
> I'm happy to announce that The RSpec Book will be updated for RSpec-2
> and Rails-3 before its final release.
Wow, this is great news. Thanks, David! I'm sure it'll be well worth the wait; having the beta book available in the meantime gives RSpec users the best of both worlds.
Cheers,
-Tom
From rick.denatale at gmail.com Tue Mar 2 10:51:48 2010
From: rick.denatale at gmail.com (Rick DeNatale)
Date: Tue, 2 Mar 2010 10:51:48 -0500
Subject: [rspec-users] RSpec-2 and The RSpec Book
In-Reply-To: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com>
References: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com>
Message-ID:
On Tue, Mar 2, 2010 at 9:51 AM, David Chelimsky wrote:
> Hey all,
>
> I'm happy to announce that The RSpec Book will be updated for RSpec-2
> and Rails-3 before its final release. This, of course, means that the
> print schedule will get pushed back, but we'll have a couple of more
> beta releases of the book before we go to print. I don't know the
> exact schedule right now, but I'll follow up as it shapes up.
Good news. It's hard for a dead-tree book authors to keep up with
changing software, even when he/she/they are the folks changing the
software.
I guess that the current beta PDF will serve as the best checkpoint
for RSpec 1 and Rails 2.x. I guess it's time to print a personal
hard-copy.
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
From dchelimsky at gmail.com Tue Mar 2 11:38:33 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Tue, 2 Mar 2010 10:38:33 -0600
Subject: [rspec-users] RSpec-2 and The RSpec Book
In-Reply-To:
References: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com>
Message-ID: <57c63afe1003020838m359beeb5sba55ccfd539bbe93@mail.gmail.com>
On Tue, Mar 2, 2010 at 9:51 AM, Rick DeNatale wrote:
> On Tue, Mar 2, 2010 at 9:51 AM, David Chelimsky wrote:
>> Hey all,
>>
>> I'm happy to announce that The RSpec Book will be updated for RSpec-2
>> and Rails-3 before its final release. This, of course, means that the
>> print schedule will get pushed back, but we'll have a couple of more
>> beta releases of the book before we go to print. I don't know the
>> exact schedule right now, but I'll follow up as it shapes up.
>
> Good news. ?It's hard for a dead-tree book authors to keep up with
> changing software, even when he/she/they are the folks changing the
> software.
>
> I guess that the current beta PDF will serve as the best checkpoint
> for RSpec 1 and Rails 2.x. ?I guess it's time to print a personal
> hard-copy.
That is probably a good idea, but we'll be including notes in the book
about differences w/ the previous versions.
From dbatshaw at gmail.com Tue Mar 2 12:53:05 2010
From: dbatshaw at gmail.com (drewB)
Date: Tue, 2 Mar 2010 09:53:05 -0800 (PST)
Subject: [rspec-users] Integration testing without cucumber
In-Reply-To: <8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com>
References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
<0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com>
<28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com>
<57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com>
<8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com>
Message-ID: <3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com>
Looks like I spoke too soon. I made a mistake when testing your
suggest. When I add that I still get the same failure.
On Mar 1, 4:06?pm, drewB wrote:
> That fixed it! Thanks!
>
> Any idea why that was needed for integration specs and not MVCs?
>
> On Mar 1, 3:04?pm, David Chelimsky wrote:
>
> > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote:
> > > Belwo is a spec that when used with the default spec_helper fails
> > > with:
>
> > > NoMethodError in 'test matchers should be able to find be_success'
> > > undefined method `be_success' for
> > > #
>
> > > ----------
>
> > > require 'spec_helper'
>
> > > describe "test matchers" do
> > > ?it "should be able to find be_success" do
> > > ? ?get '/'
> > > ? ?response.should be_success
> > > ?end
>
> > > end
>
> > Try adding this to spec/spec_helper.rb
>
> > Spec::Runner.configure {|c| c.include Spec::Matchers}
> > _______________________________________________
> > rspec-users mailing list
> > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
From reed.adam at gmail.com Tue Mar 2 12:24:10 2010
From: reed.adam at gmail.com (Adam R)
Date: Tue, 2 Mar 2010 09:24:10 -0800 (PST)
Subject: [rspec-users] RSpec and Watir, easy script structure question
Message-ID: <27758607.post@talk.nabble.com>
Howdy! I'm relatively new to RSpec, but I've worked with Watir and Ruby for
about 5 years now. My company is redesigning a web app from the ground up,
so I'm taking the opportunity to leverage RSpec instead of Test/Unit.
I've run into a problem with RSpec organization that I just can't sort out
on my own, so I'm hoping it's straightforward enough that someone can help
me out.
Basically I have a single HTML page with an organized list of links. Each
link points to a new page with a single verifiable item on it. The script
collects all the links into an array, then iterates over the array, loading
each link and verifying a single piece of text. That's the easy part.
Here's the relevant code for what I believe to be the closest attempt right
now:
@links = Array.new
@browser = Watir::Browser.new
@browser.goto(page)
@browser.link.each do |link|
@links << [link.name, link.href]
end
@links.each do |name, link|
describe name do
it "should contain the word #{name}" do
@browser.goto link
@browser.div(:id, /example/).text.should include(name)
end #it
end #desc
end #@links
I've tried a combination of methods -- putting all of this code inside a
describe block, etc, but I end up with the variables being unknown because
they're not inside the same describe or it block (even when set to $global),
or the describe/it blocks being layered incorrectly.
I'm sure there's a simple solution to the format, but unfortunately I
haven't been able to Google or RDoc my way to an answer. I appreciate any
advice you can offer!
Thanks,
Adam
--
View this message in context: http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27758607.html
Sent from the rspec-users mailing list archive at Nabble.com.
From dbatshaw at gmail.com Tue Mar 2 14:22:55 2010
From: dbatshaw at gmail.com (drewB)
Date: Tue, 2 Mar 2010 11:22:55 -0800 (PST)
Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts
Message-ID: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com>
There is a nice little gem that gives you desktop notifications of
your spec commands called test_noitifer (http://github.com/fnando/
test_notifier). I can get it to work by including require
"test_notifier/rspec" toward the top of my spec_helper, or by manually
including it in the command line like:
spec --require "test_notifier/rspec"
However, if I add it to the top of my spec.opts file, I get the
following error:
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require': no such file to load -- "test_notifier/
rspec" (LoadError)
Any ideas on how to make it work? I don't want to add it to
spec_helper because then others on my team would need to use the gem
as well (which they might not want to).
From dchelimsky at gmail.com Tue Mar 2 14:33:22 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Tue, 2 Mar 2010 13:33:22 -0600
Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts
In-Reply-To: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com>
References: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com>
Message-ID: <57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com>
On Tue, Mar 2, 2010 at 1:22 PM, drewB wrote:
> There is a nice little gem that gives you desktop notifications of
> your spec commands called test_noitifer (http://github.com/fnando/
> test_notifier). ?I can get it to work by including require
> "test_notifier/rspec" toward the top of my spec_helper, or by manually
> including it in the command line like:
>
> spec --require "test_notifier/rspec"
>
> However, if I add it to the top of my spec.opts file, I get the
> following error:
>
> /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
> `gem_original_require': no such file to load -- "test_notifier/
> rspec" (LoadError)
>
> Any ideas on how to make it work? ?I don't want to add it to
> spec_helper because then others on my team would need to use the gem
> as well (which they might not want to).
spec.opts is not a ruby file, so you can't put it there. Why not add
it to a ruby file in spec/support/ that you don't keep in source
control?
From phillipkoebbe at gmail.com Tue Mar 2 14:38:08 2010
From: phillipkoebbe at gmail.com (Phillip Koebbe)
Date: Tue, 02 Mar 2010 13:38:08 -0600
Subject: [rspec-users] stub and should_receive
In-Reply-To: <4B8D67E0.2000606@gmail.com>
References: <4B8D67E0.2000606@gmail.com>
Message-ID: <4B8D6920.9090002@gmail.com>
Nevermind. If I would have waited five more minutes before clicking
"Send", I would have seen my error.
Blech.
Phillip Koebbe wrote:
> What is the expected behavior when a model has both stub and
> should_receive defined for the same method?
>
> I have a helper method which creates an admin "logged in":
>
> def stub_user(is_administrator)
> user = stub_model(User)
> user.stub(:is_administrator).and_return(is_administrator)
> User.stub(:find_by_id).and_return(user)
> user
> end
>
> def setup_admin
> @admin = stub_user(true)
> session[:user_id] = @admin.id
> end
>
> In an admin controller spec, I have to setup_admin so the specs can
> get to the controllers, but then later in particular contexts, I do
>
> @some_user = stub_model(User)
> User.should_receive(:find_by_id).and_return(@some_user)
>
> This is to simulate selecting a user from a list and either showing or
> editing details. Based on what I'm seeing, it appears that the the
> find_by_id return values are getting mixed up. Am I wrong to attempt
> to use both of these or should this work as I expect? If the latter,
> then I have more digging to do to determine what's going wrong.
>
> Thanks,
> Phillip
From phillipkoebbe at gmail.com Tue Mar 2 14:32:48 2010
From: phillipkoebbe at gmail.com (Phillip Koebbe)
Date: Tue, 02 Mar 2010 13:32:48 -0600
Subject: [rspec-users] stub and should_receive
Message-ID: <4B8D67E0.2000606@gmail.com>
What is the expected behavior when a model has both stub and
should_receive defined for the same method?
I have a helper method which creates an admin "logged in":
def stub_user(is_administrator)
user = stub_model(User)
user.stub(:is_administrator).and_return(is_administrator)
User.stub(:find_by_id).and_return(user)
user
end
def setup_admin
@admin = stub_user(true)
session[:user_id] = @admin.id
end
In an admin controller spec, I have to setup_admin so the specs can get
to the controllers, but then later in particular contexts, I do
@some_user = stub_model(User)
User.should_receive(:find_by_id).and_return(@some_user)
This is to simulate selecting a user from a list and either showing or
editing details. Based on what I'm seeing, it appears that the the
find_by_id return values are getting mixed up. Am I wrong to attempt to
use both of these or should this work as I expect? If the latter, then I
have more digging to do to determine what's going wrong.
Thanks,
Phillip
From reed.adam at gmail.com Tue Mar 2 16:05:41 2010
From: reed.adam at gmail.com (Adam R)
Date: Tue, 2 Mar 2010 13:05:41 -0800 (PST)
Subject: [rspec-users] RSpec framework question
In-Reply-To: <27758607.post@talk.nabble.com>
References: <27758607.post@talk.nabble.com>
Message-ID: <27761159.post@talk.nabble.com>
An update for this issue. This script works, but only if I explicitly define
the array that I'm iterating over (][countryname, url]].each do, rather than
@countries.each do).
Can someone help me understand why my array here (@countries) is not
recognized? I tried to instantiate it as a global variable ($countries) and
it still was not recognized. If I explicitly describe an array in place of
the variable, the script works.
Is it an issue with my organization format, or something else?
global_page_spec.rb
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
require 'helpers/example_helper'
describe "The country page for" do
include ExHelper
before(:all) do
setup
collect_global_countries
end
@countries.each do |name, link|
describe name do
it "should contain the word #{name} in the title" do
@browser.goto link
@browser.div(:id, /content-content/).text.should include(name)
end #it
end #desc
end #countries
after(:all) do
teardown
end #after
end #spec
example_helper.rb
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
require 'helpers/global_helper'
module ExHelper
include GlobalHelper
def setup
@browser = Watir::Browser.new
@browser.add_checker lambda {|b| b.text.should_not include('The
requested page could not be found.')}
end # setup
def collect_global_countries
@countries = Array.new
@countries.should be_empty
@browser.goto "http://www.#{$env}.com/global"
@browser.table(:class, /global-list/).links.each do |link|
@countries << [link.text, link.href]
end #links
@countries.should_not be_empty
def teardown
@browser.close
end # teardown
end #module
--
View this message in context: http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27761159.html
Sent from the rspec-users mailing list archive at Nabble.com.
From dbatshaw at gmail.com Tue Mar 2 16:13:40 2010
From: dbatshaw at gmail.com (drewB)
Date: Tue, 2 Mar 2010 13:13:40 -0800 (PST)
Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts
In-Reply-To: <57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com>
References: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com>
<57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com>
Message-ID:
I may not have been clear. When I said if I add it to the top of my
spec.opts file, I meant adding, '--require "test_notifier/rspec"'.
Nevertheless, I tried you suggestion (a very good one).
Unfortunately, it seems that it must be required before "require
File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))"
or the following error appears:
/usr/local/lib/site_ruby/1.8/rubygems.rb:270:in `activate': You have a
nil object when you didn't expect it! (NoMethodError)
You might have expected an instance of Array.
The error occurred while evaluating nil.map
On Mar 2, 11:33?am, David Chelimsky wrote:
> On Tue, Mar 2, 2010 at 1:22 PM, drewB wrote:
> > There is a nice little gem that gives you desktop notifications of
> > your spec commands called test_noitifer (http://github.com/fnando/
> > test_notifier). ?I can get it to work by including require
> > "test_notifier/rspec" toward the top of my spec_helper, or by manually
> > including it in the command line like:
>
> > spec --require "test_notifier/rspec"
>
> > However, if I add it to the top of my spec.opts file, I get the
> > following error:
>
> > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
> > `gem_original_require': no such file to load -- "test_notifier/
> > rspec" (LoadError)
>
> > Any ideas on how to make it work? ?I don't want to add it to
> > spec_helper because then others on my team would need to use the gem
> > as well (which they might not want to).
>
> spec.opts is not a ruby file, so you can't put it there. Why not add
> it to a ruby file in spec/support/ that you don't keep in source
> control?
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
From dbatshaw at gmail.com Tue Mar 2 17:56:21 2010
From: dbatshaw at gmail.com (drewB)
Date: Tue, 2 Mar 2010 14:56:21 -0800 (PST)
Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts
In-Reply-To:
References: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com>
<57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com>
Message-ID:
If I add to spec.opts '--require test_notifier/rspec' (quotes are
removed) it is finding it but I am encountering the same error as if I
didn't require the file early enough in spec_helper:
/usr/local/lib/site_ruby/1.8/rubygems.rb:270:in `activate': You have a
nil object when you didn't expect it! (NoMethodError)
You might have expected an instance of Array.
The error occurred while evaluating nil.map
No sure they same problem won't occur when using the option on the
command line.
On Mar 2, 1:13?pm, drewB wrote:
> I may not have been clear. ?When I said if I add it to the top of my
> spec.opts file, I meant adding, '--require "test_notifier/rspec"'.
>
> Nevertheless, I tried you suggestion (a very good one).
> Unfortunately, it seems that it must be required before "require
> File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))"
> or the following error appears:
>
> /usr/local/lib/site_ruby/1.8/rubygems.rb:270:in `activate': You have a
> nil object when you didn't expect it! (NoMethodError)
> You might have expected an instance of Array.
> The error occurred while evaluating nil.map
>
> On Mar 2, 11:33?am, David Chelimsky wrote:
>
> > On Tue, Mar 2, 2010 at 1:22 PM, drewB wrote:
> > > There is a nice little gem that gives you desktop notifications of
> > > your spec commands called test_noitifer (http://github.com/fnando/
> > > test_notifier). ?I can get it to work by including require
> > > "test_notifier/rspec" toward the top of my spec_helper, or by manually
> > > including it in the command line like:
>
> > > spec --require "test_notifier/rspec"
>
> > > However, if I add it to the top of my spec.opts file, I get the
> > > following error:
>
> > > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
> > > `gem_original_require': no such file to load -- "test_notifier/
> > > rspec" (LoadError)
>
> > > Any ideas on how to make it work? ?I don't want to add it to
> > > spec_helper because then others on my team would need to use the gem
> > > as well (which they might not want to).
>
> > spec.opts is not a ruby file, so you can't put it there. Why not add
> > it to a ruby file in spec/support/ that you don't keep in source
> > control?
> > _______________________________________________
> > rspec-users mailing list
> > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
From matt at mattwynne.net Tue Mar 2 18:16:26 2010
From: matt at mattwynne.net (Matt Wynne)
Date: Tue, 2 Mar 2010 23:16:26 +0000
Subject: [rspec-users] RSpec framework question
In-Reply-To: <27761159.post@talk.nabble.com>
References: <27758607.post@talk.nabble.com> <27761159.post@talk.nabble.com>
Message-ID: <6D4244AA-51CD-409E-9F8B-02EC7CB72623@mattwynne.net>
On 2 Mar 2010, at 21:05, Adam R wrote:
>
> An update for this issue. This script works, but only if I
> explicitly define
> the array that I'm iterating over (][countryname, url]].each do,
> rather than
> @countries.each do).
>
> Can someone help me understand why my array here (@countries) is not
> recognized? I tried to instantiate it as a global variable
> ($countries) and
> it still was not recognized. If I explicitly describe an array in
> place of
> the variable, the script works.
>
> Is it an issue with my organization format, or something else?
>
> global_page_spec.rb
> $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 ==
> __FILE__
> require 'helpers/example_helper'
>
> describe "The country page for" do
> include ExHelper
>
> before(:all) do
> setup
> collect_global_countries
> end
>
> @countries.each do |name, link|
> describe name do
> it "should contain the word #{name} in the title" do
> @browser.goto link
> @browser.div(:id, /content-content/).text.should include(name)
> end #it
> end #desc
> end #countries
>
> after(:all) do
> teardown
> end #after
> end #spec
>
> example_helper.rb
> $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 ==
> __FILE__
> require 'helpers/global_helper'
>
> module ExHelper
> include GlobalHelper
>
> def setup
> @browser = Watir::Browser.new
> @browser.add_checker lambda {|b| b.text.should_not include('The
> requested page could not be found.')}
> end # setup
>
> def collect_global_countries
> @countries = Array.new
> @countries.should be_empty
>
> @browser.goto "http://www.#{$env}.com/global"
> @browser.table(:class, /global-list/).links.each do |link|
> @countries << [link.text, link.href]
> end #links
>
> @countries.should_not be_empty
>
> def teardown
> @browser.close
> end # teardown
> end #module
> --
> View this message in context: http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27761159.html
> Sent from the rspec-users mailing list archive at Nabble.com.
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
Briefly, think of two passes over this file: the first 'parse' pass,
and the second 'execution' pass. The #before and #it blocks run during
the 'execution' pass, but the code in the #describe blocks runs in the
initial 'parse' pass. Because @countries is not created until the
before blocks run, there's no way for the 'parse' pass to know what
value it has.
That's the basic essence of your issue. I'd recommend paring this back
to a much simpler example, getting that working, then building up from
there.
I'm also not sure why you're using the SUT to generate the tests, but
that's for another thread...
cheers,
Matt
http://mattwynne.net
+447974 430184
From dchelimsky at gmail.com Tue Mar 2 18:54:00 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Tue, 2 Mar 2010 17:54:00 -0600
Subject: [rspec-users] Integration testing without cucumber
In-Reply-To: <3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com>
References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
<0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com>
<28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com>
<57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com>
<8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com>
<3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com>
Message-ID: <57c63afe1003021554m7b0e90bs3b86847ac97f2691@mail.gmail.com>
On Tue, Mar 2, 2010 at 11:53 AM, drewB wrote:
> Looks like I spoke too soon. ?I made a mistake when testing your
> suggest. ?When I add that I still get the same failure.
I just did the following using rails 2.3.5, rspec 1.3.2 and rspec-rails 1.3.0:
$ rails foo
$ cd foo
$ script/generate rspec
$ mkdir spec/integration
$ script/generate integration_spec widgets
$ rake db:migrate && db:test:prepare
Then I modified spec/integration/widgets_spec.rb as follows:
require 'spec_helper'
describe "Widgets" do
it "shows me the list" do
get "/widgets"
response.should be_success
end
end
Then I ran this:
$ script/spec spec/integration/
And here's the output I saw:
F
1)
'Widgets ..' FAILED
expected success? to return true, got false
/Users/dchelimsky/tmp/foo/spec/integration/widgets_spec.rb:6:
So everything is working as it should on a fresh app. Did you update
spec/spec_helper.rb the last time you upgraded the app? Are you using
an earlier version of rspec-rails or rspec?
>
> On Mar 1, 4:06?pm, drewB wrote:
>> That fixed it! Thanks!
>>
>> Any idea why that was needed for integration specs and not MVCs?
>>
>> On Mar 1, 3:04?pm, David Chelimsky wrote:
>>
>> > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote:
>> > > Belwo is a spec that when used with the default spec_helper fails
>> > > with:
>>
>> > > NoMethodError in 'test matchers should be able to find be_success'
>> > > undefined method `be_success' for
>> > > #
>>
>> > > ----------
>>
>> > > require 'spec_helper'
>>
>> > > describe "test matchers" do
>> > > ?it "should be able to find be_success" do
>> > > ? ?get '/'
>> > > ? ?response.should be_success
>> > > ?end
>>
>> > > end
>>
>> > Try adding this to spec/spec_helper.rb
>>
>> > Spec::Runner.configure {|c| c.include Spec::Matchers}
From dchelimsky at gmail.com Tue Mar 2 19:11:09 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Tue, 2 Mar 2010 18:11:09 -0600
Subject: [rspec-users] RSpec and Watir, easy script structure question
In-Reply-To: <27758607.post@talk.nabble.com>
References: <27758607.post@talk.nabble.com>
Message-ID: <57c63afe1003021611r4602b831ha4307d917721fa15@mail.gmail.com>
On Tue, Mar 2, 2010 at 11:24 AM, Adam R wrote:
>
> Howdy! ?I'm relatively new to RSpec, but I've worked with Watir and Ruby for
> about 5 years now. ?My company is redesigning a web app from the ground up,
> so I'm taking the opportunity to leverage RSpec instead of Test/Unit.
>
> I've run into a problem with RSpec organization that I just can't sort out
> on my own, so I'm hoping it's straightforward enough that someone can help
> me out.
>
> Basically I have a single HTML page with an organized list of links. ?Each
> link points to a new page with a single verifiable item on it. ?The script
> collects all the links into an array, then iterates over the array, loading
> each link and verifying a single piece of text. ?That's the easy part.
>
> Here's the relevant code for what I believe to be the closest attempt right
> now:
>
> @links = Array.new
> @browser = Watir::Browser.new
> @browser.goto(page)
>
> @browser.link.each do |link|
> ? ?@links << [link.name, link.href]
> end
>
> ? ?@links.each do |name, link|
> ? ? ? ? describe name do
> ? ? ? ? ? ? ?it "should contain the word #{name}" do
> ? ? ? ? ? ? ? ? ? ?@browser.goto link
> ? ? ? ? ? ? ? ? ? ?@browser.div(:id, /example/).text.should include(name)
> ? ? ? ? ? ? ?end #it
> ? ? ? ? end #desc
> ? ?end #@links
>
> I've tried a combination of methods -- putting all of this code inside a
> describe block, etc, but I end up with the variables being unknown because
> they're not inside the same describe or it block (even when set to $global),
> or the describe/it blocks being layered incorrectly.
>
> I'm sure there's a simple solution to the format, but unfortunately I
> haven't been able to Google or RDoc my way to an answer. ?I appreciate any
> advice you can offer!
describe "something" do
it "does something" do
end
end
That's the simplest format - everything should go in the example (it
block), not directly inside the describe block.
HTH,
David
>
> Thanks,
> Adam
> --
> View this message in context: http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27758607.html
> Sent from the rspec-users mailing list archive at Nabble.com.
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
From reed.adam at gmail.com Tue Mar 2 20:40:15 2010
From: reed.adam at gmail.com (Adam Reed)
Date: Tue, 2 Mar 2010 19:40:15 -0600
Subject: [rspec-users] RSpec and Watir, easy script structure question
In-Reply-To: <57c63afe1003021611r4602b831ha4307d917721fa15@mail.gmail.com>
References: <27758607.post@talk.nabble.com>
<57c63afe1003021611r4602b831ha4307d917721fa15@mail.gmail.com>
Message-ID: <1f87a1c1003021740p553b181ak586df8458d7cd0e5@mail.gmail.com>
Thanks David. I have the basic format working in other scripts, so that's a
good sign. Another user pointed me to this example, which is why I was
exploring a different format:
> ["Los Angeles", "Austin"].each do |location|
> it "should show #{location}" do
> @browser.div(:id, /example/).text.should include(location)
> end
> end
>
Is this not correct/usable?
Thanks again,
Adam
On Tue, Mar 2, 2010 at 6:11 PM, David Chelimsky wrote:
> On Tue, Mar 2, 2010 at 11:24 AM, Adam R wrote:
> >
> > Howdy! I'm relatively new to RSpec, but I've worked with Watir and Ruby
> for
> > about 5 years now. My company is redesigning a web app from the ground
> up,
> > so I'm taking the opportunity to leverage RSpec instead of Test/Unit.
> >
> > I've run into a problem with RSpec organization that I just can't sort
> out
> > on my own, so I'm hoping it's straightforward enough that someone can
> help
> > me out.
> >
> > Basically I have a single HTML page with an organized list of links.
> Each
> > link points to a new page with a single verifiable item on it. The
> script
> > collects all the links into an array, then iterates over the array,
> loading
> > each link and verifying a single piece of text. That's the easy part.
> >
> > Here's the relevant code for what I believe to be the closest attempt
> right
> > now:
> >
> > @links = Array.new
> > @browser = Watir::Browser.new
> > @browser.goto(page)
> >
> > @browser.link.each do |link|
> > @links << [link.name, link.href]
> > end
> >
> > @links.each do |name, link|
> > describe name do
> > it "should contain the word #{name}" do
> > @browser.goto link
> > @browser.div(:id, /example/).text.should include(name)
> > end #it
> > end #desc
> > end #@links
> >
> > I've tried a combination of methods -- putting all of this code inside a
> > describe block, etc, but I end up with the variables being unknown
> because
> > they're not inside the same describe or it block (even when set to
> $global),
> > or the describe/it blocks being layered incorrectly.
> >
> > I'm sure there's a simple solution to the format, but unfortunately I
> > haven't been able to Google or RDoc my way to an answer. I appreciate
> any
> > advice you can offer!
>
> describe "something" do
> it "does something" do
> end
> end
>
> That's the simplest format - everything should go in the example (it
> block), not directly inside the describe block.
>
> HTH,
> David
>
> >
> > Thanks,
> > Adam
> > --
> > View this message in context:
> http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27758607.html
> > Sent from the rspec-users mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From thiyagarajannv at gmail.com Wed Mar 3 03:16:59 2010
From: thiyagarajannv at gmail.com (vtr)
Date: Wed, 3 Mar 2010 00:16:59 -0800 (PST)
Subject: [rspec-users] Hi All
Message-ID:
Hi All,
This is Thiyagarajan Veluchamy from India, i am new to rspec. gI need
to learn rspec. Can anyone guide me, how to start properly.
Advance Thanks,
Thanks,
Thiyagarajan Veluchamy
From dchelimsky at gmail.com Wed Mar 3 08:15:09 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Wed, 3 Mar 2010 07:15:09 -0600
Subject: [rspec-users] RSpec and Watir, easy script structure question
In-Reply-To: <1f87a1c1003021740p553b181ak586df8458d7cd0e5@mail.gmail.com>
References: <27758607.post@talk.nabble.com>
<57c63afe1003021611r4602b831ha4307d917721fa15@mail.gmail.com>
<1f87a1c1003021740p553b181ak586df8458d7cd0e5@mail.gmail.com>
Message-ID: <57c63afe1003030515h1f24292dqe778adf746667767@mail.gmail.com>
On Tue, Mar 2, 2010 at 7:40 PM, Adam Reed wrote:
> On Tue, Mar 2, 2010 at 6:11 PM, David Chelimsky
> wrote:
>>
>> On Tue, Mar 2, 2010 at 11:24 AM, Adam R wrote:
>> >
>> > Howdy! ?I'm relatively new to RSpec, but I've worked with Watir and Ruby
>> > for
>> > about 5 years now. ?My company is redesigning a web app from the ground
>> > up,
>> > so I'm taking the opportunity to leverage RSpec instead of Test/Unit.
>> >
>> > I've run into a problem with RSpec organization that I just can't sort
>> > out
>> > on my own, so I'm hoping it's straightforward enough that someone can
>> > help
>> > me out.
>> >
>> > Basically I have a single HTML page with an organized list of links.
>> > ?Each
>> > link points to a new page with a single verifiable item on it. ?The
>> > script
>> > collects all the links into an array, then iterates over the array,
>> > loading
>> > each link and verifying a single piece of text. ?That's the easy part.
>> >
>> > Here's the relevant code for what I believe to be the closest attempt
>> > right
>> > now:
>> >
>> > @links = Array.new
>> > @browser = Watir::Browser.new
>> > @browser.goto(page)
>> >
>> > @browser.link.each do |link|
>> > ? ?@links << [link.name, link.href]
>> > end
>> >
>> > ? ?@links.each do |name, link|
>> > ? ? ? ? describe name do
>> > ? ? ? ? ? ? ?it "should contain the word #{name}" do
>> > ? ? ? ? ? ? ? ? ? ?@browser.goto link
>> > ? ? ? ? ? ? ? ? ? ?@browser.div(:id, /example/).text.should
>> > include(name)
>> > ? ? ? ? ? ? ?end #it
>> > ? ? ? ? end #desc
>> > ? ?end #@links
>> >
>> > I've tried a combination of methods -- putting all of this code inside a
>> > describe block, etc, but I end up with the variables being unknown
>> > because
>> > they're not inside the same describe or it block (even when set to
>> > $global),
>> > or the describe/it blocks being layered incorrectly.
>> >
>> > I'm sure there's a simple solution to the format, but unfortunately I
>> > haven't been able to Google or RDoc my way to an answer. ?I appreciate
>> > any
>> > advice you can offer!
>>
>> describe "something" do
>> ?it "does something" do
>> ?end
>> end
>>
>> That's the simplest format - everything should go in the example (it
>> block), not directly inside the describe block.
> Thanks David.? I have the basic format working in other scripts, so that's a
> good sign.? Another user pointed me to this example, which is why I was
> exploring a different format:
>
>>
>> ["Los Angeles", "Austin"].each do |location|
>> ? ? it "should show #{location}" do
>> ? ? ? @browser.div(:id, /example/).text.should include(location)
>> ? ? end
>> end
>
> Is this not correct/usable?
Correct is subjective. What you have here is somewhat harmless, but
I've seen simple lists like that grow into nested lists with
conditional logic where members of one list impact what is done with
the values in the other. That makes it very difficult to understand
failures and difficult to change as requirements change.
HTH,
David
From dchelimsky at gmail.com Wed Mar 3 08:26:12 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Wed, 3 Mar 2010 07:26:12 -0600
Subject: [rspec-users] Hi All
In-Reply-To:
References:
Message-ID: <57c63afe1003030526jc7a2107k27d90e41f0815384@mail.gmail.com>
On Wed, Mar 3, 2010 at 2:16 AM, vtr wrote:
> Hi All,
>
> This is Thiyagarajan Veluchamy from India, i am new to rspec. gI need
> to learn rspec. Can anyone guide me, how to start properly.
> Advance Thanks,
Hi Thiyagarajan. Welcome to Rspec and this mailing list. If you're
interested in participating, please read
http://wiki.github.com/dchelimsky/rspec/get-in-touch. We're here to
answer specific questions, but vague questions like "how do I start
properly" are much better suited for google than this list:
http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=getting+started+with+rspec
Looking forward to your specific questions.
Cheers,
David
From dchelimsky at gmail.com Wed Mar 3 08:38:43 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Wed, 3 Mar 2010 07:38:43 -0600
Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts
In-Reply-To:
References: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com>
<57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com>
Message-ID: <57c63afe1003030538t3e635f26ja3e2137c640bde26@mail.gmail.com>
On Tue, Mar 2, 2010 at 3:13 PM, drewB wrote:
> I may not have been clear. ?When I said if I add it to the top of my
> spec.opts file, I meant adding, '--require "test_notifier/rspec"'.
>
> Nevertheless, I tried you suggestion (a very good one).
> Unfortunately, it seems that it must be required before "require
> File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))"
> or the following error appears:
>
> /usr/local/lib/site_ruby/1.8/rubygems.rb:270:in `activate': You have a
> nil object when you didn't expect it! (NoMethodError)
> You might have expected an instance of Array.
> The error occurred while evaluating nil.map
If you know where it works in the spec_helper file, then you can do
what I suggested before, but in a new directory. So right now in
spec_helper you've got something like:
Dir['spec/support/*_.rb'].each {|f| require f}
Do the same thing, but put your helpers in a separate directory, and
include that _before_ the line that requires 'config/environment'
Dir['spec/before_rails_loads/*_.rb'].each {|f| require f}
require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
HTH,
David
>
> On Mar 2, 11:33?am, David Chelimsky wrote:
>> On Tue, Mar 2, 2010 at 1:22 PM, drewB wrote:
>> > There is a nice little gem that gives you desktop notifications of
>> > your spec commands called test_noitifer (http://github.com/fnando/
>> > test_notifier). ?I can get it to work by including require
>> > "test_notifier/rspec" toward the top of my spec_helper, or by manually
>> > including it in the command line like:
>>
>> > spec --require "test_notifier/rspec"
>>
>> > However, if I add it to the top of my spec.opts file, I get the
>> > following error:
>>
>> > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
>> > `gem_original_require': no such file to load -- "test_notifier/
>> > rspec" (LoadError)
>>
>> > Any ideas on how to make it work? ?I don't want to add it to
>> > spec_helper because then others on my team would need to use the gem
>> > as well (which they might not want to).
>>
>> spec.opts is not a ruby file, so you can't put it there. Why not add
>> it to a ruby file in spec/support/ that you don't keep in source
>> control?
>> _______________________________________________
>> rspec-users mailing list
>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
From mailinglists at patmaddox.com Wed Mar 3 10:30:58 2010
From: mailinglists at patmaddox.com (Pat Maddox)
Date: Wed, 3 Mar 2010 07:30:58 -0800
Subject: [rspec-users] Hi All
In-Reply-To: <57c63afe1003030526jc7a2107k27d90e41f0815384@mail.gmail.com>
References:
<57c63afe1003030526jc7a2107k27d90e41f0815384@mail.gmail.com>
Message-ID: <423E4759-C34A-4E45-9965-CEB6F0DB51A9@patmaddox.com>
On Mar 3, 2010, at 5:26 AM, David Chelimsky wrote:
> On Wed, Mar 3, 2010 at 2:16 AM, vtr wrote:
>> Hi All,
>>
>> This is Thiyagarajan Veluchamy from India, i am new to rspec. gI need
>> to learn rspec. Can anyone guide me, how to start properly.
>> Advance Thanks,
>
> Hi Thiyagarajan. Welcome to Rspec and this mailing list. If you're
> interested in participating, please read
> http://wiki.github.com/dchelimsky/rspec/get-in-touch. We're here to
> answer specific questions, but vague questions like "how do I start
> properly" are much better suited for google than this list:
>
> http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=getting+started+with+rspec
>
> Looking forward to your specific questions.
>
> Cheers,
> David
Also, buy and study http://www.pragprog.com/titles/achbd/the-rspec-book
:)
From reed.adam at gmail.com Wed Mar 3 11:08:15 2010
From: reed.adam at gmail.com (Adam R)
Date: Wed, 3 Mar 2010 08:08:15 -0800 (PST)
Subject: [rspec-users] RSpec and Watir, easy script structure question
In-Reply-To: <27758607.post@talk.nabble.com>
References: <27758607.post@talk.nabble.com>
Message-ID: <27770149.post@talk.nabble.com>
Thanks again for the parse/execute perspective Matt, that really sorted me
out.
Solution: Hey dummy, collect the data and create the array before starting
the describe function.
Moral of the story: I was trying to make collecting the data that I wanted
to verify part of the test/spec, partially because I had it stuck in my head
that 'everything' had to be inside a describe block, and partially because I
was treating RSpec like some new alien technology instead of a Ruby library.
Code:
@Array = [...] or Method to collect array data
@array.each do |name, stuff|
describe name do
it "should put the lotion in the basket" do
end
end
end
--
View this message in context: http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27770149.html
Sent from the rspec-users mailing list archive at Nabble.com.
From dbatshaw at gmail.com Wed Mar 3 13:24:45 2010
From: dbatshaw at gmail.com (drewB)
Date: Wed, 3 Mar 2010 10:24:45 -0800 (PST)
Subject: [rspec-users] Integration testing without cucumber
In-Reply-To: <57c63afe1003021554m7b0e90bs3b86847ac97f2691@mail.gmail.com>
References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
<0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com>
<28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com>
<57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com>
<8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com>
<3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com>
<57c63afe1003021554m7b0e90bs3b86847ac97f2691@mail.gmail.com>
Message-ID: <48fa2440-24cd-46d9-90e1-2a2e7191e5f6@q16g2000yqq.googlegroups.com>
Let me start by saying thank you for the time you are spending helping
me.
It appears to be a rails version issue. I ran though the same steps
you outlined on my machine and continued to get the same error
message, "undefined method `be_success'". I am running rspec 1.3.0,
rspec-rails 1.3.2, rails 2.3.4. When I upgraded to rails 2.3.5 and
tried again, everything worked.
The project I am working on is frozen at rails 2.1.2 so am still
looking for a way to get this to work with rails 2.1.2. Should I
downgrade to an earlier version of RSpec or spec-rails? If so, which
one?
On Mar 2, 3:54?pm, David Chelimsky wrote:
> On Tue, Mar 2, 2010 at 11:53 AM, drewB wrote:
> > Looks like I spoke too soon. ?I made a mistake when testing your
> > suggest. ?When I add that I still get the same failure.
>
> I just did the following using rails 2.3.5, rspec 1.3.2 and rspec-rails 1.3.0:
>
> $ rails foo
> $ cd foo
> $ script/generate rspec
> $ mkdir spec/integration
> $ script/generate integration_spec widgets
> $ rake db:migrate && db:test:prepare
>
> Then I modified spec/integration/widgets_spec.rb as follows:
>
> require 'spec_helper'
>
> describe "Widgets" do
> ? it "shows me the list" do
> ? ? get "/widgets"
> ? ? response.should be_success
> ? end
> end
>
> Then I ran this:
>
> $ script/spec spec/integration/
>
> And here's the output I saw:
>
> F
>
> 1)
> 'Widgets ..' FAILED
> expected success? to return true, got false
> /Users/dchelimsky/tmp/foo/spec/integration/widgets_spec.rb:6:
>
> So everything is working as it should on a fresh app. Did you update
> spec/spec_helper.rb the last time you upgraded the app? Are you using
> an earlier version of rspec-rails or rspec?
>
>
>
>
>
> > On Mar 1, 4:06?pm, drewB wrote:
> >> That fixed it! Thanks!
>
> >> Any idea why that was needed for integration specs and not MVCs?
>
> >> On Mar 1, 3:04?pm, David Chelimsky wrote:
>
> >> > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote:
> >> > > Belwo is a spec that when used with the default spec_helper fails
> >> > > with:
>
> >> > > NoMethodError in 'test matchers should be able to find be_success'
> >> > > undefined method `be_success' for
> >> > > #
>
> >> > > ----------
>
> >> > > require 'spec_helper'
>
> >> > > describe "test matchers" do
> >> > > ?it "should be able to find be_success" do
> >> > > ? ?get '/'
> >> > > ? ?response.should be_success
> >> > > ?end
>
> >> > > end
>
> >> > Try adding this to spec/spec_helper.rb
>
> >> > Spec::Runner.configure {|c| c.include Spec::Matchers}
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
From dchelimsky at gmail.com Wed Mar 3 13:38:21 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Wed, 3 Mar 2010 12:38:21 -0600
Subject: [rspec-users] Integration testing without cucumber
In-Reply-To: <48fa2440-24cd-46d9-90e1-2a2e7191e5f6@q16g2000yqq.googlegroups.com>
References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
<0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com>
<28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com>
<57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com>
<8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com>
<3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com>
<57c63afe1003021554m7b0e90bs3b86847ac97f2691@mail.gmail.com>
<48fa2440-24cd-46d9-90e1-2a2e7191e5f6@q16g2000yqq.googlegroups.com>
Message-ID: <57c63afe1003031038x1f3e2759p1a59a0668581e708@mail.gmail.com>
On Wed, Mar 3, 2010 at 12:24 PM, drewB wrote:
> Let me start by saying thank you for the time you are spending helping
> me.
You're welcome.
> It appears to be a rails version issue. ?I ran though the same steps
> you outlined on my machine and continued to get the same error
> message, "undefined method `be_success'". ?I am running rspec 1.3.0,
> rspec-rails 1.3.2, rails 2.3.4. ?When I upgraded to rails 2.3.5 and
> tried again, everything worked.
>
> The project I am working on is frozen at rails 2.1.2 so am still
> looking for a way to get this to work with rails 2.1.2. ?Should I
> downgrade to an earlier version of RSpec or spec-rails? ?If so, which
> one?
1.3.2 is tested against the last fix release of each series: 2.3.5,
2.2.2, 2.1.2, 2.0.5. So it should work with 2.1.2. If not, it's a bug,
so go ahead and file a bug report at http://rspec.lighthouseapp.com -
feel free to reference this thread.
Cheers,
David
>
> On Mar 2, 3:54?pm, David Chelimsky wrote:
>> On Tue, Mar 2, 2010 at 11:53 AM, drewB wrote:
>> > Looks like I spoke too soon. ?I made a mistake when testing your
>> > suggest. ?When I add that I still get the same failure.
>>
>> I just did the following using rails 2.3.5, rspec 1.3.2 and rspec-rails 1.3.0:
>>
>> $ rails foo
>> $ cd foo
>> $ script/generate rspec
>> $ mkdir spec/integration
>> $ script/generate integration_spec widgets
>> $ rake db:migrate && db:test:prepare
>>
>> Then I modified spec/integration/widgets_spec.rb as follows:
>>
>> require 'spec_helper'
>>
>> describe "Widgets" do
>> ? it "shows me the list" do
>> ? ? get "/widgets"
>> ? ? response.should be_success
>> ? end
>> end
>>
>> Then I ran this:
>>
>> $ script/spec spec/integration/
>>
>> And here's the output I saw:
>>
>> F
>>
>> 1)
>> 'Widgets ..' FAILED
>> expected success? to return true, got false
>> /Users/dchelimsky/tmp/foo/spec/integration/widgets_spec.rb:6:
>>
>> So everything is working as it should on a fresh app. Did you update
>> spec/spec_helper.rb the last time you upgraded the app? Are you using
>> an earlier version of rspec-rails or rspec?
>>
>>
>>
>>
>>
>> > On Mar 1, 4:06?pm, drewB wrote:
>> >> That fixed it! Thanks!
>>
>> >> Any idea why that was needed for integration specs and not MVCs?
>>
>> >> On Mar 1, 3:04?pm, David Chelimsky wrote:
>>
>> >> > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote:
>> >> > > Belwo is a spec that when used with the default spec_helper fails
>> >> > > with:
>>
>> >> > > NoMethodError in 'test matchers should be able to find be_success'
>> >> > > undefined method `be_success' for
>> >> > > #
>>
>> >> > > ----------
>>
>> >> > > require 'spec_helper'
>>
>> >> > > describe "test matchers" do
>> >> > > ?it "should be able to find be_success" do
>> >> > > ? ?get '/'
>> >> > > ? ?response.should be_success
>> >> > > ?end
>>
>> >> > > end
>>
>> >> > Try adding this to spec/spec_helper.rb
>>
>> >> > Spec::Runner.configure {|c| c.include Spec::Matchers}
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
From dbatshaw at gmail.com Wed Mar 3 14:33:15 2010
From: dbatshaw at gmail.com (drewB)
Date: Wed, 3 Mar 2010 11:33:15 -0800 (PST)
Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts
In-Reply-To: <57c63afe1003030538t3e635f26ja3e2137c640bde26@mail.gmail.com>
References: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com>
<57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com>
<57c63afe1003030538t3e635f26ja3e2137c640bde26@mail.gmail.com>
Message-ID:
Thank you. That makes perfect sense.
Just in case anyone else comes across this, for me to include spec/
before_rails_loads/test_notifer.rb I needed to remove the underscore
so:
Dir['spec/before_rails_loads/*.rb'].each {|f| require f}
On Mar 3, 5:38?am, David Chelimsky wrote:
> On Tue, Mar 2, 2010 at 3:13 PM, drewB wrote:
> > I may not have been clear. ?When I said if I add it to the top of my
> > spec.opts file, I meant adding, '--require "test_notifier/rspec"'.
>
> > Nevertheless, I tried you suggestion (a very good one).
> > Unfortunately, it seems that it must be required before "require
> > File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))"
> > or the following error appears:
>
> > /usr/local/lib/site_ruby/1.8/rubygems.rb:270:in `activate': You have a
> > nil object when you didn't expect it! (NoMethodError)
> > You might have expected an instance of Array.
> > The error occurred while evaluating nil.map
>
> If you know where it works in the spec_helper file, then you can do
> what I suggested before, but in a new directory. So right now in
> spec_helper you've got something like:
>
> ? Dir['spec/support/*_.rb'].each {|f| require f}
>
> Do the same thing, but put your helpers in a separate directory, and
> include that _before_ the line that requires 'config/environment'
>
> ? Dir['spec/before_rails_loads/*_.rb'].each {|f| require f}
> ? require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
>
> HTH,
> David
>
>
>
>
>
> > On Mar 2, 11:33?am, David Chelimsky wrote:
> >> On Tue, Mar 2, 2010 at 1:22 PM, drewB wrote:
> >> > There is a nice little gem that gives you desktop notifications of
> >> > your spec commands called test_noitifer (http://github.com/fnando/
> >> > test_notifier). ?I can get it to work by including require
> >> > "test_notifier/rspec" toward the top of my spec_helper, or by manually
> >> > including it in the command line like:
>
> >> > spec --require "test_notifier/rspec"
>
> >> > However, if I add it to the top of my spec.opts file, I get the
> >> > following error:
>
> >> > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
> >> > `gem_original_require': no such file to load -- "test_notifier/
> >> > rspec" (LoadError)
>
> >> > Any ideas on how to make it work? ?I don't want to add it to
> >> > spec_helper because then others on my team would need to use the gem
> >> > as well (which they might not want to).
>
> >> spec.opts is not a ruby file, so you can't put it there. Why not add
> >> it to a ruby file in spec/support/ that you don't keep in source
> >> control?
> >> _______________________________________________
> >> rspec-users mailing list
> >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
> > _______________________________________________
> > rspec-users mailing list
> > rspec-us... at rubyforge.org
> >http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
From stefan.kanev at gmail.com Wed Mar 3 15:43:53 2010
From: stefan.kanev at gmail.com (Stefan Kanev)
Date: Wed, 3 Mar 2010 21:43:53 +0100
Subject: [rspec-users] Disabling database access in controller specs
Message-ID: <285b75bb1003031243x316a2830sa947bb5bdf52b2fe@mail.gmail.com>
It took a while, but now I an totally convinced that controller specs should
not access the database and stub as much as possible. I'm committed to that
style of writing, yet from time to time I incidentally allow it to happen.
Is there a way to err on the safe side and have RSpec throw an error every
time a controller spec attempts to access the database?
And does it sound like a good idea?
Thanks,
Stefan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From matt at mattwynne.net Wed Mar 3 17:54:34 2010
From: matt at mattwynne.net (Matt Wynne)
Date: Wed, 3 Mar 2010 22:54:34 +0000
Subject: [rspec-users] Disabling database access in controller specs
In-Reply-To: <285b75bb1003031243x316a2830sa947bb5bdf52b2fe@mail.gmail.com>
References: <285b75bb1003031243x316a2830sa947bb5bdf52b2fe@mail.gmail.com>
Message-ID:
You could use something like NullDb to achieve this, I think:
http://www.slideshare.net/bmabey/disconnecting-the-database-with-activerecord
On 3 Mar 2010, at 20:43, Stefan Kanev wrote:
> It took a while, but now I an totally convinced that controller
> specs should not access the database and stub as much as possible.
> I'm committed to that style of writing, yet from time to time I
> incidentally allow it to happen.
>
> Is there a way to err on the safe side and have RSpec throw an error
> every time a controller spec attempts to access the database?
>
> And does it sound like a good idea?
>
> Thanks,
> Stefan
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
cheers,
Matt
http://mattwynne.net
+447974 430184
From dchelimsky at gmail.com Wed Mar 3 21:29:08 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Wed, 3 Mar 2010 20:29:08 -0600
Subject: [rspec-users] rspec-2 update
In-Reply-To: <57c63afe1003031743j4356cae4o80f166f77a4f158c@mail.gmail.com>
References: <57c63afe1003031743j4356cae4o80f166f77a4f158c@mail.gmail.com>
Message-ID: <57c63afe1003031829u24cdbe24p8f97ae64812efe50@mail.gmail.com>
Hey all,
rspec-2 is moving along nicely and we're at the point now where we'd
love to see more people starting to use it, provide feedback, and
hopefully start contributing as well.
You can find the rspec-2 repositories under the rspec user on github:
http://github.com/rspec.
There are currently 6 repos:
http://github.com/rspec
http://github.com/rspec-core
http://github.com/rspec-dev
http://github.com/rspec-expectations
http://github.com/rspec-mocks
http://github.com/rspec-rails
Here's a brief explanation of each:
rspec is just a meta-gem, that depends on rspec-core,
rspec-expectations, rspec-mocks. For users, you only need to "gem
install rspec" (with --pre for now) and the rest is taken care of for
you.
rspec-core provides rspec's new runner, which comes from Chad
Humphries' Micronaut, the describe and it methods (and their aliases),
and the rspec command (which replaces the spec command).
rspec-expectations provides "should" and "should_not" and matchers.
rspec-mocks provides test double behaviour (stubbing and mocking)
rspec-rails provides specialized example groups and matchers for rails-3
rspec-dev is for people like me who work on all of these libraries.
You don't really need rspec-dev if you want to patch any one library,
but it's useful if you plan to contribute to more than one.
Each has a wiki and most have issues configured. Please feel free to
start updating the wikis, entering issues, forking the repos and
submitting pull requests.
Our near term goal is to identify and document rspec-1 features that
are missing from rspec-2. We'll want to get most of them working like
rspec-1, but there will likely be some that we decide to stop
supporting. In the latter case, we want to be sure that they are well
documented so users don't get too surprised when they upgrade.
There are cucumber features in the rspec-core, rspec-expectations, and
rspec-mocks libraries. Please have a look at those as well. By the
time we release 2.0 final, I'd like to be able to point to them as the
definitive resource as to how to use rspec's features. As we identify
missing features that we want to support in rspec 2.0, I want to be
sure to add cukes for them.
Let me know if you have any questions. Looking forward to your
feedback and contributions!
Cheers,
David
From dchelimsky at gmail.com Wed Mar 3 21:36:28 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Wed, 3 Mar 2010 20:36:28 -0600
Subject: [rspec-users] rspec-2 for rails-2????
Message-ID: <57c63afe1003031836ma07b191sc1118d8b7dd11cb9@mail.gmail.com>
Hey all,
rspec-rails-2 will only work with rails-3 (not rails-2). My suspicion
is that once rspec-2 is out, folks are going to want to start using it
with their existing rails-2 projects (because it offers some sweet new
goodness that you won't want to live without).
Would anybody be interested in writing and maintaining and
rspec-2-rails-2 gem? This would be a separate code-base from
rspec-rails, but we could keep the repo under the new rspec github
user (http://github.com/rspec) provided that it is generally accepted
and used by the community.
Let me know if you're interested, or if you have any concerns about
this approach.
Cheers,
David
From me at franklakatos.com Thu Mar 4 01:03:57 2010
From: me at franklakatos.com (Frank Lakatos)
Date: Thu, 4 Mar 2010 01:03:57 -0500
Subject: [rspec-users] Verify Order
Message-ID:
I may be missing something obvious, but how do I verify sort order?
I have
class Project < ActiveRecord::Base
has_many :tasks, :order => "position"
end
I create a project, and 2 tasks: one with position = 1 and the other
with position = 2. I want to verify that Project.tasks orders the
tasks so that the task with position = 1 comes before the task with
position = 2.
Little push would be great, thanks
Frank
From godfoca at gmail.com Thu Mar 4 01:15:34 2010
From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=)
Date: Thu, 4 Mar 2010 04:15:34 -0200
Subject: [rspec-users] Verify Order
In-Reply-To:
References:
Message-ID:
Assuming Project.tasks has :order => 'position ASC' then:
describe Project do
before do
@project = Project.create
@first_task = @project.tasks.create(:position => 1)
@last_task = @project.tasks.create(:position => 2)
end
it "returns its tasks in order" do
@project.tasks.should == [@first_task, @last_task]
end
end
Will check that they are ordered.
Cheers,
-foca
On Thu, Mar 4, 2010 at 4:03 AM, Frank Lakatos wrote:
> I may be missing something obvious, but how do I verify sort order?
>
> I have
>
> class Project < ActiveRecord::Base
> ?has_many :tasks, :order => "position"
> end
>
>
> I create a project, and 2 tasks: one with position = 1 and the other with
> position = 2. I want to verify that Project.tasks orders the tasks so that
> the task with position = 1 comes before the task with position = 2.
>
> Little push would be great, thanks
>
> Frank
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
From aslak.hellesoy at gmail.com Thu Mar 4 02:58:53 2010
From: aslak.hellesoy at gmail.com (=?utf-8?Q?Aslak_Helles=C3=B8y?=)
Date: Thu, 4 Mar 2010 08:58:53 +0100
Subject: [rspec-users] rspec-2 for rails-2????
In-Reply-To: <57c63afe1003031836ma07b191sc1118d8b7dd11cb9@mail.gmail.com>
References: <57c63afe1003031836ma07b191sc1118d8b7dd11cb9@mail.gmail.com>
Message-ID: <8D5E5421-8353-462E-9F20-77567988038E@gmail.com>
> Hey all,
>
> rspec-rails-2 will only work with rails-3 (not rails-2). My suspicion
> is that once rspec-2 is out, folks are going to want to start using it
> with their existing rails-2 projects (because it offers some sweet new
> goodness that you won't want to live without).
>
> Would anybody be interested in writing and maintaining and
> rspec-2-rails-2 gem? This would be a separate code-base from
> rspec-rails, but we could keep the repo under the new rspec github
> user (http://github.com/rspec) provided that it is generally accepted
> and used by the community.
>
FWIW, cucumber-rails supports both Rails2 and Rails3. If someone picks
up the challenge it might be worthwhile to study the codebase. It uses
some smart tricks to support both in the same codebase, without too
much duplication.
Maybe supporting both Rails2 and Rails3 in rspec-rails is a smaller
effort than maintaining 2 gems?
Aslak
> Let me know if you're interested, or if you have any concerns about
> this approach.
>
> Cheers,
> David
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
From rick.denatale at gmail.com Thu Mar 4 08:32:55 2010
From: rick.denatale at gmail.com (Rick DeNatale)
Date: Thu, 4 Mar 2010 08:32:55 -0500
Subject: [rspec-users] rspec-2 update
In-Reply-To: <57c63afe1003031829u24cdbe24p8f97ae64812efe50@mail.gmail.com>
References: <57c63afe1003031743j4356cae4o80f166f77a4f158c@mail.gmail.com>
<57c63afe1003031829u24cdbe24p8f97ae64812efe50@mail.gmail.com>
Message-ID:
On Wed, Mar 3, 2010 at 9:29 PM, David Chelimsky wrote:
> Hey all,
>
> rspec-2 is moving along nicely and we're at the point now where we'd
> love to see more people starting to use it, provide feedback, and
> hopefully start contributing as well.
>
> You can find the rspec-2 repositories under the rspec user on github:
> http://github.com/rspec.
>
> There are currently 6 repos:
>
> http://github.com/rspec
> http://github.com/rspec-core
> http://github.com/rspec-dev
> http://github.com/rspec-expectations
> http://github.com/rspec-mocks
> http://github.com/rspec-rails
I think those should be:
http://github.com/rspec/rspec
http://github.com/rspec/rspec-core
http://github.com/rspec/rspec-dev
http://github.com/rspec/rspec-expectations
http://github.com/rspec/rspec-mocks
http://github.com/rspec/rspec-rails
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
From dchelimsky at gmail.com Thu Mar 4 08:37:36 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Thu, 4 Mar 2010 07:37:36 -0600
Subject: [rspec-users] rspec-2 for rails-2????
In-Reply-To: <8D5E5421-8353-462E-9F20-77567988038E@gmail.com>
References: <57c63afe1003031836ma07b191sc1118d8b7dd11cb9@mail.gmail.com>
<8D5E5421-8353-462E-9F20-77567988038E@gmail.com>
Message-ID: <57c63afe1003040537s70fb7369v2e9377c253fc942d@mail.gmail.com>
On Thu, Mar 4, 2010 at 1:58 AM, Aslak Helles?y wrote:
>
>
>> Hey all,
>>
>> rspec-rails-2 will only work with rails-3 (not rails-2). My suspicion
>> is that once rspec-2 is out, folks are going to want to start using it
>> with their existing rails-2 projects (because it offers some sweet new
>> goodness that you won't want to live without).
>>
>> Would anybody be interested in writing and maintaining and
>> rspec-2-rails-2 gem? This would be a separate code-base from
>> rspec-rails, but we could keep the repo under the new rspec github
>> user (http://github.com/rspec) provided that it is generally accepted
>> and used by the community.
>>
> FWIW, cucumber-rails supports both Rails2 and Rails3. If someone picks up
> the challenge it might be worthwhile to study the codebase. It uses some
> smart tricks to support both in the same codebase, without too much
> duplication.
>
> Maybe supporting both Rails2 and Rails3 in rspec-rails is a smaller effort
> than maintaining 2 gems?
I'm certainly open to the idea, but don't have cycles to investigate
it myself. I'd welcome someone taking on this cause and submitting
patches. Anyone interested?
>
> Aslak
>>
>> Let me know if you're interested, or if you have any concerns about
>> this approach.
>>
>> Cheers,
>> David
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
From dchelimsky at gmail.com Thu Mar 4 08:47:10 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Thu, 4 Mar 2010 07:47:10 -0600
Subject: [rspec-users] rspec-2 update
In-Reply-To:
References: <57c63afe1003031743j4356cae4o80f166f77a4f158c@mail.gmail.com>
<57c63afe1003031829u24cdbe24p8f97ae64812efe50@mail.gmail.com>
Message-ID: <57c63afe1003040547r69f762edjdf06531e6f8532e4@mail.gmail.com>
On Thu, Mar 4, 2010 at 7:32 AM, Rick DeNatale wrote:
> On Wed, Mar 3, 2010 at 9:29 PM, David Chelimsky wrote:
>> Hey all,
>>
>> rspec-2 is moving along nicely and we're at the point now where we'd
>> love to see more people starting to use it, provide feedback, and
>> hopefully start contributing as well.
>>
>> You can find the rspec-2 repositories under the rspec user on github:
>> http://github.com/rspec.
>>
>> There are currently 6 repos:
>>
>> http://github.com/rspec
>> http://github.com/rspec-core
>> http://github.com/rspec-dev
>> http://github.com/rspec-expectations
>> http://github.com/rspec-mocks
>> http://github.com/rspec-rails
>
> I think those should be:
>
>
> http://github.com/rspec/rspec
> http://github.com/rspec/rspec-core
> http://github.com/rspec/rspec-dev
> http://github.com/rspec/rspec-expectations
> http://github.com/rspec/rspec-mocks
> http://github.com/rspec/rspec-rails
Yes, indeed. Thank you, Rick :)
Cheers,
David
>
> --
> Rick DeNatale
>
> Blog: http://talklikeaduck.denhaven2.com/
> Twitter: http://twitter.com/RickDeNatale
> WWR: http://www.workingwithrails.com/person/9021-rick-denatale
> LinkedIn: http://www.linkedin.com/in/rickdenatale
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
From lists at ruby-forum.com Thu Mar 4 10:08:10 2010
From: lists at ruby-forum.com (Amit Kulkarni)
Date: Thu, 4 Mar 2010 16:08:10 +0100
Subject: [rspec-users] Undefined method 'post'
Message-ID: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com>
Hello all,
I am facing a strange problem.
I have generated rspec for a particular project.Similarly created a spec
controller.Under that controller i have written post :create action
When i run my spec i get an error as
"undefined method `post' for
#"
Strangely my models are working fine.My rails version is 2.3.5 and rspec
version is 1.1.12
I tried in some other project,in that i am getting error as "Undefined
method controller for nil class"
Earlier it was working fine,but dont know what is the problem.
Please suggest.
--
Posted via http://www.ruby-forum.com/.
From dbatshaw at gmail.com Thu Mar 4 12:26:30 2010
From: dbatshaw at gmail.com (drewB)
Date: Thu, 4 Mar 2010 09:26:30 -0800 (PST)
Subject: [rspec-users] Integration testing without cucumber
In-Reply-To: <57c63afe1003031038x1f3e2759p1a59a0668581e708@mail.gmail.com>
References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com>
<0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com>
<28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com>
<57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com>
<8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com>
<3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com>
<57c63afe1003021554m7b0e90bs3b86847ac97f2691@mail.gmail.com>
<48fa2440-24cd-46d9-90e1-2a2e7191e5f6@q16g2000yqq.googlegroups.com>
<57c63afe1003031038x1f3e2759p1a59a0668581e708@mail.gmail.com>
Message-ID: <83110f94-b06b-445a-95c0-26526158b928@y17g2000yqd.googlegroups.com>
Bug filed. Any idea about an earlier version that I might try?
On Mar 3, 10:38?am, David Chelimsky wrote:
> On Wed, Mar 3, 2010 at 12:24 PM, drewB wrote:
> > Let me start by saying thank you for the time you are spending helping
> > me.
>
> You're welcome.
>
> > It appears to be a rails version issue. ?I ran though the same steps
> > you outlined on my machine and continued to get the same error
> > message, "undefined method `be_success'". ?I am running rspec 1.3.0,
> > rspec-rails 1.3.2, rails 2.3.4. ?When I upgraded to rails 2.3.5 and
> > tried again, everything worked.
>
> > The project I am working on is frozen at rails 2.1.2 so am still
> > looking for a way to get this to work with rails 2.1.2. ?Should I
> > downgrade to an earlier version of RSpec or spec-rails? ?If so, which
> > one?
>
> 1.3.2 is tested against the last fix release of each series: 2.3.5,
> 2.2.2, 2.1.2, 2.0.5. So it should work with 2.1.2. If not, it's a bug,
> so go ahead and file a bug report athttp://rspec.lighthouseapp.com-
> feel free to reference this thread.
>
> Cheers,
> David
>
>
>
>
>
> > On Mar 2, 3:54?pm, David Chelimsky wrote:
> >> On Tue, Mar 2, 2010 at 11:53 AM, drewB wrote:
> >> > Looks like I spoke too soon. ?I made a mistake when testing your
> >> > suggest. ?When I add that I still get the same failure.
>
> >> I just did the following using rails 2.3.5, rspec 1.3.2 and rspec-rails 1.3.0:
>
> >> $ rails foo
> >> $ cd foo
> >> $ script/generate rspec
> >> $ mkdir spec/integration
> >> $ script/generate integration_spec widgets
> >> $ rake db:migrate && db:test:prepare
>
> >> Then I modified spec/integration/widgets_spec.rb as follows:
>
> >> require 'spec_helper'
>
> >> describe "Widgets" do
> >> ? it "shows me the list" do
> >> ? ? get "/widgets"
> >> ? ? response.should be_success
> >> ? end
> >> end
>
> >> Then I ran this:
>
> >> $ script/spec spec/integration/
>
> >> And here's the output I saw:
>
> >> F
>
> >> 1)
> >> 'Widgets ..' FAILED
> >> expected success? to return true, got false
> >> /Users/dchelimsky/tmp/foo/spec/integration/widgets_spec.rb:6:
>
> >> So everything is working as it should on a fresh app. Did you update
> >> spec/spec_helper.rb the last time you upgraded the app? Are you using
> >> an earlier version of rspec-rails or rspec?
>
> >> > On Mar 1, 4:06?pm, drewB wrote:
> >> >> That fixed it! Thanks!
>
> >> >> Any idea why that was needed for integration specs and not MVCs?
>
> >> >> On Mar 1, 3:04?pm, David Chelimsky wrote:
>
> >> >> > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote:
> >> >> > > Belwo is a spec that when used with the default spec_helper fails
> >> >> > > with:
>
> >> >> > > NoMethodError in 'test matchers should be able to find be_success'
> >> >> > > undefined method `be_success' for
> >> >> > > #
>
> >> >> > > ----------
>
> >> >> > > require 'spec_helper'
>
> >> >> > > describe "test matchers" do
> >> >> > > ?it "should be able to find be_success" do
> >> >> > > ? ?get '/'
> >> >> > > ? ?response.should be_success
> >> >> > > ?end
>
> >> >> > > end
>
> >> >> > Try adding this to spec/spec_helper.rb
>
> >> >> > Spec::Runner.configure {|c| c.include Spec::Matchers}
>
> >> _______________________________________________
> >> rspec-users mailing list
> >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
> > _______________________________________________
> > rspec-users mailing list
> > rspec-us... at rubyforge.org
> >http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
From lists at ruby-forum.com Fri Mar 5 08:03:59 2010
From: lists at ruby-forum.com (Amit Kulkarni)
Date: Fri, 5 Mar 2010 14:03:59 +0100
Subject: [rspec-users] Undefined method 'post'
In-Reply-To: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com>
References: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com>
Message-ID: <5170faf6cf63695dedad0c38d342660b@ruby-forum.com>
Amit Kulkarni wrote:
> Hello all,
> I am facing a strange problem.
> I have generated rspec for a particular project.Similarly created a spec
> controller.Under that controller i have written post :create action
> When i run my spec i get an error as
> "undefined method `post' for
> #"
>
> Strangely my models are working fine.My rails version is 2.3.5 and rspec
> version is 1.1.12
> I tried in some other project,in that i am getting error as "Undefined
> method controller for nil class"
> Earlier it was working fine,but dont know what is the problem.
> Please suggest.
I created a fresh application and tried to write simple user signup
controller.
But when i tried to run then it is showing the same error as undefined
method "post"
Please suggest
--
Posted via http://www.ruby-forum.com/.
From dchelimsky at gmail.com Fri Mar 5 08:48:17 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Fri, 5 Mar 2010 07:48:17 -0600
Subject: [rspec-users] Undefined method 'post'
In-Reply-To: <5170faf6cf63695dedad0c38d342660b@ruby-forum.com>
References: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com>
<5170faf6cf63695dedad0c38d342660b@ruby-forum.com>
Message-ID: <57c63afe1003050548k1c2a931bv2efc73886a9c1f58@mail.gmail.com>
On Fri, Mar 5, 2010 at 7:03 AM, Amit Kulkarni wrote:
> Amit Kulkarni wrote:
>> Hello all,
>> I am facing a strange problem.
>> I have generated rspec for a particular project.Similarly created a spec
>> controller.Under that controller i have written post :create action
>> When i run my spec i get an error as
>> "undefined method `post' for
>> #"
>>
>> Strangely my models are working fine.My rails version is 2.3.5 and rspec
>> version is 1.1.12
>> I tried in some other project,in that i am getting error as "Undefined
>> method controller for nil class"
>> Earlier it was working fine,but dont know what is the problem.
>> Please suggest.
> I created a fresh application and tried to write simple user signup
> controller.
> But when i tried to run then it is showing the same error as undefined
> method "post"
> Please suggest
Take a look at these two pages:
http://rubygems.org/gems/rspec-rails/versions
http://rubygems.org/gems/rails/versions
rspec-rails-1.1.12 was released in January of 2009
rails-2.3.5 was released in November of 2009
You've got to use a version of rspec-rails that was released _after_
the version of rails you're working with.
Cheers,
David
From ashley.moran at patchspace.co.uk Sat Mar 6 11:34:57 2010
From: ashley.moran at patchspace.co.uk (Ashley Moran)
Date: Sat, 6 Mar 2010 16:34:57 +0000
Subject: [rspec-users] RSpec 2 / Rails 3 autoload
Message-ID:
Hi
For the last 18 months I've been used to writing specs like this, which was written with Merb 1.1.0.pre and RSpec 1.3:
module LanguageRepository
describe DataMapperAdapter do
it_should_behave_like "Contract: LanguageRepository"
def language_repository
DataMapperAdapter.new
end
end
end
This will happily find and instantiate ::LanguageRepository::DataMapperAdapter from the models/language_repository folder.
However, using Rails 3.0.0.beta from master and Rspec 2.0.0.beta.2, I get the following error:
1) LanguageRepository::DataMapperAdapter storage and retrieval can store
a Language and retrieve it by code
Failure/Error: DataMapperAdapter.new
uninitialized constant Rspec::Core::ExampleGroup::NestedLevel_8::DataMapperAdapter
I have to change it to this to make it work:
def language_repository
LanguageRepository::DataMapperAdapter.new
end
Now, having just changed two moving parts (RSpec and web framework) I'm not sure what correct behaviour is on anything. I don't know how Rails code auto-loading works, or how RSpec interacts with it.
Is the above behaviour a bug or a misunderstanding on my part?
Cheers
Ashley
--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
From jarmo.p at gmail.com Sat Mar 6 12:09:32 2010
From: jarmo.p at gmail.com (Jarmo Pertman)
Date: Sat, 6 Mar 2010 09:09:32 -0800 (PST)
Subject: [rspec-users] how to pass objects from spec to formatter from
before :all block?
Message-ID: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com>
Hello.
I need to pass something from before :all to formatter. I know that i
could use options hash from spec and then get the value back in
formatter, but it doesn't work when i'm doing it from before :all.
So, this work:
# in spec
before :each do
options[:something] = 1
end
# in formatter
def example_failed(example, counter, failure)
puts example.options[:something] # outputs 1
super
end
But if i try to do the same thing from before :all, then it doesn't
work.
So i looked into the source of RSpec and in example/example_methods.rb
in method set_instance_variables_from_hash there is a line which
ignores some instance variables among with others @_proxy, which has
this option hash initialized in before :all and that's why it's not
getting into the formatter - in other words it is just dropped.
Is this a bug or expected behaviour? If it's expected then what's the
reason and how could i get the desired results of passing something to
formatter from before :all?
Can't we just pass this options hash along?
Jarmo
From dchelimsky at gmail.com Sat Mar 6 12:28:59 2010
From: dchelimsky at gmail.com (David Chelimsky)
Date: Sat, 6 Mar 2010 11:28:59 -0600
Subject: [rspec-users] how to pass objects from spec to formatter from
before :all block?
In-Reply-To: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com>
References: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com>
Message-ID: <57c63afe1003060928k59a489d2o37f4106d92c5c8fb@mail.gmail.com>
On Sat, Mar 6, 2010 at 11:09 AM, Jarmo Pertman wrote:
> Hello.
>
> I need to pass something from before :all to formatter. I know that i
> could use options hash from spec and then get the value back in
> formatter, but it doesn't work when i'm doing it from before :all.
>
> So, this work:
>
> # in spec
> before :each do
> ?options[:something] = 1
> end
>
> # in formatter
> def example_failed(example, counter, failure)
> ?puts example.options[:something] # outputs 1
> ?super
> end
>
> But if i try to do the same thing from before :all, then it doesn't
> work.
>
> So i looked into the source of RSpec and in example/example_methods.rb
> in method set_instance_variables_from_hash there is a line which
> ignores some instance variables among with others @_proxy, which has
> this option hash initialized in before :all and that's why it's not
> getting into the formatter - in other words it is just dropped.
>
> Is this a bug or expected behaviour? If it's expected then what's the
> reason and how could i get the desired results of passing something to
> formatter from before :all?
>
> Can't we just pass this options hash along?
It was never intended that you would set values on options from inside
an example and access them in a formatter. You've happened on
something that just happens to work because we're using a standard
Ruby data structure.
The reason it won't work for before(:all) is that before(:all) gets
run before any of the examples are run - so it doesn't have access to
the options hash, which is created per example in rspec-1.
What sort of information are you trying to get to your formatter?
Maybe there is a different way to do it.
From jarmo.p at gmail.com Sat Mar 6 13:33:20 2010
From: jarmo.p at gmail.com (Jarmo Pertman)
Date: Sat, 6 Mar 2010 10:33:20 -0800 (PST)
Subject: [rspec-users] how to pass objects from spec to formatter from
before :all block?
In-Reply-To: <57c63afe1003060928k59a489d2o37f4106d92c5c8fb@mail.gmail.com>
References: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com>
<57c63afe1003060928k59a489d2o37f4106d92c5c8fb@mail.gmail.com>
Message-ID: <54f97986-2774-4e66-8e36-54240be7390a@g7g2000yqe.googlegroups.com>
Since i'm using Watir then i usually open up the browser in
before :all block like this:
before :all do
@browser = Watir::Browser.new
end
and then in the formatter I'm saving html of the browser - thus
needing to access the browser object.
I could solve it currently by using before :each block as shown in my
first post or a global variable (not nice at all), but i thought that
it would be more logical to set it into options in before :all once.
Also, if using before :each solution and something fails in
before :all, then formatter doesn't know currently anything about the
browser object and cannot save the html or anything. It's little bit
bad, since let's say if i do also some "setup actions" in before :all
before the actual tests and what if something fails there?
But what would happen if example_group options would be merged with
example options?
Any other solutions?
Jarmo
On Mar 6, 7:28?pm, David Chelimsky wrote:
> On Sat, Mar 6, 2010 at 11:09 AM, Jarmo Pertman wrote:
> > Hello.
>
> > I need to pass something from before :all to formatter. I know that i
> > could use options hash from spec and then get the value back in
> > formatter, but it doesn't work when i'm doing it from before :all.
>
> > So, this work:
>
> > # in spec
> > before :each do
> > ?options[:something] = 1
> > end
>
> > # in formatter
> > def example_failed(example, counter, failure)
> > ?puts example.options[:something] # outputs 1
> > ?super
> > end
>
> > But if i try to do the same thing from before :all, then it doesn't
> > work.
>
> > So i looked into the source of RSpec and in example/example_methods.rb
> > in method set_instance_variables_from_hash there is a line which
> > ignores some instance variables among with others @_proxy, which has
> > this option hash initialized in before :all and that's why it's not
> > getting into the formatter - in other words it is just dropped.
>
> > Is this a bug or expected behaviour? If it's expected then what's the
> > reason and how could i get the desired results of passing something to
> > formatter from before :all?
>
> > Can't we just pass this options hash along?
>
> It was never intended that you would set values on options from inside
> an example and access them in a formatter. You've happened on
> something that just happens to work because we're using a standard
> Ruby data structure.
>
> The reason it won't work for before(:all) is that before(:all) gets
> run before any of the examples are run - so it doesn't have access to
> the options hash, which is created per example in rspec-1.
>
> What sort of information are you trying to get to your formatter?
> Maybe there is a different way to do it.
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
From ed.howland at gmail.com Sat Mar 6 14:21:21 2010
From: ed.howland at gmail.com (Ed Howland)
Date: Sat, 6 Mar 2010 14:21:21 -0500
Subject: [rspec-users] Newlines in step arguments Was How can I pass an XML
block...
Message-ID: <3df642dd1003061121s63e65d66y143977644dbdb039@mail.gmail.com>
On Tue, Apr 14, 2009 at 10:03 PM, Stephen Eley wrote:
> On Tue, Apr 14, 2009 at 10:37 PM, Stephen Eley wrote:
>>
> All right, never mind. ?Having been given enough clues that the
> feature exists and what it generally might look like, I prowled
> through Cucumber's specs and examples until I got a clearer picture.
> Then, to keep my 'There ain't no documentation!' whining privileges, I
> went and added what I learned to the wiki:
>
> http://wiki.github.com/aslakhellesoy/cucumber/multiline-step-arguments
>
This is fantastic! I admit that I must gave skimmed over the that in
the book, but your wiki page made it very clear.
I wrote some steps that call a command and capture the output with
IO at popen. In my code I was testing, I used puts everywhere and could
not figure out how to match the newlines in Cuke,
E.g.
Then the output should be
"""
| | |