From james at rapleaf.com Tue Feb 1 04:40:52 2011 From: james at rapleaf.com (James OBrien) Date: Tue, 1 Feb 2011 01:40:52 -0800 Subject: [rspec-users] array order-agnostic matching? Message-ID: hey, thanks for reading: I have a problem which can be reduced to this, from within an example of mine I call the helper 'expect_call' which is defined thus: def expect_call(*hash*)* *obj.should_receive(:some_ method).with(*hash*)* *end and in one of my examples the 'expected' hash is strictly defined as follows expect_call(*{ :some_key => [1,2,3] }*) however my spec fails because it is actually called with *{ :some_key => [1,3,2] } *or maybe *{ :some_key => [2,3,1] } *or *{ :some_key => [2,1,3] } *i.e. the array part is not in the order i 'expect' BUT i don't actually care about the order. So I would like to be able to change my one example to something like this: expect_call(*{ *:some_key => [1,2,3]*.ignoring_order }*) does such a concept exist or do I have to change the implementation of expect_call to use some sort of custom matcher - I am reluctant to do this since this method is called in other cases where maybe (for arguments sake) I DO care about array ordering within the hash. Hope someone can solve this for me - MUCH appreciation. James -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Feb 1 07:43:27 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 1 Feb 2011 06:43:27 -0600 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: References: Message-ID: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> On Feb 1, 2011, at 3:40 AM, James OBrien wrote: > hey, thanks for reading: > > I have a problem which can be reduced to this, > > from within an example of mine I call the helper 'expect_call' which is defined thus: > > def expect_call(hash) > obj.should_receive(:some_ > method).with(hash) > end > > and in one of my examples the 'expected' hash is strictly defined as follows > > expect_call({ > :some_key => [1,2,3] > }) > > however my spec fails because it is actually called with > > { > :some_key => [1,3,2] > } > > or maybe > > { > :some_key => [2,3,1] > } > > or > > { > :some_key => [2,1,3] > } > > i.e. the array part is not in the order i 'expect' BUT i don't actually care about the order. So I would like to be able to change my one example to something like this: > > expect_call({ > :some_key => [1,2,3].ignoring_order > }) > > does such a concept exist or do I have to change the implementation of expect_call to use some sort of custom matcher - I am reluctant to do this since this method is called in other cases where maybe (for arguments sake) I DO care about array ordering within the hash. rspec-expectations lets you do this: foo.bar.should =~ [1,2,3] This passes as long as the array contains exactly those three elements in any order. You can use this now in conjunction with rspec-mocks, like this: foo.should_receive(:bar) do |hash| hash[:some_key].should =~ [1,2,3] end It's a bit more verbose than what you're looking for, but it can get you there with rspec as/is today. Going forward, we might want to consider an array_including argument matcher for rspec-mocks. We already have a hash_including matcher that works like this: foo.should_receive(:bar).with(hash_including(:a => 'b')) Similarly we could have: foo.should_receive(:bar).with(array_including(1,2,3)) The only problem with this is the name: array_including could mean different things (ordered/unordered, only these elements or subset, etc). The hash_including matcher is specifically about a subset of a hash. But perhaps we could extend this with something like you proposed above: foo.should_receive(:bar).with(array_including(1,2,3)) foo.should_receive(:bar).with(array_including(1,2,3).ingoring_order) foo.should_receive(:bar).with(array_including(1,2,3).only.ingoring_order) The thing is, I'm not sure this is any better than the example I gave above, which is very precise and works today. Thoughts/opinions welcome. > Hope someone can solve this for me - MUCH appreciation. As an aside, when passing a hash as an argument you don't need to use curly braces, as long as the hash is the last argument to the method. These two are equivalent: expect_call(1, :a, {:some_key => 'some value'}) expect_call(1, :a, :some_key => 'some value') HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at rapleaf.com Tue Feb 1 11:46:42 2011 From: james at rapleaf.com (James OBrien) Date: Tue, 1 Feb 2011 08:46:42 -0800 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> References: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> Message-ID: Awesome, thanks David! there are other entries in the hash so presumably I will need something like this i.e. foo.should_receive(:bar) do |hash| actual = hash[:some_key] hash[:some_key].should =~ [1,2,3] hash.shoul end On Tue, Feb 1, 2011 at 4:43 AM, David Chelimsky wrote: > > On Feb 1, 2011, at 3:40 AM, James OBrien wrote: > > hey, thanks for reading: > > I have a problem which can be reduced to this, > > from within an example of mine I call the helper 'expect_call' which is > defined thus: > > def expect_call(*hash*)* > *obj.should_receive(:some_ > method).with(*hash*)* > *end > > and in one of my examples the 'expected' hash is strictly defined as > follows > > expect_call(*{ > :some_key => [1,2,3] > }*) > > however my spec fails because it is actually called with > > *{ > :some_key => [1,3,2] > } > > *or maybe > > *{ > :some_key => [2,3,1] > } > > *or > > *{ > :some_key => [2,1,3] > } > > *i.e. the array part is not in the order i 'expect' BUT i don't actually > care about the order. So I would like to be able to change my one example to > something like this: > > expect_call(*{ > *:some_key => [1,2,3]*.ignoring_order > }*) > > does such a concept exist or do I have to change the implementation of > expect_call to use some sort of custom matcher - I am reluctant to do this > since this method is called in other cases where maybe (for arguments sake) > I DO care about array ordering within the hash. > > > rspec-expectations lets you do this: > > foo.bar.should =~ [1,2,3] > > This passes as long as the array contains exactly those three elements in > any order. You can use this now in conjunction with rspec-mocks, like this: > > foo.should_receive(:bar) do |hash| > hash[:some_key].should =~ [1,2,3] > end > > It's a bit more verbose than what you're looking for, but it can get you > there with rspec as/is today. > > Going forward, we might want to consider an array_including argument > matcher for rspec-mocks. We already have a hash_including matcher that works > like this: > > foo.should_receive(:bar).with(hash_including(:a => 'b')) > > Similarly we could have: > > foo.should_receive(:bar).with(array_including(1,2,3)) > > The only problem with this is the name: array_including could mean > different things (ordered/unordered, only these elements or subset, etc). > The hash_including matcher is specifically about a subset of a hash. But > perhaps we could extend this with something like you proposed above: > > foo.should_receive(:bar).with(array_including(1,2,3)) > foo.should_receive(:bar).with(array_including(1,2,3).ingoring_order) > foo.should_receive(:bar).with(array_including(1,2,3).only.ingoring_order) > > The thing is, I'm not sure this is any better than the example I gave > above, which is very precise and works today. Thoughts/opinions welcome. > > Hope someone can solve this for me - MUCH appreciation. > > > As an aside, when passing a hash as an argument you don't need to use curly > braces, as long as the hash is the last argument to the method. These two > are equivalent: > > expect_call(1, :a, {:some_key => 'some value'}) > expect_call(1, :a, :some_key => 'some value') > > HTH, > David > > > > > _______________________________________________ > 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 james at rapleaf.com Tue Feb 1 11:51:01 2011 From: james at rapleaf.com (James OBrien) Date: Tue, 1 Feb 2011 08:51:01 -0800 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: References: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> Message-ID: ooops, that sent itself early... . . . there are other entries in the hash so presumably I will need something like this foo.should_receive(:bar) do |hash| actual = hash[:some_key] *hash[:some_key] = nil* hash.should == { :my => 'expected' :other => 1 :ields => :in_the_hash } actual.should =~ [1,2,3] end i.e. I assert :some_key and 'the rest' separately. There isn't a way to do this simpler is there? Thanks again David! On Tue, Feb 1, 2011 at 8:46 AM, James OBrien wrote: > Awesome, thanks David! > > there are other entries in the hash so presumably I will need something > like this > > i.e. > > > foo.should_receive(:bar) do |hash| > actual = hash[:some_key] > > hash[:some_key].should =~ [1,2,3] > hash.shoul > end > > > > > On Tue, Feb 1, 2011 at 4:43 AM, David Chelimsky wrote: > >> >> On Feb 1, 2011, at 3:40 AM, James OBrien wrote: >> >> hey, thanks for reading: >> >> I have a problem which can be reduced to this, >> >> from within an example of mine I call the helper 'expect_call' which is >> defined thus: >> >> def expect_call(*hash*)* >> *obj.should_receive(:some_ >> method).with(*hash*)* >> *end >> >> and in one of my examples the 'expected' hash is strictly defined as >> follows >> >> expect_call(*{ >> :some_key => [1,2,3] >> }*) >> >> however my spec fails because it is actually called with >> >> *{ >> :some_key => [1,3,2] >> } >> >> *or maybe >> >> *{ >> :some_key => [2,3,1] >> } >> >> *or >> >> *{ >> :some_key => [2,1,3] >> } >> >> *i.e. the array part is not in the order i 'expect' BUT i don't actually >> care about the order. So I would like to be able to change my one example to >> something like this: >> >> expect_call(*{ >> *:some_key => [1,2,3]*.ignoring_order >> }*) >> >> does such a concept exist or do I have to change the implementation of >> expect_call to use some sort of custom matcher - I am reluctant to do this >> since this method is called in other cases where maybe (for arguments sake) >> I DO care about array ordering within the hash. >> >> >> rspec-expectations lets you do this: >> >> foo.bar.should =~ [1,2,3] >> >> This passes as long as the array contains exactly those three elements in >> any order. You can use this now in conjunction with rspec-mocks, like this: >> >> foo.should_receive(:bar) do |hash| >> hash[:some_key].should =~ [1,2,3] >> end >> >> It's a bit more verbose than what you're looking for, but it can get you >> there with rspec as/is today. >> >> Going forward, we might want to consider an array_including argument >> matcher for rspec-mocks. We already have a hash_including matcher that works >> like this: >> >> foo.should_receive(:bar).with(hash_including(:a => 'b')) >> >> Similarly we could have: >> >> foo.should_receive(:bar).with(array_including(1,2,3)) >> >> The only problem with this is the name: array_including could mean >> different things (ordered/unordered, only these elements or subset, etc). >> The hash_including matcher is specifically about a subset of a hash. But >> perhaps we could extend this with something like you proposed above: >> >> foo.should_receive(:bar).with(array_including(1,2,3)) >> foo.should_receive(:bar).with(array_including(1,2,3).ingoring_order) >> >> foo.should_receive(:bar).with(array_including(1,2,3).only.ingoring_order) >> >> The thing is, I'm not sure this is any better than the example I gave >> above, which is very precise and works today. Thoughts/opinions welcome. >> >> Hope someone can solve this for me - MUCH appreciation. >> >> >> As an aside, when passing a hash as an argument you don't need to use >> curly braces, as long as the hash is the last argument to the method. These >> two are equivalent: >> >> expect_call(1, :a, {:some_key => 'some value'}) >> expect_call(1, :a, :some_key => 'some value') >> >> HTH, >> David >> >> >> >> >> _______________________________________________ >> 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 james at rapleaf.com Tue Feb 1 12:01:51 2011 From: james at rapleaf.com (James OBrien) Date: Tue, 1 Feb 2011 09:01:51 -0800 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: References: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> Message-ID: additionally, since my *foo.should_receive(... *expectation * *is actually in a private helper method ('expect_call') on the example group I will need to pull this code up into a block, since not all callers pass a hash with :some_key set viz: #helper_method *def expect_call foo.should_receiver(:bar) do |hash| yield hash end end* then those examples which dont care about my array ordering problem (or rather care that it is in order!) can just do: *expect_call do |actual_hash| actual_hash.should == {:some => 'expected_value', :other => [4,5,6]} end* and the one case that does care can do: *expect_call do |actual_hash| actual = **actual_hash[:some_key] **actual_hash**[:some_key] = nil **actual_hash.should == { :my => 'expected' :other => 1 :ields => :in_the_hash } actual.should =~ [1,2,3] ** end* does this sound sensible? Thanks so much again - I have your book :) and although I'm new to it I really enjoy rspec! On Tue, Feb 1, 2011 at 8:51 AM, James OBrien wrote: > ooops, that sent itself early... > > . . . > > there are other entries in the hash so presumably I will need something > like this > > foo.should_receive(:bar) do |hash| > actual = hash[:some_key] > *hash[:some_key] = nil* > hash.should == { > :my => 'expected' > :other => 1 > :ields => :in_the_hash > } > actual.should =~ [1,2,3] > > end > > i.e. I assert :some_key and 'the rest' separately. > > There isn't a way to do this simpler is there? > > Thanks again David! > > > On Tue, Feb 1, 2011 at 8:46 AM, James OBrien wrote: > >> Awesome, thanks David! >> >> there are other entries in the hash so presumably I will need something >> like this >> >> i.e. >> >> >> foo.should_receive(:bar) do |hash| >> actual = hash[:some_key] >> >> hash[:some_key].should =~ [1,2,3] >> hash.shoul >> end >> >> >> >> >> On Tue, Feb 1, 2011 at 4:43 AM, David Chelimsky wrote: >> >>> >>> On Feb 1, 2011, at 3:40 AM, James OBrien wrote: >>> >>> hey, thanks for reading: >>> >>> I have a problem which can be reduced to this, >>> >>> from within an example of mine I call the helper 'expect_call' which is >>> defined thus: >>> >>> def expect_call(*hash*)* >>> *obj.should_receive(:some_ >>> method).with(*hash*)* >>> *end >>> >>> and in one of my examples the 'expected' hash is strictly defined as >>> follows >>> >>> expect_call(*{ >>> :some_key => [1,2,3] >>> }*) >>> >>> however my spec fails because it is actually called with >>> >>> *{ >>> :some_key => [1,3,2] >>> } >>> >>> *or maybe >>> >>> *{ >>> :some_key => [2,3,1] >>> } >>> >>> *or >>> >>> *{ >>> :some_key => [2,1,3] >>> } >>> >>> *i.e. the array part is not in the order i 'expect' BUT i don't actually >>> care about the order. So I would like to be able to change my one example to >>> something like this: >>> >>> expect_call(*{ >>> *:some_key => [1,2,3]*.ignoring_order >>> }*) >>> >>> does such a concept exist or do I have to change the implementation of >>> expect_call to use some sort of custom matcher - I am reluctant to do this >>> since this method is called in other cases where maybe (for arguments sake) >>> I DO care about array ordering within the hash. >>> >>> >>> rspec-expectations lets you do this: >>> >>> foo.bar.should =~ [1,2,3] >>> >>> This passes as long as the array contains exactly those three elements in >>> any order. You can use this now in conjunction with rspec-mocks, like this: >>> >>> foo.should_receive(:bar) do |hash| >>> hash[:some_key].should =~ [1,2,3] >>> end >>> >>> It's a bit more verbose than what you're looking for, but it can get you >>> there with rspec as/is today. >>> >>> Going forward, we might want to consider an array_including argument >>> matcher for rspec-mocks. We already have a hash_including matcher that works >>> like this: >>> >>> foo.should_receive(:bar).with(hash_including(:a => 'b')) >>> >>> Similarly we could have: >>> >>> foo.should_receive(:bar).with(array_including(1,2,3)) >>> >>> The only problem with this is the name: array_including could mean >>> different things (ordered/unordered, only these elements or subset, etc). >>> The hash_including matcher is specifically about a subset of a hash. But >>> perhaps we could extend this with something like you proposed above: >>> >>> foo.should_receive(:bar).with(array_including(1,2,3)) >>> foo.should_receive(:bar).with(array_including(1,2,3).ingoring_order) >>> >>> foo.should_receive(:bar).with(array_including(1,2,3).only.ingoring_order) >>> >>> The thing is, I'm not sure this is any better than the example I gave >>> above, which is very precise and works today. Thoughts/opinions welcome. >>> >>> Hope someone can solve this for me - MUCH appreciation. >>> >>> >>> As an aside, when passing a hash as an argument you don't need to use >>> curly braces, as long as the hash is the last argument to the method. These >>> two are equivalent: >>> >>> expect_call(1, :a, {:some_key => 'some value'}) >>> expect_call(1, :a, :some_key => 'some value') >>> >>> HTH, >>> David >>> >>> >>> >>> >>> _______________________________________________ >>> 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 ks at cissor.com Tue Feb 1 17:23:55 2011 From: ks at cissor.com (Kurt) Date: Tue, 1 Feb 2011 14:23:55 -0800 (PST) Subject: [rspec-users] Notes on upgrading from RSpec 1 to RSpec 2 In-Reply-To: <3e26c20f-cabf-4b1b-b2d6-fd8a9879c16a@z26g2000prf.googlegroups.com> References: <3e26c20f-cabf-4b1b-b2d6-fd8a9879c16a@z26g2000prf.googlegroups.com> Message-ID: I've started a chart of differences between RSpec 1 and 2 here: http://snyderscribbles.blogspot.com/2011/01/rspec-2-changes-from-rspec-1.html I'll gladly post any new discoveries anyone want to contribute. On Dec 4 2010, 3:22?pm, Jim Morris wrote: > I am trying to upgrade a Rails 2.2.2app to Rails3, its ?a pain ;) > > Part of this is I need to upgrade all my Specs to RSpec2, as this info > does not seem to be in any one place, here is a summary of what I > needed to do... > > * needed to rename all my views from .haml to .html.haml, > (or .html.erb) although > ? Rails3 seemed ok with the old naming RSpec2 view specs failed to > find the templates with the old name. > > * rewrite all my view specs... > ? - change `... at controller.template.` to `view.` > > ? - ?change `have_tag` to `have_selector` and change the parameters > ? ? ?- place holders not supported, need to use #{} > ? ? ?- add :content => for any text in second parameter > > ? - change `assign[:blah]= :blod` to `assign(:blag, :blod)` > > ? - change the describe ... do to have the path to the view rather > than text description > > ? - change the render '/show' to just render or render :file => 'full > template spec' > > ? - change have_text to matches(/../) > > ? - change response.should to rendered.shoul > > * modify the controller specs > ? - controller_name is no longer supported, so need to nest all my > ? ? describes under a top level describe that has the controller > name. > ? ? ?describe 'UsersController' do > ? ? ?or use subject {SomeController.new} ?(not tested yet) > > ? ?- when using post/delete/put :something, :id => 1 passing in an > integer id used to work, now it needs to > ? ? ?be a string (probably a rails3 thing) > ? ? ?delete :destroy, :id => "1" > > * helper specs only needed minor changes > ? - change have_tag to have_selector > > _______________________________________________rspec-users mailing listrspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ks at cissor.com Tue Feb 1 17:31:26 2011 From: ks at cissor.com (Kurt) Date: Tue, 1 Feb 2011 14:31:26 -0800 (PST) Subject: [rspec-users] Notes on upgrading from RSpec 1 to RSpec 2 In-Reply-To: <0869CA82-68F6-4BE9-9F7F-2237D9B83653@gmail.com> References: <3e26c20f-cabf-4b1b-b2d6-fd8a9879c16a@z26g2000prf.googlegroups.com> <25e0965e-27e3-4502-8d0d-0adba7132b55@v17g2000vbo.googlegroups.com> <0869CA82-68F6-4BE9-9F7F-2237D9B83653@gmail.com> Message-ID: <8d1bb229-8fc9-4322-b4b9-c11e156c83b7@y12g2000prf.googlegroups.com> Most of our RSpec2 conversion has been done since version 2.4, so my report of performance 2-3 times slower than RSpec 1 is based on those releases. On Jan 13, 11:11?am, David Chelimsky wrote: > On Jan 13, 2011, at 12:36 PM, Kurt wrote: > > > Hi -- Thanks for sharing all your tips. ?I couldn't understand your > > line about what replaces have_text, however. ?I don't see a method > > called "matches" or "match"... > > > I think your list might be the start of an effort by users to document > >RSpec2the hard way, since a lot has changed that the core team has > > not documented anywhere. ?We've found that the Rails3upgradeis some > > work, but the advantages over Rails 2 are clear. ?RSpec2, however, is > > so poorly documented, useful features have been removed for no > > apparent reason, and any advantages over RSpec1 have not become clear > > yet (our test suite runs 3 times slower than it did in RSpec1!). > > re: speed, you be sure toupgradeto rspec-rails-2.2 (I'd go for the latest, 2.4.1), which sped things up considerably. > > As for docs - official docs are athttp://relishapp.com/rspec. > > Info about contributing to the docs can be found there and athttp://blog.davidchelimsky.net/2010/12/23/rspec-2-documentation-2/. > > Thanks in advance for your help. > > Cheers, > David > > > > > On Dec 4 2010, 3:22 pm, Jim Morris wrote: > >> I am trying toupgradea Rails 2.2.2 app to Rails3, its ?a pain ;) > > >> Part of this is I need toupgradeall my Specs toRSpec2, as this info > >> does not seem to be in any one place, here is a summary of what I > >> needed to do... > > >> * needed to rename all my views from .haml to .html.haml, > >> (or .html.erb) although > >> ? Rails3 seemed ok with the old namingRSpec2view specs failed to > >> find the templates with the old name. > > >> * rewrite all my view specs... > >> ? - change `... at controller.template.` to `view.` > > >> ? - ?change `have_tag` to `have_selector` and change the parameters > >> ? ? ?- place holders not supported, need to use #{} > >> ? ? ?- add :content => for any text in second parameter > > >> ? - change `assign[:blah]= :blod` to `assign(:blag, :blod)` > > >> ? - change the describe ... do to have the path to the view rather > >> than text description > > >> ? - change the render '/show' to just render or render :file => 'full > >> template spec' > > >> ? - changehave_textto matches(/../) > > >> ? - change response.should to rendered.shoul > > >> * modify the controller specs > >> ? - controller_name is no longer supported, so need to nest all my > >> ? ? describes under a top level describe that has the controller > >> name. > >> ? ? ?describe 'UsersController' do > >> ? ? ?or use subject {SomeController.new} ?(not tested yet) > > >> ? ?- when using post/delete/put :something, :id => 1 passing in an > >> integer id used to work, now it needs to > >> ? ? ?be a string (probably a rails3 thing) > >> ? ? ?delete :destroy, :id => "1" > > >> * helper specs only needed minor changes > >> ? - change have_tag to have_selector > > >> _______________________________________________ > >> 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 ks at cissor.com Tue Feb 1 17:39:01 2011 From: ks at cissor.com (Kurt) Date: Tue, 1 Feb 2011 14:39:01 -0800 (PST) Subject: [rspec-users] Rspec2 - Absolutely brilliant! (at breaking stuff) - Is there a downgrade path ? In-Reply-To: <9b5d915c-88b8-4802-b380-d6656b32134f@f20g2000vbc.googlegroups.com> Message-ID: <21121543.36.1296599941458.JavaMail.geo-discussion-forums@prnp16> When you're ready to try RSpec2 again, checkout this cheat sheet of changes from RSpec1. http://snyderscribbles.blogspot.com/2011/01/rspec-2-changes-from-rspec-1.html We're adding to the list as people discover more... -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Feb 1 18:12:17 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 1 Feb 2011 17:12:17 -0600 Subject: [rspec-users] Notes on upgrading from RSpec 1 to RSpec 2 In-Reply-To: <8d1bb229-8fc9-4322-b4b9-c11e156c83b7@y12g2000prf.googlegroups.com> References: <3e26c20f-cabf-4b1b-b2d6-fd8a9879c16a@z26g2000prf.googlegroups.com> <25e0965e-27e3-4502-8d0d-0adba7132b55@v17g2000vbo.googlegroups.com> <0869CA82-68F6-4BE9-9F7F-2237D9B83653@gmail.com> <8d1bb229-8fc9-4322-b4b9-c11e156c83b7@y12g2000prf.googlegroups.com> Message-ID: <768A406B-B5AF-441C-AA91-E4908C2E64C5@gmail.com> On Feb 1, 2011, at 4:31 PM, Kurt wrote: > Most of our RSpec2 conversion has been done since version 2.4, so my > report of performance 2-3 times slower than RSpec 1 is based on those > releases. Are you sure that's all RSpec? rspec-core-2.2 actually runs faster than rspec-core-1.x, and a lot of the Rails framework changed as well. And don't forget bundler. There are a lot of moving parts here, so if you can isolate the slow down to RSpec, please let us know what you find so we can address any specific issues. Thanks! David > On Jan 13, 11:11 am, David Chelimsky wrote: >> On Jan 13, 2011, at 12:36 PM, Kurt wrote: >> >>> Hi -- Thanks for sharing all your tips. I couldn't understand your >>> line about what replaces have_text, however. I don't see a method >>> called "matches" or "match"... >> >>> I think your list might be the start of an effort by users to document >>> RSpec2the hard way, since a lot has changed that the core team has >>> not documented anywhere. We've found that the Rails3upgradeis some >>> work, but the advantages over Rails 2 are clear. RSpec2, however, is >>> so poorly documented, useful features have been removed for no >>> apparent reason, and any advantages over RSpec1 have not become clear >>> yet (our test suite runs 3 times slower than it did in RSpec1!). >> >> re: speed, you be sure toupgradeto rspec-rails-2.2 (I'd go for the latest, 2.4.1), which sped things up considerably. >> >> As for docs - official docs are athttp://relishapp.com/rspec. >> >> Info about contributing to the docs can be found there and athttp://blog.davidchelimsky.net/2010/12/23/rspec-2-documentation-2/. >> >> Thanks in advance for your help. >> >> Cheers, >> David >> >> >> >>> On Dec 4 2010, 3:22 pm, Jim Morris wrote: >>>> I am trying toupgradea Rails 2.2.2 app to Rails3, its a pain ;) >> >>>> Part of this is I need toupgradeall my Specs toRSpec2, as this info >>>> does not seem to be in any one place, here is a summary of what I >>>> needed to do... >> >>>> * needed to rename all my views from .haml to .html.haml, >>>> (or .html.erb) although >>>> Rails3 seemed ok with the old namingRSpec2view specs failed to >>>> find the templates with the old name. >> >>>> * rewrite all my view specs... >>>> - change `... at controller.template.` to `view.` >> >>>> - change `have_tag` to `have_selector` and change the parameters >>>> - place holders not supported, need to use #{} >>>> - add :content => for any text in second parameter >> >>>> - change `assign[:blah]= :blod` to `assign(:blag, :blod)` >> >>>> - change the describe ... do to have the path to the view rather >>>> than text description >> >>>> - change the render '/show' to just render or render :file => 'full >>>> template spec' >> >>>> - changehave_textto matches(/../) >> >>>> - change response.should to rendered.shoul >> >>>> * modify the controller specs >>>> - controller_name is no longer supported, so need to nest all my >>>> describes under a top level describe that has the controller >>>> name. >>>> describe 'UsersController' do >>>> or use subject {SomeController.new} (not tested yet) >> >>>> - when using post/delete/put :something, :id => 1 passing in an >>>> integer id used to work, now it needs to >>>> be a string (probably a rails3 thing) >>>> delete :destroy, :id => "1" >> >>>> * helper specs only needed minor changes >>>> - change have_tag to have_selector >> >>>> _______________________________________________ >>>> 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Feb 1 18:17:57 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 1 Feb 2011 17:17:57 -0600 Subject: [rspec-users] Notes on upgrading from RSpec 1 to RSpec 2 In-Reply-To: References: <3e26c20f-cabf-4b1b-b2d6-fd8a9879c16a@z26g2000prf.googlegroups.com> Message-ID: <270924ED-4D97-4BD5-A061-1EB537802E1E@gmail.com> On Feb 1, 2011, at 4:23 PM, Kurt wrote: > I've started a chart of differences between RSpec 1 and 2 here: > http://snyderscribbles.blogspot.com/2011/01/rspec-2-changes-from-rspec-1.html > > I'll gladly post any new discoveries anyone want to contribute. It would be great if you would contribute these directly to RSpec's docs so everyone can find them and benefit from them. Take a look at: http://relishapp.com/rspec/rspec-core/v/2-4/file/upgrade http://relishapp.com/rspec/rspec-rails/v/2-4/file/upgrade They are just Markdown files, maintained in the rspec projects: https://github.com/rspec/rspec-core/blob/master/features/Upgrade.md https://github.com/rspec/rspec-rails/blob/master/features/Upgrade.md Just submit pull requests and I'll be happy to merge them. Cheers, David > On Dec 4 2010, 3:22 pm, Jim Morris wrote: >> I am trying to upgrade a Rails 2.2.2app to Rails3, its a pain ;) >> >> Part of this is I need to upgrade all my Specs to RSpec2, as this info >> does not seem to be in any one place, here is a summary of what I >> needed to do... >> >> * needed to rename all my views from .haml to .html.haml, >> (or .html.erb) although >> Rails3 seemed ok with the old naming RSpec2 view specs failed to >> find the templates with the old name. >> >> * rewrite all my view specs... >> - change `... at controller.template.` to `view.` >> >> - change `have_tag` to `have_selector` and change the parameters >> - place holders not supported, need to use #{} >> - add :content => for any text in second parameter >> >> - change `assign[:blah]= :blod` to `assign(:blag, :blod)` >> >> - change the describe ... do to have the path to the view rather >> than text description >> >> - change the render '/show' to just render or render :file => 'full >> template spec' >> >> - change have_text to matches(/../) >> >> - change response.should to rendered.shoul >> >> * modify the controller specs >> - controller_name is no longer supported, so need to nest all my >> describes under a top level describe that has the controller >> name. >> describe 'UsersController' do >> or use subject {SomeController.new} (not tested yet) >> >> - when using post/delete/put :something, :id => 1 passing in an >> integer id used to work, now it needs to >> be a string (probably a rails3 thing) >> delete :destroy, :id => "1" >> >> * helper specs only needed minor changes >> - change have_tag to have_selector >> >> _______________________________________________rspec-users mailing listrspec-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 julian at leviston.net Tue Feb 1 20:28:20 2011 From: julian at leviston.net (Julian Leviston) Date: Wed, 2 Feb 2011 12:28:20 +1100 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: References: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> Message-ID: Does this strike anyone else as odd? Don't you think the test should actually be written IN to the code itself? I guess I'm soft of stipulating a new language here, but perhaps Ruby is flexible enough to enable this. Surely as the private methods of a class change, the testing code HAS to change... therefore isn't it best to actually write the rspec-level tests into the classes themselves as context-sensitive-optionally loaded or not depending on whether you're in testing mode or not Julian On 02/02/2011, at 4:01 AM, James OBrien wrote: > additionally, > > since my > > foo.should_receive(... > > expectation > > is actually in a private helper method ('expect_call') on the example group I will need to pull this code up into a block, since not all callers pass a hash with :some_key set > > viz: > > #helper_method > def expect_call > foo.should_receiver(:bar) do |hash| > yield hash > end > end > > then those examples which dont care about my array ordering problem (or rather care that it is in order!) can just do: > > expect_call do |actual_hash| > actual_hash.should == {:some => 'expected_value', :other => [4,5,6]} > end > > and the one case that does care can do: > > expect_call do |actual_hash| > actual = actual_hash[:some_key] > actual_hash[:some_key] = nil > actual_hash.should == { > :my => 'expected' > :other => 1 > :ields => :in_the_hash > } > actual.should =~ [1,2,3] > end > > does this sound sensible? > > Thanks so much again - I have your book :) and although I'm new to it I really enjoy rspec! > > On Tue, Feb 1, 2011 at 8:51 AM, James OBrien wrote: > ooops, that sent itself early... > > . . . > > there are other entries in the hash so presumably I will need something like this > > foo.should_receive(:bar) do |hash| > actual = hash[:some_key] > hash[:some_key] = nil > hash.should == { > :my => 'expected' > :other => 1 > :ields => :in_the_hash > } > actual.should =~ [1,2,3] > > end > > i.e. I assert :some_key and 'the rest' separately. > > There isn't a way to do this simpler is there? > > Thanks again David! > > > On Tue, Feb 1, 2011 at 8:46 AM, James OBrien wrote: > Awesome, thanks David! > > there are other entries in the hash so presumably I will need something like this > > i.e. > > > foo.should_receive(:bar) do |hash| > actual = hash[:some_key] > > hash[:some_key].should =~ [1,2,3] > hash.shoul > end > > > > > On Tue, Feb 1, 2011 at 4:43 AM, David Chelimsky wrote: > > On Feb 1, 2011, at 3:40 AM, James OBrien wrote: > >> hey, thanks for reading: >> >> I have a problem which can be reduced to this, >> >> from within an example of mine I call the helper 'expect_call' which is defined thus: >> >> def expect_call(hash) >> obj.should_receive(:some_ >> method).with(hash) >> end >> >> and in one of my examples the 'expected' hash is strictly defined as follows >> >> expect_call({ >> :some_key => [1,2,3] >> }) >> >> however my spec fails because it is actually called with >> >> { >> :some_key => [1,3,2] >> } >> >> or maybe >> >> { >> :some_key => [2,3,1] >> } >> >> or >> >> { >> :some_key => [2,1,3] >> } >> >> i.e. the array part is not in the order i 'expect' BUT i don't actually care about the order. So I would like to be able to change my one example to something like this: >> >> expect_call({ >> :some_key => [1,2,3].ignoring_order >> }) >> >> does such a concept exist or do I have to change the implementation of expect_call to use some sort of custom matcher - I am reluctant to do this since this method is called in other cases where maybe (for arguments sake) I DO care about array ordering within the hash. > > rspec-expectations lets you do this: > > foo.bar.should =~ [1,2,3] > > This passes as long as the array contains exactly those three elements in any order. You can use this now in conjunction with rspec-mocks, like this: > > foo.should_receive(:bar) do |hash| > hash[:some_key].should =~ [1,2,3] > end > > It's a bit more verbose than what you're looking for, but it can get you there with rspec as/is today. > > Going forward, we might want to consider an array_including argument matcher for rspec-mocks. We already have a hash_including matcher that works like this: > > foo.should_receive(:bar).with(hash_including(:a => 'b')) > > Similarly we could have: > > foo.should_receive(:bar).with(array_including(1,2,3)) > > The only problem with this is the name: array_including could mean different things (ordered/unordered, only these elements or subset, etc). The hash_including matcher is specifically about a subset of a hash. But perhaps we could extend this with something like you proposed above: > > foo.should_receive(:bar).with(array_including(1,2,3)) > foo.should_receive(:bar).with(array_including(1,2,3).ingoring_order) > foo.should_receive(:bar).with(array_including(1,2,3).only.ingoring_order) > > The thing is, I'm not sure this is any better than the example I gave above, which is very precise and works today. Thoughts/opinions welcome. > >> Hope someone can solve this for me - MUCH appreciation. > > > As an aside, when passing a hash as an argument you don't need to use curly braces, as long as the hash is the last argument to the method. These two are equivalent: > > expect_call(1, :a, {:some_key => 'some value'}) > expect_call(1, :a, :some_key => 'some value') > > HTH, > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at rapleaf.com Tue Feb 1 22:36:44 2011 From: james at rapleaf.com (James OBrien) Date: Tue, 1 Feb 2011 19:36:44 -0800 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: References: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> Message-ID: I don't fully understand this response.. The private method I mentioned was a helper created by me in test code on the example group. Still very interested On Feb 1, 2011 7:28 PM, "Julian Leviston" wrote: Does this strike anyone else as odd? Don't you think the test should actually be written IN to the code itself? I guess I'm soft of stipulating a new language here, but perhaps Ruby is flexible enough to enable this. Surely as the private methods of a class change, the testing code HAS to change... therefore isn't it best to actually write the rspec-level tests into the classes themselves as context-sensitive-optionally loaded or not depending on whether you're in testing mode or not Julian On 02/02/2011, at 4:01 AM, James OBrien wrote: > additionally, > > since my > > foo.should_recei... _______________________________________________ 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 julian at leviston.net Tue Feb 1 23:16:31 2011 From: julian at leviston.net (Julian Leviston) Date: Wed, 2 Feb 2011 15:16:31 +1100 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: References: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> Message-ID: <9DD42FA6-055E-4FD4-8F16-80A6A0741E32@leviston.net> Sorry it was a knee-jerk reaction that was prompted by what you wrote, but not necessarily even connected to it. Essentially, I've been wondering/thinking about this for a very long time (since about 15 years ago when I started writing smalltalk code). I think a general principle of code is that it should be specced from the inside out and simultaneously from the outside in. We have things like cucumber to generally spec from the outside in (ie define an interface according to the "user" what or whoever that may be), and we have things like rspec to spec from the inside out.... ...however inside-out specs should be built inline with the code they spec, surely? I mean, just like you *should* have comments and documentation built in, the spec should almost build a bridge from the documentation to the code... It seems rspec is incredibly close to this, much closer than cucumber is to be a very useable outside-in spec system. Essentially I'd stipulate a flow of development that went something like this: 1. Plan 2. Put Plan and Documentation in source code with placeholders 3. Build Spec 4. Build Code An architecture that, when bootstrapped, tests itself to make sure it's not borked before the code runs. (ie it does self-check on startup, essentially). Julian. On 02/02/2011, at 2:36 PM, James OBrien wrote: > I don't fully understand this response.. > > The private method I mentioned was a helper created by me in test code on the example group. > > Still very interested > > >> On Feb 1, 2011 7:28 PM, "Julian Leviston" wrote: >> >> Does this strike anyone else as odd? >> >> Don't you think the test should actually be written IN to the code itself? >> >> I guess I'm soft of stipulating a new language here, but perhaps Ruby is flexible enough to enable this. >> >> Surely as the private methods of a class change, the testing code HAS to change... therefore isn't it best to actually write the rspec-level tests into the classes themselves as context-sensitive-optionally loaded or not depending on whether you're in testing mode or not >> >> Julian >> >> >> >> On 02/02/2011, at 4:01 AM, James OBrien wrote: >> >> > additionally, >> > >> > since my >> > >> > foo.should_recei... >> >> >> _______________________________________________ >> 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 james at rapleaf.com Tue Feb 1 23:41:34 2011 From: james at rapleaf.com (James OBrien) Date: Tue, 1 Feb 2011 20:41:34 -0800 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: References: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> <9DD42FA6-055E-4FD4-8F16-80A6A0741E32@leviston.net> Message-ID: Sorry but I disagree. Specs should define only the external behavior of an object or service - allowing for confident implementation adjustments against a trusted suite of tests. What you're describing would make refactoring very hard. I think what you say goes against a lot of established theory and best practise. I would like to draw this back to the original question Take care James On Feb 1, 2011 8:16 PM, "Julian Leviston" wrote: Sorry it was a knee-jerk reaction that was prompted by what you wrote, but not necessarily even connected to it. Essentially, I've been wondering/thinking about this for a very long time (since about 15 years ago when I started writing smalltalk code). I think a general principle of code is that it should be specced from the inside out and simultaneously from the outside in. We have things like cucumber to generally spec from the outside in (ie define an interface according to the "user" what or whoever that may be), and we have things like rspec to spec from the inside out.... ...however inside-out specs should be built inline with the code they spec, surely? I mean, just like you *should* have comments and documentation built in, the spec should almost build a bridge from the documentation to the code... It seems rspec is incredibly close to this, much closer than cucumber is to be a very useable outside-in spec system. Essentially I'd stipulate a flow of development that went something like this: 1. Plan 2. Put Plan and Documentation in source code with placeholders 3. Build Spec 4. Build Code An architecture that, when bootstrapped, tests itself to make sure it's not borked before the code runs. (ie it does self-check on startup, essentially). Julian. On 02/02/2011, at 2:36 PM, James OBrien wrote: > I don't fully understand this response.. > > The... _______________________________________________ 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 win at wincent.com Tue Feb 1 23:47:13 2011 From: win at wincent.com (Wincent Colaiuta) Date: Wed, 2 Feb 2011 05:47:13 +0100 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: References: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> Message-ID: El 02/02/2011, a las 02:28, Julian Leviston escribi?: > Surely as the private methods of a class change, the testing code HAS to change... That statement sets off all sorts of alarm bells for me. In order for your specs to be non-brittle, they should be concerned with the externally-visible behavior of the code and not with the internal implementation details. For me, private methods fall under "internal implementation details". Being non-brittle and focussed on externally-visible behavior rather than implementation is a valuable attribute for a spec suite to have, because it allows us to refactor and improve the code with confidence that the behavior remains unchanged, but without having to engage in duplicative and error-prone updating of our specs to match the internal changes in implementation. So, if you're feeling the need to spec private methods, its an indication that you could be doing something better, because you're either: - specifying internal implementation details (and if that's the case, why are you specifying it?); or - you've made something private that shouldn't really be that way (and in that case, there are various refactorings you can use to restructure the code in order to make it more amenable to testing) Cheers, Wincent From james at rapleaf.com Wed Feb 2 00:36:43 2011 From: james at rapleaf.com (James OBrien) Date: Tue, 1 Feb 2011 21:36:43 -0800 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: References: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> Message-ID: I agree Vincent Can people however please use this trail to help me with my original query. I repeat the private method is declared on the test example group. This is not inside implemenraton code. On Feb 1, 2011 9:21 PM, "Wincent Colaiuta" wrote: El 02/02/2011, a las 02:28, Julian Leviston escribi?: > Surely as the private methods of a class change, the testing code HAS to change... That statement sets off all sorts of alarm bells for me. In order for your specs to be non-brittle, they should be concerned with the externally-visible behavior of the code and not with the internal implementation details. For me, private methods fall under "internal implementation details". Being non-brittle and focussed on externally-visible behavior rather than implementation is a valuable attribute for a spec suite to have, because it allows us to refactor and improve the code with confidence that the behavior remains unchanged, but without having to engage in duplicative and error-prone updating of our specs to match the internal changes in implementation. So, if you're feeling the need to spec private methods, its an indication that you could be doing something better, because you're either: - specifying internal implementation details (and if that's the case, why are you specifying it?); or - you've made something private that shouldn't really be that way (and in that case, there are various refactorings you can use to restructure the code in order to make it more amenable to testing) Cheers, Wincent _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org ... -------------- next part -------------- An HTML attachment was scrubbed... URL: From julian at leviston.net Wed Feb 2 00:39:31 2011 From: julian at leviston.net (Julian Leviston) Date: Wed, 2 Feb 2011 16:39:31 +1100 Subject: [rspec-users] array order-agnostic matching? In-Reply-To: References: <2970DB44-C62D-4F9C-929B-337867E2E13B@gmail.com> Message-ID: On 02/02/2011, at 3:47 PM, Wincent Colaiuta wrote: > El 02/02/2011, a las 02:28, Julian Leviston escribi?: > >> Surely as the private methods of a class change, the testing code HAS to change... > > That statement sets off all sorts of alarm bells for me. > > In order for your specs to be non-brittle, they should be concerned with the externally-visible behavior of the code and not with the internal implementation details. For me, private methods fall under "internal implementation details". > > Being non-brittle and focussed on externally-visible behavior rather than implementation is a valuable attribute for a spec suite to have, because it allows us to refactor and improve the code with confidence that the behavior remains unchanged, but without having to engage in duplicative and error-prone updating of our specs to match the internal changes in implementation. > > So, if you're feeling the need to spec private methods, its an indication that you could be doing something better, because you're either: > > - specifying internal implementation details (and if that's the case, why are you specifying it?); or > > - you've made something private that shouldn't really be that way (and in that case, there are various refactorings you can use to restructure the code in order to make it more amenable to testing) > > Cheers, > Wincent > That's hopefully already fairly obvious. Yes, I agree. Program to an interface. The idea is pretty much scope: ie, it depends what you're testing... it's the behaviour of the thing you're testing that is important... We have application-level scope ("behaviour testing"), class-level scope (testing that the class does what it's supposed to) and method-level scope dependant on what we're programming, right? If I'm programming a method, I want to test that it does certain things (preferably the things it's supposed to do, right? This is, after all, what a spec is....). Binding a set of components together to build an enclosing component, each component should have tests... including any enclosing components. Encapsulation of tests... :-) Julian. From rob.westgeest at gmail.com Wed Feb 2 09:42:50 2011 From: rob.westgeest at gmail.com (Rob Westgeest) Date: Wed, 2 Feb 2011 06:42:50 -0800 (PST) Subject: [rspec-users] [RAILS] [rspec 2.4.0] helper spec works but rails escapes all output Message-ID: <5be6a46a-281c-40e6-acf6-2c41a6afbc79@x17g2000yqa.googlegroups.com> Hi, rspec version: 2.4.0 Given this helper - snippet: ---- def participants_summary table table.participants.collect{|participant| show_short_participant_link(participant) }.join(', ') end def show_table_link(table) link_to(table.name, :action => :show, :id => table) end --- and this spec --- describe 'participants_summary' do let(:table) { new_table :participants => [ new_participant(:id=> 1, :name => 'name1'), new_participant(:id=> 2, :name => 'name2') ] } it "includes the names of all participants" do participants = participants_summary table participants.should include(link_to('name1', :controller=>'person',:action=>'show',:id=>1)) participants.should include(link_to('name2', :controller=>'person',:action=>'show',:id=>2)) end end --- The spec passes, but the real output is escaped. the helper should look like this ---- def participants_summary table raw table.participants.collect{|participant| show_short_participant_link(participant) }.join(', ') end --- I think (but i am not sure) that rspec should mimic Rails' behaviour in escaping all html from such helpers unless you put 'raw' in front. I can fix this in my case doing: render :text => participants_summary(table) rendered.should include(link_to('name1', :controller=.......etc This actually appears to use the rails3 rendering engine, or at least it fails if i remove the 'raw' call. Sadly, theconsequence of this is inserting something like this for not all but quite a few helpers. Does anybody know of another way of dealing with this. Do you think that this render => :text call should be (an implicitly or explicit) part of the HelperExampleGroup? I have put it in like this in one of my spec/support -ing files module HelperRenderer # renders the text as view so that rails view rendering magic # (like implicit HTML escaping) can take place def render_helper(text) render :text => text rendered end end module RSpec::Rails::HelperExampleGroup include HelperRenderer end From ks at cissor.com Wed Feb 2 12:31:29 2011 From: ks at cissor.com (Kurt) Date: Wed, 2 Feb 2011 09:31:29 -0800 (PST) Subject: [rspec-users] Notes on upgrading from RSpec 1 to RSpec 2 In-Reply-To: <768A406B-B5AF-441C-AA91-E4908C2E64C5@gmail.com> Message-ID: <30535730.365.1296667889996.JavaMail.geo-discussion-forums@prcm18> We haven't had the time to try to isolate the cause of the slowdown, but whatever the cause, it seems to be widespread as I have seen others reporting slowdowns of the same magnitude we have experienced. Our suite of 700 tests used to run in about 1 minute and on the same machine, with the minimal implementation and spec changes required to move to the newer versions, they now take about 3 minutes. What performance differences have you seen in the shift from RSpec1/Rails2 to RSpec2/Rails3? -------------- next part -------------- An HTML attachment was scrubbed... URL: From Rob.aldred at stardotstar.com Thu Feb 3 03:58:37 2011 From: Rob.aldred at stardotstar.com (Rob Aldred) Date: Thu, 3 Feb 2011 08:58:37 +0000 Subject: [rspec-users] [RAILS] [rspec 2.4.0] helper spec works but rails escapes all output In-Reply-To: <5be6a46a-281c-40e6-acf6-2c41a6afbc79@x17g2000yqa.googlegroups.com> References: <5be6a46a-281c-40e6-acf6-2c41a6afbc79@x17g2000yqa.googlegroups.com> Message-ID: <808016DC-16F9-42F1-81F7-2498EF249D04@stardotstar.com> Hi Since rails 3 all strings are escaped, unlike rails 2 where you had to use the h method use .html_safe in your helper method to stop the output escaping the test is correct This article will explain a little bit more http://markconnell.co.uk/posts/2010/02/rails-3-html-escaping -- Rob Aldred Software Developer rob at stardotstar.com twitter: stardotstar 47 Newton Street, Manchester, M1 1FT T: +44 (0) 161 236 9740 ___________________________________________________ This email and any files or ideas transmitted within it are sent in confidence and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager at info at stardotstar.com On 2 Feb 2011, at 14:42, Rob Westgeest wrote: > Hi, > > rspec version: 2.4.0 > > Given this helper - snippet: > ---- > def participants_summary table > table.participants.collect{|participant| > show_short_participant_link(participant) }.join(', ') > end > > def show_table_link(table) > link_to(table.name, :action => :show, :id => table) > end > --- > and this spec > --- > describe 'participants_summary' do > let(:table) { new_table :participants => [ > new_participant(:id=> 1, :name => > 'name1'), > new_participant(:id=> 2, :name => > 'name2') ] } > > it "includes the names of all participants" do > participants = participants_summary table > participants.should > include(link_to('name1', :controller=>'person',:action=>'show',:id=>1)) > participants.should > include(link_to('name2', :controller=>'person',:action=>'show',:id=>2)) > end > end > --- > > The spec passes, but the real output is escaped. > > the helper should look like this > ---- > def participants_summary table > raw table.participants.collect{|participant| > show_short_participant_link(participant) }.join(', ') > end > --- > > I think (but i am not sure) that rspec should mimic Rails' behaviour > in escaping all html from such helpers unless you put 'raw' in front. > > I can fix this in my case doing: > > render :text => participants_summary(table) > rendered.should include(link_to('name1', :controller=.......etc > > This actually appears to use the rails3 rendering engine, or at least > it fails if i remove the 'raw' call. > Sadly, theconsequence of this is inserting something like this for not > all but quite a few helpers. > > Does anybody know of another way of dealing with this. Do you think > that this render => :text call should be (an implicitly or explicit) > part of the HelperExampleGroup? > > I have put it in like this in one of my spec/support -ing files > > module HelperRenderer > # renders the text as view so that rails view rendering magic > # (like implicit HTML escaping) can take place > def render_helper(text) > render :text => text > rendered > end > end > > module RSpec::Rails::HelperExampleGroup > include HelperRenderer > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dk at structuralartistry.com Thu Feb 3 09:18:24 2011 From: dk at structuralartistry.com (David Kahn) Date: Thu, 3 Feb 2011 08:18:24 -0600 Subject: [rspec-users] Is there a way to tell rspec not to fail the test while in debugger? Message-ID: I am curious as with Test::Unit I could go into the debugger and stay all day inside of a test and make all kinds of errors without a problem. With rspec I experience that if I make a bad query/ActiveRecord call that it flips out and fails the test, throwing me back to the command prompt. This is normally not a problem but getting rather annoying right now as I am trying to work out some rather complex logic. Any ideas if there is a way to bypass this situation? For example: (rdb:1) TuRawBillDetail.includes(:account_subcode).select("DISTINCT account_product_id") INTERNAL ERROR!!! missing attribute: account_subcode_id /Users/DK/.rvm/gems/ruby-1.9.2-p136 at ncc_billing/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:324:in `block in preload_belongs_to_association' ... re/runner.rb:10:in `block in autorun'F............................. Failures: ... David -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott at railsnewbie.com Thu Feb 3 09:48:09 2011 From: scott at railsnewbie.com (Scott Taylor) Date: Thu, 3 Feb 2011 09:48:09 -0500 Subject: [rspec-users] Is there a way to tell rspec not to fail the test while in debugger? In-Reply-To: References: Message-ID: Probably manually rescuing your debugger call would work: begin debugger rescue Exception end Scott On Feb 3, 2011, at 9:18 AM, David Kahn wrote: > I am curious as with Test::Unit I could go into the debugger and stay all day inside of a test and make all kinds of errors without a problem. With rspec I experience that if I make a bad query/ActiveRecord call that it flips out and fails the test, throwing me back to the command prompt. This is normally not a problem but getting rather annoying right now as I am trying to work out some rather complex logic. Any ideas if there is a way to bypass this situation? > > For example: > > (rdb:1) TuRawBillDetail.includes(:account_subcode).select("DISTINCT account_product_id") > INTERNAL ERROR!!! missing attribute: account_subcode_id > /Users/DK/.rvm/gems/ruby-1.9.2-p136 at ncc_billing/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:324:in `block in preload_belongs_to_association' > ... > re/runner.rb:10:in `block in autorun'F............................. > > Failures: > ... > > > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dk at structuralartistry.com Thu Feb 3 10:28:08 2011 From: dk at structuralartistry.com (David Kahn) Date: Thu, 3 Feb 2011 09:28:08 -0600 Subject: [rspec-users] Is there a way to tell rspec not to fail the test while in debugger? In-Reply-To: References: Message-ID: On Thu, Feb 3, 2011 at 8:48 AM, Scott Taylor wrote: > > Probably manually rescuing your debugger call would work: > > begin > debugger > rescue Exception > end > Thanks, I just tried this but no go, the rspec still trips and fails me out. Maybe I have a really different methodology but I depend a lot on working stuff out in the debugger. > > Scott > > On Feb 3, 2011, at 9:18 AM, David Kahn wrote: > > > I am curious as with Test::Unit I could go into the debugger and stay all > day inside of a test and make all kinds of errors without a problem. With > rspec I experience that if I make a bad query/ActiveRecord call that it > flips out and fails the test, throwing me back to the command prompt. This > is normally not a problem but getting rather annoying right now as I am > trying to work out some rather complex logic. Any ideas if there is a way to > bypass this situation? > > > > For example: > > > > (rdb:1) TuRawBillDetail.includes(:account_subcode).select("DISTINCT > account_product_id") > > INTERNAL ERROR!!! missing attribute: account_subcode_id > > /Users/DK/.rvm/gems/ruby-1.9.2-p136 at ncc_billing/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:324:in > `block in preload_belongs_to_association' > > ... > > re/runner.rb:10:in `block in autorun'F............................. > > > > Failures: > > ... > > > > > > > > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Feb 3 11:32:34 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Feb 2011 10:32:34 -0600 Subject: [rspec-users] Is there a way to tell rspec not to fail the test while in debugger? In-Reply-To: References: Message-ID: On Feb 3, 2011, at 9:28 AM, David Kahn wrote: > On Thu, Feb 3, 2011 at 8:48 AM, Scott Taylor wrote: > > Probably manually rescuing your debugger call would work: > > begin > debugger > rescue Exception > end > > Thanks, I just tried this but no go, the rspec still trips and fails me out. Maybe I have a really different methodology but I depend a lot on working stuff out in the debugger. I actually do this sort of thing all the time, but I've never run into the problem you're talking about. The only thing I can think of is that there is a message expectation in the spec that you're triggering a failure on (they fail fast whenever they can). Are you setting any message expectations? Or using stubs of some kind? > > > Scott > > On Feb 3, 2011, at 9:18 AM, David Kahn wrote: > > > I am curious as with Test::Unit I could go into the debugger and stay all day inside of a test and make all kinds of errors without a problem. With rspec I experience that if I make a bad query/ActiveRecord call that it flips out and fails the test, throwing me back to the command prompt. This is normally not a problem but getting rather annoying right now as I am trying to work out some rather complex logic. Any ideas if there is a way to bypass this situation? > > > > For example: > > > > (rdb:1) TuRawBillDetail.includes(:account_subcode).select("DISTINCT account_product_id") > > INTERNAL ERROR!!! missing attribute: account_subcode_id > > /Users/DK/.rvm/gems/ruby-1.9.2-p136 at ncc_billing/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:324:in `block in preload_belongs_to_association' > > ... > > re/runner.rb:10:in `block in autorun'F............................. > > > > Failures: > > ... > > > > > > > > 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 > > _______________________________________________ > 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 dk at structuralartistry.com Thu Feb 3 12:04:16 2011 From: dk at structuralartistry.com (David Kahn) Date: Thu, 3 Feb 2011 11:04:16 -0600 Subject: [rspec-users] Is there a way to tell rspec not to fail the test while in debugger? In-Reply-To: References: Message-ID: On Thu, Feb 3, 2011 at 10:32 AM, David Chelimsky wrote: > On Feb 3, 2011, at 9:28 AM, David Kahn wrote: > > On Thu, Feb 3, 2011 at 8:48 AM, Scott Taylor wrote: > >> >> Probably manually rescuing your debugger call would work: >> >> begin >> debugger >> rescue Exception >> end >> > > Thanks, I just tried this but no go, the rspec still trips and fails me > out. Maybe I have a really different methodology but I depend a lot on > working stuff out in the debugger. > > > I actually do this sort of thing all the time, but I've never run into the > problem you're talking about. The only thing I can think of is that there is > a message expectation in the spec that you're triggering a failure on (they > fail fast whenever they can). Are you setting any message expectations? Or > using stubs of some kind? > No, at least nothing consciously as I am rather green overall at using rspec. This seems to be happening across projects --- I kind of took it for a necessary evil until now where it started eating into my time and patience. In fact the spec where this was happening was just a one-liner "Model.all.size.should == 3" or the like. This is my spec helper, if that helps: # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'paperclip/matchers' require Rails.root.join('db','seeds') # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| config.mock_with :rspec # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true config.include Paperclip::Shoulda::Matchers end > > > >> >> Scott >> >> On Feb 3, 2011, at 9:18 AM, David Kahn wrote: >> >> > I am curious as with Test::Unit I could go into the debugger and stay >> all day inside of a test and make all kinds of errors without a problem. >> With rspec I experience that if I make a bad query/ActiveRecord call that it >> flips out and fails the test, throwing me back to the command prompt. This >> is normally not a problem but getting rather annoying right now as I am >> trying to work out some rather complex logic. Any ideas if there is a way to >> bypass this situation? >> > >> > For example: >> > >> > (rdb:1) TuRawBillDetail.includes(:account_subcode).select("DISTINCT >> account_product_id") >> > INTERNAL ERROR!!! missing attribute: account_subcode_id >> > /Users/DK/.rvm/gems/ruby-1.9.2-p136 at ncc_billing/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:324:in >> `block in preload_belongs_to_association' >> > ... >> > re/runner.rb:10:in `block in autorun'F............................. >> > >> > Failures: >> > ... >> > >> > >> > >> > 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 >> > > _______________________________________________ > 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 dchelimsky at gmail.com Thu Feb 3 12:24:25 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Feb 2011 11:24:25 -0600 Subject: [rspec-users] Is there a way to tell rspec not to fail the test while in debugger? In-Reply-To: References: Message-ID: <6CF70107-ACD6-443A-8B2E-70926DEFC3BF@gmail.com> On Feb 3, 2011, at 11:04 AM, David Kahn wrote: > > > On Thu, Feb 3, 2011 at 10:32 AM, David Chelimsky wrote: > On Feb 3, 2011, at 9:28 AM, David Kahn wrote: > >> On Thu, Feb 3, 2011 at 8:48 AM, Scott Taylor wrote: >> >> Probably manually rescuing your debugger call would work: >> >> begin >> debugger >> rescue Exception >> end >> >> Thanks, I just tried this but no go, the rspec still trips and fails me out. Maybe I have a really different methodology but I depend a lot on working stuff out in the debugger. > > I actually do this sort of thing all the time, but I've never run into the problem you're talking about. The only thing I can think of is that there is a message expectation in the spec that you're triggering a failure on (they fail fast whenever they can). Are you setting any message expectations? Or using stubs of some kind? > > No, at least nothing consciously as I am rather green overall at using rspec. This seems to be happening across projects --- I kind of took it for a necessary evil until now where it started eating into my time and patience. In fact the spec where this was happening was just a one-liner "Model.all.size.should == 3" or the like. This is my spec helper, if that helps: > > # This file is copied to spec/ when you run 'rails generate rspec:install' > ENV["RAILS_ENV"] ||= 'test' > require File.expand_path("../../config/environment", __FILE__) > require 'rspec/rails' > require 'paperclip/matchers' > > require Rails.root.join('db','seeds') > > # Requires supporting ruby files with custom matchers and macros, etc, > # in spec/support/ and its subdirectories. > Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} > > RSpec.configure do |config| > config.mock_with :rspec > > # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures > config.fixture_path = "#{::Rails.root}/spec/fixtures" > > # If you're not using ActiveRecord, or you'd prefer not to run each of your > # examples within a transaction, remove the following line or assign false > # instead of true. > config.use_transactional_fixtures = true > > config.include Paperclip::Shoulda::Matchers > end Everything looks normal there. Have you tried the same with test/unit yet? If you haven't, please do create a test case that does exactly the same stuff and see if you can debug any differently. If that works, then at least you have a way to work through this in the short run, and we know something is up with rspec. If it doesn't work, then we know the problem is likely in some other part of the equation. > > >> >> >> Scott >> >> On Feb 3, 2011, at 9:18 AM, David Kahn wrote: >> >> > I am curious as with Test::Unit I could go into the debugger and stay all day inside of a test and make all kinds of errors without a problem. With rspec I experience that if I make a bad query/ActiveRecord call that it flips out and fails the test, throwing me back to the command prompt. This is normally not a problem but getting rather annoying right now as I am trying to work out some rather complex logic. Any ideas if there is a way to bypass this situation? >> > >> > For example: >> > >> > (rdb:1) TuRawBillDetail.includes(:account_subcode).select("DISTINCT account_product_id") >> > INTERNAL ERROR!!! missing attribute: account_subcode_id >> > /Users/DK/.rvm/gems/ruby-1.9.2-p136 at ncc_billing/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:324:in `block in preload_belongs_to_association' >> > ... >> > re/runner.rb:10:in `block in autorun'F............................. >> > >> > Failures: >> > ... >> > >> > >> > >> > 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 >> >> _______________________________________________ >> 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 > > _______________________________________________ > 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 scott at railsnewbie.com Thu Feb 3 12:27:30 2011 From: scott at railsnewbie.com (Scott Taylor) Date: Thu, 3 Feb 2011 12:27:30 -0500 Subject: [rspec-users] Is there a way to tell rspec not to fail the test while in debugger? In-Reply-To: References: Message-ID: On Feb 3, 2011, at 12:04 PM, David Kahn wrote: > > > On Thu, Feb 3, 2011 at 10:32 AM, David Chelimsky wrote: > On Feb 3, 2011, at 9:28 AM, David Kahn wrote: > >> On Thu, Feb 3, 2011 at 8:48 AM, Scott Taylor wrote: >> >> Probably manually rescuing your debugger call would work: >> >> begin >> debugger >> rescue Exception >> end >> >> Thanks, I just tried this but no go, the rspec still trips and fails me out. Maybe I have a really different methodology but I depend a lot on working stuff out in the debugger. I do the same. I've noticed that actually exiting out to irb will trip things up more often then simple 'p' / 'print' statements, so I try to stay out of irb. I've only really noticed the debugger itself crashing in rails projects - outside of rails, I've never had a problem. Maybe the ruby-debug / trepanning guys can help you out more (I suspect it's more of a debugger / integration issue with rails than an rspec one). Cheers, Scott > > I actually do this sort of thing all the time, but I've never run into the problem you're talking about. The only thing I can think of is that there is a message expectation in the spec that you're triggering a failure on (they fail fast whenever they can). Are you setting any message expectations? Or using stubs of some kind? > > No, at least nothing consciously as I am rather green overall at using rspec. This seems to be happening across projects --- I kind of took it for a necessary evil until now where it started eating into my time and patience. In fact the spec where this was happening was just a one-liner "Model.all.size.should == 3" or the like. This is my spec helper, if that helps: > > # This file is copied to spec/ when you run 'rails generate rspec:install' > ENV["RAILS_ENV"] ||= 'test' > require File.expand_path("../../config/environment", __FILE__) > require 'rspec/rails' > require 'paperclip/matchers' > > require Rails.root.join('db','seeds') > > # Requires supporting ruby files with custom matchers and macros, etc, > # in spec/support/ and its subdirectories. > Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} > > RSpec.configure do |config| > config.mock_with :rspec > > # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures > config.fixture_path = "#{::Rails.root}/spec/fixtures" > > # If you're not using ActiveRecord, or you'd prefer not to run each of your > # examples within a transaction, remove the following line or assign false > # instead of true. > config.use_transactional_fixtures = true > > config.include Paperclip::Shoulda::Matchers > end > > >> >> >> Scott >> >> On Feb 3, 2011, at 9:18 AM, David Kahn wrote: >> >> > I am curious as with Test::Unit I could go into the debugger and stay all day inside of a test and make all kinds of errors without a problem. With rspec I experience that if I make a bad query/ActiveRecord call that it flips out and fails the test, throwing me back to the command prompt. This is normally not a problem but getting rather annoying right now as I am trying to work out some rather complex logic. Any ideas if there is a way to bypass this situation? >> > >> > For example: >> > >> > (rdb:1) TuRawBillDetail.includes(:account_subcode).select("DISTINCT account_product_id") >> > INTERNAL ERROR!!! missing attribute: account_subcode_id >> > /Users/DK/.rvm/gems/ruby-1.9.2-p136 at ncc_billing/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:324:in `block in preload_belongs_to_association' >> > ... >> > re/runner.rb:10:in `block in autorun'F............................. >> > >> > Failures: >> > ... >> > >> > >> > >> > 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 >> >> _______________________________________________ >> 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 > > _______________________________________________ > 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 dk at structuralartistry.com Thu Feb 3 13:34:58 2011 From: dk at structuralartistry.com (David Kahn) Date: Thu, 3 Feb 2011 12:34:58 -0600 Subject: [rspec-users] Is there a way to tell rspec not to fail the test while in debugger? In-Reply-To: <6CF70107-ACD6-443A-8B2E-70926DEFC3BF@gmail.com> References: <6CF70107-ACD6-443A-8B2E-70926DEFC3BF@gmail.com> Message-ID: On Thu, Feb 3, 2011 at 11:24 AM, David Chelimsky wrote: > On Feb 3, 2011, at 11:04 AM, David Kahn wrote: > > > > On Thu, Feb 3, 2011 at 10:32 AM, David Chelimsky wrote: > >> On Feb 3, 2011, at 9:28 AM, David Kahn wrote: >> >> On Thu, Feb 3, 2011 at 8:48 AM, Scott Taylor wrote: >> >>> >>> Probably manually rescuing your debugger call would work: >>> >>> begin >>> debugger >>> rescue Exception >>> end >>> >> >> Thanks, I just tried this but no go, the rspec still trips and fails me >> out. Maybe I have a really different methodology but I depend a lot on >> working stuff out in the debugger. >> >> >> I actually do this sort of thing all the time, but I've never run into the >> problem you're talking about. The only thing I can think of is that there is >> a message expectation in the spec that you're triggering a failure on (they >> fail fast whenever they can). Are you setting any message expectations? Or >> using stubs of some kind? >> > > No, at least nothing consciously as I am rather green overall at using > rspec. This seems to be happening across projects --- I kind of took it for > a necessary evil until now where it started eating into my time and > patience. In fact the spec where this was happening was just a one-liner > "Model.all.size.should == 3" or the like. This is my spec helper, if that > helps: > > # This file is copied to spec/ when you run 'rails generate rspec:install' > ENV["RAILS_ENV"] ||= 'test' > require File.expand_path("../../config/environment", __FILE__) > require 'rspec/rails' > require 'paperclip/matchers' > > require Rails.root.join('db','seeds') > > # Requires supporting ruby files with custom matchers and macros, etc, > # in spec/support/ and its subdirectories. > Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} > > RSpec.configure do |config| > config.mock_with :rspec > > # Remove this line if you're not using ActiveRecord or ActiveRecord > fixtures > config.fixture_path = "#{::Rails.root}/spec/fixtures" > > # If you're not using ActiveRecord, or you'd prefer not to run each of > your > # examples within a transaction, remove the following line or assign > false > # instead of true. > config.use_transactional_fixtures = true > > config.include Paperclip::Shoulda::Matchers > end > > > Everything looks normal there. Have you tried the same with test/unit yet? > If you haven't, please do create a test case that does exactly the same > stuff and see if you can debug any differently. If that works, then at least > you have a way to work through this in the short run, and we know something > is up with rspec. If it doesn't work, then we know the problem is likely in > some other part of the equation. > Ok, so I tried in test unit. What I found was mixed. For example, the following line returned [] consistently in test::unit without crashing while in rspec I got a crash and 'INTERNAL ERROR!!! missing attribute: account_subcode_id' (this line has a flaw in association, which makes sense to me but not why it kills me in rspec but test unit takes it in stride... weird): TuRawBillDetail.includes(:account_subcode).select("DISTINCT account_product_id") Yet, this line (with a bad column) causes both rspec and test unit to crash right away: TuRawBillDetail.includes(:account_subcodes).select("DISTINCT accounproduct_id") > > > >> >> >> >>> >>> Scott >>> >>> On Feb 3, 2011, at 9:18 AM, David Kahn wrote: >>> >>> > I am curious as with Test::Unit I could go into the debugger and stay >>> all day inside of a test and make all kinds of errors without a problem. >>> With rspec I experience that if I make a bad query/ActiveRecord call that it >>> flips out and fails the test, throwing me back to the command prompt. This >>> is normally not a problem but getting rather annoying right now as I am >>> trying to work out some rather complex logic. Any ideas if there is a way to >>> bypass this situation? >>> > >>> > For example: >>> > >>> > (rdb:1) TuRawBillDetail.includes(:account_subcode).select("DISTINCT >>> account_product_id") >>> > INTERNAL ERROR!!! missing attribute: account_subcode_id >>> > /Users/DK/.rvm/gems/ruby-1.9.2-p136 at ncc_billing/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:324:in >>> `block in preload_belongs_to_association' >>> > ... >>> > re/runner.rb:10:in `block in autorun'F............................. >>> > >>> > Failures: >>> > ... >>> > >>> > >>> > >>> > 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 >>> >> >> _______________________________________________ >> 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 >> > > _______________________________________________ > 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 dk at structuralartistry.com Thu Feb 3 13:40:51 2011 From: dk at structuralartistry.com (David Kahn) Date: Thu, 3 Feb 2011 12:40:51 -0600 Subject: [rspec-users] Possible to ask rspec to show more code in the debugger? Message-ID: This came up from an other issue where I needed to go check something in test::unit. Immediately when I dropped into the debugger in test::unit I saw something I have been missing: test unit by default shows a number of lines of code. Is there a way to make the rspec debugger do this? I am not sure if it is just me, but seems to me that when I moved to rspec, certain things which seemed to be nice default behaviors in test::unit are no longer default. For example this issue, and also that it seems that rspec does not automatically 'set autoeval' when going into the debugger. Not deal breakers by any means but thought I would see if anyone else has the same comments. Loaded suite test/unit/random_test Started [4, 13] in test/unit/random_test.rb 4 5 def test_this_hahahah 6 a = 1 7 a += 1 8 debugger => 9 assert a == 2 10 end 11 12 13 end test/unit/random_test.rb:9 assert a == 2 (rdb:1) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.denatale at gmail.com Thu Feb 3 15:42:54 2011 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 3 Feb 2011 15:42:54 -0500 Subject: [rspec-users] Possible to ask rspec to show more code in the debugger? In-Reply-To: References: Message-ID: On Thu, Feb 3, 2011 at 1:40 PM, David Kahn wrote: > This came up from an other issue where I needed to go check something in > test::unit. Immediately when I dropped into the debugger in test::unit I saw > something I have been missing: test unit by default shows a number of lines > of code. Is there a way to make the rspec debugger do this? > > I am not sure if it is just me, but seems to me that when I moved to rspec, > certain things which seemed to be nice default behaviors in test::unit are > no longer default. For example this issue, and also that it seems that rspec > does not automatically 'set autoeval' when going into the debugger. Not deal > breakers by any means but thought I would see if anyone else has the same > comments. > > > Loaded suite test/unit/random_test > Started > [4, 13] in test/unit/random_test.rb > ?? 4 > ?? 5??? def test_this_hahahah > ?? 6????? a = 1 > ?? 7????? a += 1 > ?? 8????? debugger > => 9????? assert a == 2 > ?? 10??? end > ?? 11 > ?? 12 > ?? 13? end > test/unit/random_test.rb:9 > assert a == 2 > (rdb:1) both of these are set by the .rdebugrc file in your home directory set listsize 12 in that file should set the default number of lines for the list command to show, perhaps that file changed. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From adam.greene at gmail.com Fri Feb 4 00:50:15 2011 From: adam.greene at gmail.com (Adam Greene) Date: Thu, 3 Feb 2011 21:50:15 -0800 (PST) Subject: [rspec-users] autotest giving error when having shared example in specs In-Reply-To: <15BA55FF-3E43-4442-B3B1-B660DECFBFBC@gmail.com> References: <35f1161a-a48b-4cfa-bffc-701e13625a12@fl7g2000vbb.googlegroups.com> <53d2a6e9-4362-4121-82e4-e0453e7c2d50@w2g2000yqb.googlegroups.com> <15BA55FF-3E43-4442-B3B1-B660DECFBFBC@gmail.com> Message-ID: <20577278-9a04-40ef-8b51-6c691fb9dbdd@a28g2000prb.googlegroups.com> I believe this is caused by a bad example on https://github.com/rspec/rspec/wiki/autotest ,specifically under the section "Advanced autotest configuration". I ran into this exact same issue and it was solved by changing the example to use spec/**/*_spec.rb. I went ahead and took the liberty of updating the wiki page thanks, adam On Jan 21, 5:35?am, David Chelimsky wrote: > On Jan 21, 2011, at 4:57 AM, Rob Westgeest wrote: > > > > > > > On Nov 22 2010, 9:42 pm, LesFreeman wrote: > >> On Sep 28, 10:42 pm, Amiruddin Nagri wrote: > > >>> I am having asharedexample'allow authorized actions' for my Rails 3 RSpec > >>> 2.beta.20 application. Thesharedexamplelooks like > > >>> share_examples_for 'allow authorized actions' do > >>> ? ... > >>> end > > >>> Thissharedexampleis in file > >>> spec/controllers/support/authorization_shared_example.rb, which I am > >>> requiring in spec_helper.rb. I am also using autotest to give me quick > >>> feedback. Autotest is generating following command to run rspec > > >>> >>> ruby>/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/bin/rspec >>> to rails root>/spec/controllers/support/authorization_shared_example.rb > >>> > > >>> Since autotest is also including support file when running rspec, I am > >>> getting following errors with autotest > > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/shared_example_group.rb:43:in > >>> `ensure_shared_example_group_name_not_taken':Sharedexamplegroup'allow > >>> authorized actions'alreadyexists(ArgumentError) > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/shared_example_group.rb:6:in > >>> `share_examples_for' > >>> ? ? from > >>> /Users/arusarh/work/ece/carbonomist/spec/controllers/support/authorization_ shared_example.rb:1:in > >>> `' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:235:in > >>> `load' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:235:in > >>> `block in load' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:227:in > >>> `load_dependency' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:235:in > >>> `load' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/configuration.rb:302:in > >>> `block in load_spec_files' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/configuration.rb:302:in > >>> `map' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/configuration.rb:302:in > >>> `load_spec_files' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/command_line.rb:18:in > >>> `run' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/runner.rb:46:in > >>> `run_in_process' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/runner.rb:37:in > >>> `run' > >>> ? ? from > >>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/runner.rb:10:in > >>> `block in autorun' > > >>> Any ideas how to not make autotest includesharedexamplefiles loaded > >>> through command line, but only include files with pattern "*_spec.rb", or > >>> have anyone else facing same situation. > >> I too am having this error > > I am having the same problem. > > > Autotest with rspec seem to differ from rspecs rake task in which > > files to automatically require. > > > The rake task requires spec/**/*.spec > > Close, but not quite. The default pattern is spec/**/*_spec.rb. > > > Autotest rspec2 requires spec/**/* > > Again, this incorrect. Autotest fires off shell commands that include a list of files to load based on a set of mappings: if file x changes, run a command with file(s) y. > > In RSpec, those mappings are defined in Autotest::Rspec2, and they are set to include files that end with _spec.rb, with some additional constraints based on file naming conventions: a change to lib/foo/bar.rb tells RSpec to include spec/foo/bar_spec.rb. > > > As I am sharing example groups in their own files names > > (shared_*_examples.rb), and require them from *spec.rb files, rake > > works nicely and autotest fails because of its 'lets require > > everything' attitude. > > I'm not sure where that's coming from, but it's not default settings of rspec or autotest. What versions of rspec and autotest are you using? Is this a rails app? > > > > > I presume that there is a way to configure autotests require set, but > > i haven't found it yet. > > Autotest has a mapping mechanism that you can access in its initialize hook. Seehttp://blog.davidchelimsky.net/2008/01/15/rspec-1-1-2-and-zentest-3-8-0/for more on this. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From johnf at bitsbuilder.com Fri Feb 4 10:20:51 2011 From: johnf at bitsbuilder.com (John Feminella) Date: Fri, 4 Feb 2011 10:20:51 -0500 Subject: [rspec-users] `:example` and `:group` scope aliases Message-ID: As per a discussion on the mailing list [1], Evgeniy Dolzhenko suggested that if we were going to have aliases, it would be optimal to have a change that introduced the aliases of :example, and :group, to parallel the existing :suite alias. I've created a pull request that does this. It is here: https://github.com/rspec/rspec-core/pull/297 [1] http://groups.google.com/group/rspec/browse_thread/thread/26ea96043f46b3b6 ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ From lists at ruby-forum.com Sat Feb 5 22:30:11 2011 From: lists at ruby-forum.com (Sergey Qsut) Date: Sun, 06 Feb 2011 04:30:11 +0100 Subject: [rspec-users] Rspec test for correct file search Message-ID: Hi! I wrote a method to locate the file on a given within a directory, the name and line in it. How to test it? Tell me please, I have daily headache with this problem.. def search(dir,name,line) ... end -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Feb 6 01:18:30 2011 From: lists at ruby-forum.com (Peter Ehrlich) Date: Sun, 06 Feb 2011 07:18:30 +0100 Subject: [rspec-users] Controller Testing + Devise = boom (undefined @controller, request) Message-ID: <60dbe4760094c3c764db9bea58f3f9b4@ruby-forum.com> Here I am, trying to learn TDD and BDD. Getting start, most simple case, and the world is falling apart: My test code: it "should respond with success" do puts 'hi' # get :new # response.should be_success end My stack trace: $ rspec spec "controller: nil" F Failures: 1) VideosController new exposes request and response before and after the action Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `request' for nil:NilClass # /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing' # /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/devise-1.1.5/lib/devise/test_helpers.rb:20:in `initialize' # /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/devise-1.1.5/lib/devise/test_helpers.rb:60:in `new' # /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/devise-1.1.5/lib/devise/test_helpers.rb:60:in `warden' # /Users/peter/.rvm/gems/ruby-[/code] You'll notice it says controller: nil. I modified the devise helper, as such: class TestWarden < Warden::Proxy #:nodoc: attr_reader :controller def initialize(controller) @controller = controller manager = Warden::Manager.new(nil) do |config| config.merge! Devise.warden_config end p "controller: #{controller.inspect}" super(controller.request.env, manager) end Thanks for any help! --Peter -- Posted via http://www.ruby-forum.com/. From rich at gandalf.ws Sun Feb 6 10:59:48 2011 From: rich at gandalf.ws (Rich Price) Date: Sun, 06 Feb 2011 09:59:48 -0600 Subject: [rspec-users] Controller Testing + Devise = boom (undefined @controller, request) In-Reply-To: <60dbe4760094c3c764db9bea58f3f9b4@ruby-forum.com> References: <60dbe4760094c3c764db9bea58f3f9b4@ruby-forum.com> Message-ID: <4D4EC574.9040807@gandalf.ws> I am assuming that the get and response lines are not commented out in your actual test! Does your code consist ONLY of the lines below? I think you need to proceed the "it" line with a "describe" line. for example: describe "my test" do it "...." do *put other code here* end end On 02/06/2011 12:18 AM, Peter Ehrlich wrote: > Here I am, trying to learn TDD and BDD. Getting start, most simple > case, and the world is falling apart: > > My test code: > > it "should respond with success" do > puts 'hi' > # get :new > # response.should be_success > end > > > My stack trace: > $ rspec spec > "controller: nil" > F > > Failures: > > 1) VideosController new exposes request and response before and after > the action > Failure/Error: Unable to find matching line from backtrace > NoMethodError: > undefined method `request' for nil:NilClass > # > /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in > `method_missing' > # > /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/devise-1.1.5/lib/devise/test_helpers.rb:20:in > `initialize' > # > /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/devise-1.1.5/lib/devise/test_helpers.rb:60:in > `new' > # > /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/devise-1.1.5/lib/devise/test_helpers.rb:60:in > `warden' > # /Users/peter/.rvm/gems/ruby-[/code] > > You'll notice it says controller: nil. I modified the devise helper, as > such: > > class TestWarden< Warden::Proxy #:nodoc: > attr_reader :controller > > def initialize(controller) > @controller = controller > manager = Warden::Manager.new(nil) do |config| > config.merge! Devise.warden_config > end > p "controller: #{controller.inspect}" > super(controller.request.env, manager) > end > > Thanks for any help! > --Peter > From dchelimsky at gmail.com Sun Feb 6 11:17:24 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 6 Feb 2011 10:17:24 -0600 Subject: [rspec-users] rspec-2.5.0 is released! Message-ID: <06B18DC0-A99C-4AA9-8C81-6B5F74A493AC@gmail.com> RSpec-2.5.0 is released! This is a minor upgrade, and is fully backward compatible with rspec-2.4. It includes several bug fixes, enhancements, and one deprecation. See the changelog below for details. We had a little glitch publishing the docs to [http://relishapp.com/rspec](http://relishapp.com/rspec), so the 2.5 docs won't be up for another day or two, so I'll detail the noticable differences here (and on http://blog.davidchelimsky.net/2011/02/06/rspec-250-is-released/). ## Autotest/Bundler integration ### --skip-bundler RSpec's Autotest integration assumes that you want `bundle exec` in the shell command generated by Autotest if you have a `Gemfile`. This works fine for some situations, but not all, so we added an opt-out for rspec-2.5: autotest -- --skip-bundler Autotest ignores everything after the initial `--`, so RSpec's Autotest extension handles the `--skip-bundler` option. ### Autotest's bundler plugin Autotest ships with a plugin for bundler. Just add the following to a `.autotest` file in the project's root directory, or your home directory: require 'autotest/bundler' This prefixes the generated shell command with 'bundle exec'. ### Implicit detection of Gemfile is deprecated Given that Autotest has its own way of dealing with Bundler (see above), we deprecated the implicit assumption that `Gemfile` means "use bundler". You'll see a deprecation notice if you are relying on that, but it _still works_. It's just a deprecation warning. To silence the warning, either use the `--skip-bundler` option or Autotest's bundler plugin, described above. ## HTML Formatter The HTML formatter now has a set of checkboxes in the header that allow you to filter what you're looking at: ## to not, or not to not Are you the sort of person for whom "expect this block of code _to not_ raise an error" is like nails on chalkboard? If so, relief has arrived. You may now type either of the following, and RSpec will happily service you: expect { ... }.to_not raise_error expect { ... }.not_to raise_error ## Changelog ### rspec-core-2.5.0 [full changelog](http://github.com/rspec/rspec-core/compare/v2.4.0...v2.5.0) * Enhancements * Autotest::Rspec2 parses command line args passed to autotest after '--' * --skip-bundler option for autotest command * Autotest regexp fixes (Jon Rowe) * Add filters to html and textmate formatters (Daniel Quimper) * Explicit passing of block (need for JRuby 1.6) (John Firebaugh) * Bug fixes * fix dom IDs in HTML formatter (Brian Faherty) * fix bug with --drb + formatters when not running in drb * include --tag options in drb args (monocle) * fix regression so now SPEC_OPTS take precedence over CLI options again (Roman Chernyatchik) * only call its(:attribute) once (failing example from Brian Dunn) * fix bizarre bug where rspec would hang after `String.alias :to_int :to_i` (Damian Nurzynski) * Deprecations * implicit inclusion of 'bundle exec' when Gemfile present (use autotest's bundler plugin instead) ### rspec-expectations-2.5.0 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.4.0...v2.5.0) * Enhancements * `should exist` works with `exist?` or `exists?` (Myron Marston) * `expect { ... }.not_to do_something` (in addition to `to_not`) * Documentation * improved docs for `raise_error` matcher (James Almond) ### rspec-mocks-2.5.0 [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.4.0...v2.5.0) * Bug fixes * message expectation counts now work in combination with a stub (Damian Nurzynski) * fix failure message when message received with incorrect args (Josep M. Bach) ### rspec-rails-2.5.0 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.4.1...v2.5.0) * Enhancements * use `index_helper` instead of `table_name` when generating specs (Reza Primardiansyah) * Bug fixes * fixed bug in which `render_views` in a nested group set the value in its parent group. * only include MailerExampleGroup when it is defiend (Steve Sloan) * `mock_model.as_null_object.attribute.blank?` returns `false` (Randy Schmidt) * fix typo in request specs (Paco Guzman) From lists at ruby-forum.com Sun Feb 6 12:17:58 2011 From: lists at ruby-forum.com (Peter Ehrlich) Date: Sun, 06 Feb 2011 18:17:58 +0100 Subject: [rspec-users] Controller Testing + Devise = boom (undefined @controller, request) In-Reply-To: <60dbe4760094c3c764db9bea58f3f9b4@ruby-forum.com> References: <60dbe4760094c3c764db9bea58f3f9b4@ruby-forum.com> Message-ID: <5b93080f8602d2bf360d7b40a5ee8472@ruby-forum.com> My apologies! Yes, the describe is there. Here's the whole file, with some other commented code (tests, before block) removed: require 'spec_helper' describe 'VideosController' do describe 'new' do it "should respond with success" do puts 'hi' # get :new # response.should be_success end end end Really without understanding of what is going on under the hood.. :-/ -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Feb 6 12:27:57 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 6 Feb 2011 11:27:57 -0600 Subject: [rspec-users] rspec-core-2.5.1 is released! Message-ID: <3BA20519-42EB-49BE-A657-AFFFEF6FBA21@gmail.com> rspec-core-2.5.1 is released! [full changelog](http://github.com/rspec/rspec-core/compare/v2.5.0...v2.5.1) #### This release breaks compatibility with rspec/autotest/bundler integration, but does so in order to greatly simplify it. With the release of rspec-core-2.5.1, if you want the generated autotest command to include `bundle exec`, require Autotest's bundler plugin in a `.autotest` file in the project's root directory or in your home directory: require "autotest/bundler" Now you can just type 'autotest' on the commmand line and it will work as you expect. If you don't want 'bundle exec', there is nothing you have to do. From TTS at rainleader.com Wed Feb 2 19:24:10 2011 From: TTS at rainleader.com (Trenton Scott) Date: Wed, 2 Feb 2011 16:24:10 -0800 (PST) Subject: [rspec-users] Autotest Errors Message-ID: >From my Rails project directory in Terminal, I'm able to run 'bundle exec rspec spec/' and it works successfully. When I try and run 'autotest', however, I get the error(s) below. Note: my .autotest file has require 'autotest/growl' and require 'autotest/fsevent' in it and I have both installed. Here's the error (below), any thoughts? ==== Trenton-Scotts-MacBook-Air:sample_app TTS$ autotest loading autotest/rails_rspec2 style: RailsRspec2 -------------------------------------------------------------------------------- bundle exec /Users/TTS/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -S /Users/ TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.3.1/bin/rspec --tty '/ Users/TTS/Documents/Rails/sample_app/spec/controllers/ pages_controller_spec.rb' /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/rspec/ core/option_parser.rb:18:in `parse!': invalid option: --tty (OptionParser::InvalidOption) from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/ rspec/core/option_parser.rb:4:in `parse!' from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/ rspec/core/configuration_options.rb:64:in `parse_command_line_options' from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/ rspec/core/configuration_options.rb:46:in `parse_options' from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/ rspec/core/runner.rb:41:in `run' from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/ rspec/core/runner.rb:10:in `block in autorun' == From liststuff at gmail.com Fri Feb 4 04:30:36 2011 From: liststuff at gmail.com (Alan B) Date: Fri, 4 Feb 2011 01:30:36 -0800 (PST) Subject: [rspec-users] custom matchers for request specs Message-ID: Hi all, I'm trying to create a custom matcher that will visit a given path and check it's authenticated. Here's what I have so far (using rspec-rails and capybara): matcher :require_authentication do match do |path| visit path #page.current_path.should == sign_in_path page.current_path.should == '/sign_in' end end The above version works, but when using the commented out line I get: NameError: undefined local variable or method `sign_in_path' for # sign_in_path is one of the routes in my application and works fine inside a describe/it block. I don't understand why the matcher recognises visit() but not sign_in_path. any ideas? From martin.streicher at gmail.com Sat Feb 5 08:49:55 2011 From: martin.streicher at gmail.com (Martin Streicher) Date: Sat, 5 Feb 2011 05:49:55 -0800 (PST) Subject: [rspec-users] debugger in controller in rspec Message-ID: <51e83124-b309-4ae6-a01e-0f1e20b977a5@y36g2000pra.googlegroups.com> I placed a debugger statement in a controller being tested with rspec2 to catch what's going on, but the statement is ignored? Do I have to do anything special to get the debugger to stop in the controller under rspec? If I place the debugger statement in the spec, I get a break -- but I want the break in the controller itself. Ideas? From mikerin.slava at gmail.com Sat Feb 5 16:29:55 2011 From: mikerin.slava at gmail.com (slavix) Date: Sat, 5 Feb 2011 13:29:55 -0800 (PST) Subject: [rspec-users] routing error for a name-spaced nested controller Message-ID: <5fae0820-58af-4ba2-9bb8-1186b95ceacd@u11g2000prk.googlegroups.com> Struggling with nested routing and rspec... When I run spec/controllers/admin/website_users_controller_spec.rb describe Admin::WebsiteUsersController do ... get :index, :website => @website at this line I get: ActionController::RoutingError Exception: No route matches {:website=>#, :controller=>"admin/ website_users"} My routes.rb .. namespace :admin do resources :websites do resources :users, :controller => 'website_users' end end rake routes ... admin_website_users GET /admin/websites/:website_id/ users(.:format) {:action=>"index", :controller=>"admin/ website_users"} thanks for help! From mmazur at gmail.com Mon Feb 7 19:02:48 2011 From: mmazur at gmail.com (Mike Mazur) Date: Tue, 8 Feb 2011 08:02:48 +0800 Subject: [rspec-users] routing error for a name-spaced nested controller In-Reply-To: <5fae0820-58af-4ba2-9bb8-1186b95ceacd@u11g2000prk.googlegroups.com> References: <5fae0820-58af-4ba2-9bb8-1186b95ceacd@u11g2000prk.googlegroups.com> Message-ID: Hi, On Sun, Feb 6, 2011 at 05:29, slavix wrote: > Struggling with nested routing and rspec... > When I run spec/controllers/admin/website_users_controller_spec.rb > > describe Admin::WebsiteUsersController do > ... > get :index, :website => @website Does that need to be: get :index, :website => @website.to_param HTH, Mike From dchelimsky at gmail.com Mon Feb 7 19:12:00 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 7 Feb 2011 18:12:00 -0600 Subject: [rspec-users] Autotest Errors In-Reply-To: References: Message-ID: On Wed, Feb 2, 2011 at 6:24 PM, Trenton Scott wrote: > >From my Rails project directory in Terminal, I'm able to run 'bundle > exec rspec spec/' and it works successfully. When I try and run > 'autotest', however, I get the error(s) below. Note: my .autotest file > has require 'autotest/growl' and require 'autotest/fsevent' in it and > I have both installed. > > Here's the error (below), any thoughts? > > ==== > > Trenton-Scotts-MacBook-Air:sample_app TTS$ autotest > loading autotest/rails_rspec2 > style: RailsRspec2 > > > -------------------------------------------------------------------------------- > > > bundle exec /Users/TTS/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -S /Users/ ^^ bundle exec ^^ > TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.3.1/bin/rspec --tty '/ ^^ rspec-core-2.3.1 ^^ > Users/TTS/Documents/Rails/sample_app/spec/controllers/ > pages_controller_spec.rb' > /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/rspec/ > core/option_parser.rb:18:in `parse!': invalid option: --tty > (OptionParser::InvalidOption) > ? ? ? ?from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/ ^^ rspec-core-2.0.1 ^^ > rspec/core/option_parser.rb:4:in `parse!' > ? ? ? ?from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/ > rspec/core/configuration_options.rb:64:in `parse_command_line_options' > ? ? ? ?from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/ > rspec/core/configuration_options.rb:46:in `parse_options' > ? ? ? ?from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/ > rspec/core/runner.rb:41:in `run' > ? ? ? ?from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/ > rspec/core/runner.rb:10:in `block in autorun' The problem is that there are two different versions of rspec-core being loaded: 2.0.1 and 2.3.1. Autotest generates a command to run specs. In this case, the generated command starts with 'bundle exec', and it looks like the bundle is configured to load rspec-core-2.0.1. The autotest command that you are starting with is not prefixed with 'bundle exec', which means it's using whatever gems are available in the current shell environment, which includes rspec-core-2.3.1. Try running 'bundle exec autotest' instead of just 'autotest'. HTH, David From dolzenko at gmail.com Tue Feb 8 03:54:47 2011 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Tue, 08 Feb 2011 11:54:47 +0300 Subject: [rspec-users] debugger in controller in rspec In-Reply-To: <51e83124-b309-4ae6-a01e-0f1e20b977a5@y36g2000pra.googlegroups.com> References: <51e83124-b309-4ae6-a01e-0f1e20b977a5@y36g2000pra.googlegroups.com> Message-ID: <4D5104D7.3050704@gmail.com> Just tested the debugger statement from controller and it worked as it should I'm using the latest RSpec gems, have this in my Gemfile: group :development do platforms :mri_18 do gem "ruby-debug" end platforms :mri_19 do gem "ruby-debug19", :require => "ruby-debug" end end and run rspec with -d option. So you probably should supply us with your failing example. On 2/5/2011 4:49 PM, Martin Streicher wrote: > I placed a debugger statement in a controller being tested with rspec2 > to catch what's going on, but the statement is ignored? Do I have to > do anything special to get the debugger to stop in the controller > under rspec? If I place the debugger statement in the spec, I get a > break -- but I want the break in the controller itself. > > Ideas? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Tue Feb 8 05:14:16 2011 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 8 Feb 2011 10:14:16 +0000 Subject: [rspec-users] custom matchers for request specs In-Reply-To: References: Message-ID: <6E80EF5D-4B58-45A1-A968-E131F4EC741D@mattwynne.net> On 4 Feb 2011, at 09:30, Alan B wrote: > Hi all, I'm trying to create a custom matcher that will visit a given > path and check it's authenticated. > Here's what I have so far (using rspec-rails and capybara): > > matcher :require_authentication do > match do |path| > visit path > #page.current_path.should == sign_in_path > page.current_path.should == '/sign_in' > end > end > > The above version works, but when using the commented out line I get: > > NameError: > undefined local variable or method `sign_in_path' for > # > > sign_in_path is one of the routes in my application and works fine > inside a describe/it block. > I don't understand why the matcher recognises visit() but not > sign_in_path. I'm surprised either of them do. This DSL is just a factory method for a matcher class. Unless that matcher class includes Capybara and the Rails routing methods module (can't remember the name off-hand) you won't have access to either of these methods in the matcher. Look at the non-DSL way to create a matcher and this will make more sense. Also, you need to return true / false from #match, rather than using an assertion. cheers, Matt matt at mattwynne.net 07974 430184 From phillipkoebbe at gmail.com Tue Feb 8 07:13:22 2011 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Tue, 08 Feb 2011 06:13:22 -0600 Subject: [rspec-users] routing error for a name-spaced nested controller In-Reply-To: <5fae0820-58af-4ba2-9bb8-1186b95ceacd@u11g2000prk.googlegroups.com> References: <5fae0820-58af-4ba2-9bb8-1186b95ceacd@u11g2000prk.googlegroups.com> Message-ID: <4D513362.3080300@gmail.com> On 2011-02-05 3:29 PM, slavix wrote: > Struggling with nested routing and rspec... > When I run spec/controllers/admin/website_users_controller_spec.rb > > describe Admin::WebsiteUsersController do > ... > get :index, :website => @website > at this line I get: > > ActionController::RoutingError Exception: No route matches > {:website=>#, :controller=>"admin/ > website_users"} > > My routes.rb > .. > namespace :admin do > resources :websites do > resources :users, :controller => 'website_users' > end > end > > Just got up, so I may not be thinking clearly yet, but... If your users controller is nested inside a websites namespace, shouldn't the spec be describe Admin::Websites::UsersController Check the controller itself and make sure the describe matches the class name. Peace. Phillip From dchelimsky at gmail.com Tue Feb 8 07:58:03 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Feb 2011 06:58:03 -0600 Subject: [rspec-users] custom matchers for request specs In-Reply-To: <6E80EF5D-4B58-45A1-A968-E131F4EC741D@mattwynne.net> References: <6E80EF5D-4B58-45A1-A968-E131F4EC741D@mattwynne.net> Message-ID: On Feb 8, 2011, at 4:14 AM, Matt Wynne wrote: > > On 4 Feb 2011, at 09:30, Alan B wrote: > >> Hi all, I'm trying to create a custom matcher that will visit a given >> path and check it's authenticated. >> Here's what I have so far (using rspec-rails and capybara): >> >> matcher :require_authentication do >> match do |path| >> visit path >> #page.current_path.should == sign_in_path >> page.current_path.should == '/sign_in' >> end >> end >> >> The above version works, but when using the commented out line I get: >> >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> >> sign_in_path is one of the routes in my application and works fine >> inside a describe/it block. >> I don't understand why the matcher recognises visit() but not >> sign_in_path. > > I'm surprised either of them do. Actually, I'm not, but that's because I know something that you don't know (because I wrote it and it's not well documented): A matcher created using the Matcher DSL is provided access to the example it is running in. When it receives method_missing, it asks the example if _it_ will respond to the message and, if so, sends it to the example. If visit() is defined in the scope of the example using "def visit", then example.respond_to?(:visit) would return true, so the matcher would send visit() to the example. If, however, sign_in_path() is handled with method_missing(), but respond_to?() is not also overridden to return true for respond_to?(:sign_in_path), then the matcher would call super from method_missing, raising the NameError. You can test this theory out by putting the following in the same example before the matcher: self.should respond_to(:visit) self.should respond_to(:sign_in_path) If my guess is correct, the former will pass, but the latter will fail. If they both pass, then I'm not sure about the explanation. HTH, David > This DSL is just a factory method for a matcher class. Unless that matcher class includes Capybara and the Rails routing methods module (can't remember the name off-hand) you won't have access to either of these methods in the matcher. Look at the non-DSL way to create a matcher and this will make more sense. > > Also, you need to return true / false from #match, rather than using an assertion. > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From lists at ruby-forum.com Tue Feb 8 12:25:30 2011 From: lists at ruby-forum.com (The Ultimation) Date: Tue, 08 Feb 2011 18:25:30 +0100 Subject: [rspec-users] Model validation failing in rspec for unknown reason Message-ID: <5eb72198e716f44fecf484f4ecf2864e@ruby-forum.com> Hi, i'm getting the following error when running a spec on my controller for my Equipment model. it "edit action should render edit template" do get :edit, :id => Factory(:equipment) response.should render_template(:edit) end Failure/Error: get :edit, :id => Factory(:equipment) ActiveRecord::RecordInvalid: Validation failed: The test is very simple, it builds an Equipment factory and tests to see if the edit template loads. This test works for every other model, and I tried removing all validations from this model but still no luck. Everything works on the webpage, just not in this test. I even created the factory successfully in command line without error. I'm just stumped as to what's going on. When i use --backtrace, it doesn't really shed any light either. It's just not saving because of an unknown validation failure. The only thing I can think of that might be causing an issue is an inflection that i use for this model. Here it is: ActiveSupport::Inflector.inflections do |inflect| inflect.irregular 'equipment', 'equipments' end Any help would be greatly appreciated. Thanks! -- Posted via http://www.ruby-forum.com/. From celoserpa at gmail.com Tue Feb 8 12:49:34 2011 From: celoserpa at gmail.com (Marcelo de Moraes Serpa) Date: Tue, 8 Feb 2011 11:49:34 -0600 Subject: [rspec-users] Why use DatabaseCleaner with rSpec? Message-ID: Hi list, I've used DatabaseCleaner in the past, but only when using Cucumber and Selenium (or Steak + Celerity) since turning on transactional_fixtures would prevent the data being accessible from app-server that is also triggered for the tests. This works fine, and is a de-facto solution for this problem. I don't see why I would want to use DatabaseCleaner with rspec though, since everything is in the same process, transactional_fixtures could do fine, in theory. Or not? Marcelo. From ben at benmabey.com Tue Feb 8 13:25:23 2011 From: ben at benmabey.com (Ben Mabey) Date: Tue, 08 Feb 2011 11:25:23 -0700 Subject: [rspec-users] Why use DatabaseCleaner with rSpec? In-Reply-To: References: Message-ID: <4D518A93.1020000@benmabey.com> On 2/8/11 10:49 AM, Marcelo de Moraes Serpa wrote: > Hi list, > > I've used DatabaseCleaner in the past, but only when using Cucumber > and Selenium (or Steak + Celerity) since turning on > transactional_fixtures would prevent the data being accessible from > app-server that is also triggered for the tests. This works fine, and > is a de-facto solution for this problem. > > I don't see why I would want to use DatabaseCleaner with rspec though, > since everything is in the same process, transactional_fixtures could > do fine, in theory. Or not? > > Marcelo. If you are using RSpec with Rails and have a *single* ActiveRecord connection for your app then you do not need to use DatabaseCleaner and the built in transactional_fixtures method will do just great. Once you need to either a) use a non-AR DB (e.g. mongodb, couchdb) b) have an out of process testing scenario (e.g. selenium) c) clean multiple connections (with an ActiveRecord DB or otherwise) or d) are not testing a Rails app (where the transactional_fixtures come from) then using DatabaseCleaner will make your life easier. HTH, Ben From nick at deadorange.com Tue Feb 8 14:04:40 2011 From: nick at deadorange.com (Nick) Date: Tue, 8 Feb 2011 11:04:40 -0800 (PST) Subject: [rspec-users] Model validation failing in rspec for unknown reason In-Reply-To: <5eb72198e716f44fecf484f4ecf2864e@ruby-forum.com> Message-ID: <15439656.426.1297191880337.JavaMail.geo-discussion-forums@yqeq15> On Tuesday, February 8, 2011 12:25:30 PM UTC-5, The Ultimation wrote: > > Hi, i'm getting the following error when running a spec on my controller > for my Equipment model. > > it "edit action should render edit template" do > get :edit, :id => Factory(:equipment) > Shouldn't you pass an ID to the "id" key, rather than a model instance? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Feb 8 14:17:49 2011 From: lists at ruby-forum.com (The Ultimation) Date: Tue, 08 Feb 2011 20:17:49 +0100 Subject: [rspec-users] Model validation failing in rspec for unknown reason In-Reply-To: <15439656.426.1297191880337.JavaMail.geo-discussion-forums@yqeq15> References: <5eb72198e716f44fecf484f4ecf2864e@ruby-forum.com> <15439656.426.1297191880337.JavaMail.geo-discussion-forums@yqeq15> Message-ID: <33d229e7b24d46b44de4ff60719f529c@ruby-forum.com> Nick Hoffman wrote in post #980380: > On Tuesday, February 8, 2011 12:25:30 PM UTC-5, The Ultimation wrote: >> >> Hi, i'm getting the following error when running a spec on my controller >> for my Equipment model. >> >> it "edit action should render edit template" do >> get :edit, :id => Factory(:equipment) >> > Shouldn't you pass an ID to the "id" key, rather than a model instance? I've tried every method of passing the id in, still same error :/ -- Posted via http://www.ruby-forum.com/. From dk at structuralartistry.com Tue Feb 8 19:43:39 2011 From: dk at structuralartistry.com (David Kahn) Date: Tue, 8 Feb 2011 18:43:39 -0600 Subject: [rspec-users] Possible to ask rspec to show more code in the debugger? In-Reply-To: References: Message-ID: On Thu, Feb 3, 2011 at 2:42 PM, Rick DeNatale wrote: > On Thu, Feb 3, 2011 at 1:40 PM, David Kahn > wrote: > > This came up from an other issue where I needed to go check something in > > test::unit. Immediately when I dropped into the debugger in test::unit I > saw > > something I have been missing: test unit by default shows a number of > lines > > of code. Is there a way to make the rspec debugger do this? > > > > I am not sure if it is just me, but seems to me that when I moved to > rspec, > > certain things which seemed to be nice default behaviors in test::unit > are > > no longer default. For example this issue, and also that it seems that > rspec > > does not automatically 'set autoeval' when going into the debugger. Not > deal > > breakers by any means but thought I would see if anyone else has the same > > comments. > > > > > > Loaded suite test/unit/random_test > > Started > > [4, 13] in test/unit/random_test.rb > > 4 > > 5 def test_this_hahahah > > 6 a = 1 > > 7 a += 1 > > 8 debugger > > => 9 assert a == 2 > > 10 end > > 11 > > 12 > > 13 end > > test/unit/random_test.rb:9 > > assert a == 2 > > (rdb:1) > > both of these are set by the .rdebugrc file in your home directory > > set listsize 12 > > in that file should set the default number of lines for the list > command to show, > > perhaps that file changed. > Thanks Rick... I just tried this but does not seem to work... closed and re-opened the terminal, but get same output --- this is my file: set autoeval set listsize 12 Any other ideas?... I'd love to get this working > > -- > Rick DeNatale > > Blog: http://talklikeaduck.denhaven2.com/ > Github: http://github.com/rubyredrick > Twitter: @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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ks at cissor.com Tue Feb 8 20:32:24 2011 From: ks at cissor.com (Kurt) Date: Tue, 8 Feb 2011 17:32:24 -0800 (PST) Subject: [rspec-users] Rails 3 / RSpec 2 use_transactional_fixtures and after_commit In-Reply-To: Message-ID: <32804128.509.1297215144162.JavaMail.geo-discussion-forums@prfp36> We're just running into it now, but we're using after_commit in Rails 3 for the first time. The callback appears not to fire in our specs -- I noticed your posting but have not had luck getting the gem to load. Bundler 1.0.7 requires the gem, and it generates this: /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02 at rails3/gems/after_commit-1.0.7/lib/after_commit/active_record.rb:15:in `include_after_commit_extensions': undefined method `subclasses_of' for Object:Class (NoMethodError) from /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02 at rails3/gems/after_commit-1.0.7/lib/after_commit.rb:81 Did you add these two lines to your spec_helper.rb file or somewhere else? ActiveRecord::Base.send(:include, AfterCommit::AfterSavepoint) ActiveRecord::Base.include_after_savepoint_extensions I'd be interested in helping to get this to work, but not sure where to start as we're new to after_commit. -------------- next part -------------- An HTML attachment was scrubbed... URL: From coreyhaines at gmail.com Tue Feb 8 20:49:51 2011 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 8 Feb 2011 19:49:51 -0600 Subject: [rspec-users] Excluding a spec subdirectory from rake spec Message-ID: I have a directory in my spec directory that I want to exclude from rake spec That is, I have spec/lib_no_rails And I don't want it to run when I do rake spec Best way? Thanks. -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines From jko170 at gmail.com Tue Feb 8 21:32:26 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 8 Feb 2011 18:32:26 -0800 (PST) Subject: [rspec-users] Excluding a spec subdirectory from rake spec In-Reply-To: References: Message-ID: <40f49a5a-0a21-417c-a1b7-7b4b929452e9@v7g2000yqh.googlegroups.com> On Feb 8, 6:49?pm, Corey Haines wrote: > I have a directory in my spec directory that I want to exclude from rake spec > > That is, I have > spec/lib_no_rails > > And I don't want it to run when I do rake spec > > Best way? > > Thanks. > -Corey > > --http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users Is it for specs that make live api calls? Here is an alternative to have a "remote" directory: https://gist.github.com/812278 From lists at ruby-forum.com Wed Feb 9 03:08:58 2011 From: lists at ruby-forum.com (Alex H.) Date: Wed, 09 Feb 2011 09:08:58 +0100 Subject: [rspec-users] cucumber generator error in rails 3 In-Reply-To: References: Message-ID: <1ae7859d00af64d7d0f4770607c7431a@ruby-forum.com> I also get this error, after I run "rails generate cucumber:install # Rails 3". My target is that let Cucumber-Rails add a few files to your project. I am following the guid of https://github.com/aslakhellesoy/cucumber/wiki/Ruby-on-Rails I run bundle install. Out put as following: Using rake (0.8.7) Using abstract (1.0.0) Using activesupport (3.0.3) Using builder (2.1.2) Using i18n (0.5.0) Using activemodel (3.0.3) Using erubis (2.6.6) Using rack (1.2.1) Using rack-mount (0.6.13) Using rack-test (0.5.7) Using tzinfo (0.3.24) Using actionpack (3.0.3) Using mime-types (1.16) Using polyglot (0.3.1) Using treetop (1.4.9) Using mail (2.2.15) Using actionmailer (3.0.3) Using arel (2.0.7) Using activerecord (3.0.3) Using activeresource (3.0.3) Using bundler (1.0.9) Using mysql2 (0.2.6) Using thor (0.14.6) Using railties (3.0.3) Using rails (3.0.3) Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. PS: OS is Window7, My project is Rails for jRuby project. -- Posted via http://www.ruby-forum.com/. From mguterl at gmail.com Wed Feb 9 08:46:19 2011 From: mguterl at gmail.com (Michael Guterl) Date: Wed, 9 Feb 2011 08:46:19 -0500 Subject: [rspec-users] Rails 3 / RSpec 2 use_transactional_fixtures and after_commit In-Reply-To: <32804128.509.1297215144162.JavaMail.geo-discussion-forums@prfp36> References: <32804128.509.1297215144162.JavaMail.geo-discussion-forums@prfp36> Message-ID: Hi Kurt, On Tue, Feb 8, 2011 at 8:32 PM, Kurt wrote: > We're just running into it now, but we're using after_commit in Rails 3 for > the first time.? The callback appears not to fire in our specs -- I noticed > your posting but have not had luck getting the gem to load.? Bundler 1.0.7 > requires the gem, and it generates this: > > /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02 at rails3/gems/after_commit-1.0.7/lib/after_commit/active_record.rb:15:in > `include_after_commit_extensions': undefined method `subclasses_of' for > Object:Class (NoMethodError) > ??? from > /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02 at rails3/gems/after_commit-1.0.7/lib/after_commit.rb:81 > > Did you add these two lines to your spec_helper.rb file or somewhere else? > > ActiveRecord::Base.send(:include, AfterCommit::AfterSavepoint) > ActiveRecord::Base.include_after_savepoint_extensions > > I'd be interested in helping to get this to work, but not sure where to > start as we're new to after_commit. > after_commit is built-in to Rails 3, so you don't need the gem. Rails 3 does not include any type of AfterSavepoint helper for running with transactional fixtures turned on. That is the piece that needs to be ported over to Rails 3. Best, Michael Guterl From ks at cissor.com Wed Feb 9 13:10:48 2011 From: ks at cissor.com (Kurt) Date: Wed, 9 Feb 2011 10:10:48 -0800 (PST) Subject: [rspec-users] Rails 3 / RSpec 2 use_transactional_fixtures and after_commit In-Reply-To: Message-ID: <22956121.767.1297275048794.JavaMail.geo-discussion-forums@prfp36> Thanks -- that confirms the results of our experiments. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Feb 10 07:49:26 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Feb 2011 06:49:26 -0600 Subject: [rspec-users] Opinions sought on feature/pull request Message-ID: Hey all, Looking for thoughts on a feature/pull request: https://github.com/rspec/rspec-core/pull/306. Cheers, David From frederick.cheung at gmail.com Thu Feb 10 13:40:25 2011 From: frederick.cheung at gmail.com (Frederick Cheung) Date: Thu, 10 Feb 2011 18:40:25 +0000 Subject: [rspec-users] hash form of stub_chain returning nil for chains with shared first message Message-ID: <4AA94B44-94C3-4B2E-AD2E-D47196B31187@gmail.com> I'm new using rspec, so please forgive me if I'm barking up the wrong tree, but... I'd expect this to pass (using rspec 2.5.1) describe 'stub_chain' do it "returns expected value from two chains with hash" do subject = Object.new subject.stub_chain(:msg1, :msg2 => :first) subject.stub_chain(:msg1, :msg3 => :second) subject.msg1.msg2.should equal(:first) subject.msg1.msg3.should equal(:second) end end But it doesn't - subject.msg1.msg3 returns nil I think this is because in stub_chain (in rspec-mocks/lib/rspec/mocks/methods.rb, line 43) there is if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, chain[0].to_sym) chain.shift matching_stub.invoke.stub_chain(*chain) else ie blk isn't used in any way. Changing this to matching_stub.invoke.stub_chain(*chain, &blk) makes my example pass Is this true or am I just misusing rspec? Fred From dchelimsky at gmail.com Thu Feb 10 14:30:50 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Feb 2011 13:30:50 -0600 Subject: [rspec-users] hash form of stub_chain returning nil for chains with shared first message In-Reply-To: <4AA94B44-94C3-4B2E-AD2E-D47196B31187@gmail.com> References: <4AA94B44-94C3-4B2E-AD2E-D47196B31187@gmail.com> Message-ID: <798774CD-7291-46E1-81EE-4188A878AF22@gmail.com> On Feb 10, 2011, at 12:40 PM, Frederick Cheung wrote: > I'm new using rspec, so please forgive me if I'm barking up the wrong tree, but... > > I'd expect this to pass (using rspec 2.5.1) > > describe 'stub_chain' do > it "returns expected value from two chains with hash" do > subject = Object.new > subject.stub_chain(:msg1, :msg2 => :first) > subject.stub_chain(:msg1, :msg3 => :second) This ^^ is not documented to work. See http://relishapp.com/rspec/rspec-mocks/v/2-5/dir/method-stubs/stub-a-chain-of-methods. Try: subject.stub_chain(:msg1, :msg2).and_return(:first) If that works, feel free to submit a feature request to support the format you were using. Cheers, David > subject.msg1.msg2.should equal(:first) > subject.msg1.msg3.should equal(:second) > end > end > > But it doesn't - subject.msg1.msg3 returns nil > > I think this is because in stub_chain (in rspec-mocks/lib/rspec/mocks/methods.rb, line 43) there is > > if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, chain[0].to_sym) > chain.shift > matching_stub.invoke.stub_chain(*chain) > else > > ie blk isn't used in any way. Changing this to matching_stub.invoke.stub_chain(*chain, &blk) makes my example pass > Is this true or am I just misusing rspec? > > Fred > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jimmymartin at gmail.com Thu Feb 10 19:29:04 2011 From: jimmymartin at gmail.com (James Martin) Date: Fri, 11 Feb 2011 11:29:04 +1100 Subject: [rspec-users] Pull requests via Github - To Fork or Not? That is the Question. Message-ID: Hi, I've been coming up with some documentation examples, which I'd like to contribute as Cucumber features to go into the relishapp. I started following the contribute instructions on the rspec-dev README[1] but have a question about pull requests. Should I clone from the rspec/* projects on github, or fork them all and then setup my local development environment from my own forks? If the preferred method is to clone from the official rspec/*?repos then it presumably wouldn't be possible to submit pull requests. Thanks, James. [1]?https://github.com/rspec/rspec-dev/blob/master/README.markdown From dchelimsky at gmail.com Thu Feb 10 21:05:19 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Feb 2011 20:05:19 -0600 Subject: [rspec-users] Pull requests via Github - To Fork or Not? That is the Question. In-Reply-To: References: Message-ID: <98C56EFD-BCB5-49F4-A09B-FA2B5A28552E@gmail.com> On Feb 10, 2011, at 6:29 PM, James Martin wrote: > Hi, > > I've been coming up with some documentation examples, which I'd like > to contribute as Cucumber features to go into the relishapp. > > I started following the contribute instructions on the rspec-dev > README[1] but have a question about pull requests. > > Should I clone from the rspec/* projects on github, or fork them all > and then setup my local development environment from my own forks? > > If the preferred method is to clone from the official rspec/* repos > then it presumably wouldn't be possible to submit pull requests. Do whichever is easiest for you. You can follow the directions in the readme and then fork the repos and point your local repos at your fork instead of rspec's repo. Assuming, for example, your github account is jmartin: # in rspec-core git remote rm origin git remote add origin https://github.com/jamesmartin/rspec-core.git Make sense? Looking forward to your contributions. Thanks! Cheers, David > > [1] https://github.com/rspec/rspec-dev/blob/master/README.markdown > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmymartin at gmail.com Thu Feb 10 22:01:47 2011 From: jimmymartin at gmail.com (James Martin) Date: Fri, 11 Feb 2011 14:01:47 +1100 Subject: [rspec-users] Pull requests via Github - To Fork or Not? That is the Question. In-Reply-To: <98C56EFD-BCB5-49F4-A09B-FA2B5A28552E@gmail.com> References: <98C56EFD-BCB5-49F4-A09B-FA2B5A28552E@gmail.com> Message-ID: Thanks, David. That makes perfect sense. James. On Fri, Feb 11, 2011 at 1:05 PM, David Chelimsky wrote: > On Feb 10, 2011, at 6:29 PM, James Martin wrote: > > Hi, > > I've been coming up with some documentation examples, which I'd like > to contribute as Cucumber features to go into the relishapp. > > I started following the contribute instructions on the rspec-dev > README[1] but have a question about pull requests. > > Should I clone from the rspec/* projects on github, or fork them all > and then setup my local development environment from my own forks? > > If the preferred method is to clone from the official rspec/*?repos > then it presumably wouldn't be possible to submit pull requests. > > Do whichever is easiest for you. You can follow the directions in the readme > and then fork the repos and point your local repos at your fork instead of > rspec's repo. Assuming, for example, your github account is jmartin: > # in rspec-core > git remote rm origin > git remote add origin https://github.com/jamesmartin/rspec-core.git > Make sense? > Looking forward to your contributions. Thanks! > Cheers, > David > > [1]?https://github.com/rspec/rspec-dev/blob/master/README.markdown > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Thu Feb 10 22:56:57 2011 From: coreyhaines at gmail.com (Corey Haines) Date: Thu, 10 Feb 2011 21:56:57 -0600 Subject: [rspec-users] Excluding a spec subdirectory from rake spec Message-ID: > > Message: 3 > Date: Tue, 8 Feb 2011 18:32:26 -0800 (PST) > From: Justin Ko > To: rspec-users at rubyforge.org > Subject: Re: [rspec-users] Excluding a spec subdirectory from rake > ? ? ? ?spec > Message-ID: > ? ? ? ?<40f49a5a-0a21-417c-a1b7-7b4b929452e9 at v7g2000yqh.googlegroups.com> > Content-Type: text/plain; charset=ISO-8859-1 > > > > On Feb 8, 6:49?pm, Corey Haines wrote: >> I have a directory in my spec directory that I want to exclude from rake spec >> >> That is, I have >> spec/lib_no_rails >> >> And I don't want it to run when I do rake spec >> >> Best way? >> >> Thanks. >> -Corey >> >> --http://www.coreyhaines.com >> The Internet's Premiere source of information about Corey Haines >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > Is it for specs that make live api calls? Here is an alternative to > have a "remote" directory: https://gist.github.com/812278 > > No, it is a directory that I want to run without loading rails. It has its own spec_helper. -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines From jko170 at gmail.com Fri Feb 11 00:27:54 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 10 Feb 2011 21:27:54 -0800 (PST) Subject: [rspec-users] Excluding a spec subdirectory from rake spec In-Reply-To: References: Message-ID: On Feb 10, 8:56?pm, Corey Haines wrote: > > Message: 3 > > Date: Tue, 8 Feb 2011 18:32:26 -0800 (PST) > > From: Justin Ko > > To: rspec-us... at rubyforge.org > > Subject: Re: [rspec-users] Excluding a spec subdirectory from rake > > ? ? ? ?spec > > Message-ID: > > ? ? ? ?<40f49a5a-0a21-417c-a1b7-7b4b92945... at v7g2000yqh.googlegroups.com> > > Content-Type: text/plain; charset=ISO-8859-1 > > > On Feb 8, 6:49?pm, Corey Haines wrote: > >> I have a directory in my spec directory that I want to exclude from rake spec > > >> That is, I have > >> spec/lib_no_rails > > >> And I don't want it to run when I do rake spec > > >> Best way? > > >> Thanks. > >> -Corey > > >> --http://www.coreyhaines.com > >> The Internet's Premiere source of information about Corey Haines > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > Is it for specs that make live api calls? Here is an alternative to > > have a "remote" directory:https://gist.github.com/812278 > > No, it is a directory that I want to run without loading rails. It has > its own spec_helper. > > -Corey > > --http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users In that case, instead of overriding the default "spec" rake task, and it has its own spec_helper, I would put it in its own top-level directory. It would also have a Gemfile to load RSpec. Here is an example, you can see the "spec_rails" directory: https://github.com/justinko/diagnostics From frederick.cheung at gmail.com Fri Feb 11 04:51:13 2011 From: frederick.cheung at gmail.com (Frederick Cheung) Date: Fri, 11 Feb 2011 01:51:13 -0800 (PST) Subject: [rspec-users] hash form of stub_chain returning nil for chains with shared first message In-Reply-To: <798774CD-7291-46E1-81EE-4188A878AF22@gmail.com> References: <4AA94B44-94C3-4B2E-AD2E-D47196B31187@gmail.com> <798774CD-7291-46E1-81EE-4188A878AF22@gmail.com> Message-ID: <90633953-a366-4bc0-9506-27163fca3319@1g2000yqq.googlegroups.com> On Feb 10, 7:30?pm, David Chelimsky wrote: > On Feb 10, 2011, at 12:40 PM, Frederick Cheung wrote: > > > I'm new using rspec, so please forgive me if I'm barking up the wrong tree, but... > > > I'd expect this to pass (using rspec 2.5.1) > > > describe 'stub_chain' do > > ?it "returns expected value from two chains with hash" do > > ? ?subject = Object.new > > ? ?subject.stub_chain(:msg1, :msg2 => :first) > > ? ?subject.stub_chain(:msg1, :msg3 => :second) > > This ^^ is not documented to work. Seehttp://relishapp.com/rspec/rspec-mocks/v/2-5/dir/method-stubs/stub-a-.... > > Try: > > ? subject.stub_chain(:msg1, :msg2).and_return(:first) > > If that works, feel free to submit a feature request to support the format you were using. > Fair enough. I'd been reading stub_chain_spec.rb (which does do stuff like @subject.stub_chain(:msg1, :msg2, :msg3, :msg4 => :return_value)) rather than stub_chain.feature and had taken that (as well as https://github.com/rspec/rspec-mocks/commit/2c23b86cc5aaa99557df456054765e95aa1a0d5a ) to mean that subject.stub_chain(:msg1, :msg2 => :first) was official Fred > Cheers, > David > > > > > > > ? ?subject.msg1.msg2.should equal(:first) > > ? ?subject.msg1.msg3.should equal(:second) > > ?end > > end ? > > > But it doesn't - subject.msg1.msg3 returns nil > > > I think this is because in stub_chain (in rspec-mocks/lib/rspec/mocks/methods.rb, line 43) there is > > > if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, chain[0].to_sym) > > ? ?chain.shift > > ? ?matching_stub.invoke.stub_chain(*chain) > > else > > > ie blk isn't used in any way. Changing this to matching_stub.invoke.stub_chain(*chain, &blk) makes my example pass > > Is this true or am I just misusing rspec? > > > Fred > > > _______________________________________________ > > 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 wagner.andrew at gmail.com Fri Feb 11 07:00:58 2011 From: wagner.andrew at gmail.com (Andrew Wagner) Date: Fri, 11 Feb 2011 07:00:58 -0500 Subject: [rspec-users] Current test failing? Message-ID: Is there any way, within a test (e.g., in an after block), to see whether the test is currently passing, failing, or pending? Even a hack-ish kind of way? I'm just curious. -------------- next part -------------- An HTML attachment was scrubbed... URL: From antsmailinglist at gmail.com Fri Feb 11 11:04:36 2011 From: antsmailinglist at gmail.com (Ants Pants) Date: Fri, 11 Feb 2011 17:04:36 +0100 Subject: [rspec-users] Problem with rendering JSON Message-ID: You are my last resort for solving this issue as I have tried and tried to solve it myself but can't. I'm not even sure if it's an RSpec issue but the thing is, if I run the request from the browser, it works. Sadly, my test fails. So either there's something about Rails I don't know about (but should) or I'm doing something wrong in RSpec. Here is my test .... let(:charity) { mock_model(Charity).as_null_object } ... context "params[:term] has data" do it "calls Charity::fulltext_search" do Charity.should_receive(:fulltext_search).with(String).and_return([charity]) xhr :get, :autocomplete_index, :term => String, :format => :json end end And this is my controller .... def autocomplete_index @charities = (params[:term].blank?) ? [] : Charity.fulltext_search(params[:term]) render :json => @charities ##.to_json(:only => [:name, :official_website]) end As I said, this works from the browser but I get into a 'stack level too deep' with RSpec. I looked in to gems/actionpack-2.3.8/lib/action_view/paths.rb and it's responsible for finding the template. It raises MissingTemplate.new(self, original_template_path, format) and I printed the original_template_path (charities/) and the format (json) If anyone can me in the right direction, I would be v grateful. Thank you. -ants This is a snippet of the output (the bit between [[ ]] is repeated until the program quits with the 'stack level too deep' message. [[ gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `each' gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `map' gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `to_json' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' gems/activesupport-2.3.8/lib/active_support/json/encoders/object.rb:4:in `to_json' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:38:in `to_json' *gems/actionpack-2.3.8/lib/action_view/paths.rb:74:in `map'* ]] gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `each' gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `map' gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `to_json' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' gems/activesupport-2.3.8/lib/active_support/json/encoders/object.rb:4:in `to_json' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in `to_json' gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in `map' gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in `to_json' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' gems/actionpack-2.3.8/lib/action_controller/base.rb:954:in `render_without_benchmark' gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render' gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render' */home/anthony/Development/websites/ruby/project/trunk/app/controllers/charities_controller.rb:23:in `autocomplete_index'* gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in `send' gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in `perform_action_without_filters' gems/actionpack-2.3.8/lib/action_controller/filters.rb:617:in `call_filters' gems/actionpack-2.3.8/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark' gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' gems/actionpack-2.3.8/lib/action_controller/rescue.rb:160:in `perform_action_without_flash' gems/actionpack-2.3.8/lib/action_controller/flash.rb:151:in `perform_action' gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `send' gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `process_without_filters' gems/actionpack-2.3.8/lib/action_controller/filters.rb:606:in `process' gems/actionpack-2.3.8/lib/action_controller/test_process.rb:567:in `process_with_test' gems/actionpack-2.3.8/lib/action_controller/test_process.rb:447:in `process' gems/actionpack-2.3.8/lib/action_controller/test_process.rb:398:in `get' gems/actionpack-2.3.8/lib/action_controller/test_process.rb:453:in `__send__' gems/actionpack-2.3.8/lib/action_controller/test_process.rb:453:in `xhr' -------------- next part -------------- An HTML attachment was scrubbed... URL: From gditrick at fuse.net Fri Feb 11 11:28:53 2011 From: gditrick at fuse.net (GregD) Date: Fri, 11 Feb 2011 08:28:53 -0800 (PST) Subject: [rspec-users] testing a collection Message-ID: All, Is there away to test a collection with rspec 1.3? I've seen Jim Weirich's rspec-collection, but it requires rspec 2.0. I'd like to go to rspec 2.0, but have another dependency that will not work with rspec 2.0. I may have to bite the bullet and see if I can update that dependency to work wit rspec 2 and go to rspec 2. What I'd like to do is: describe "blah" do subject { a-collection } subjects.each do |s| subject { s } it { should pass a test } end end BTW: Using this to test a 3rd party app. Probably not the right tool, but I like ruby and its tools. So, I have access to the app db and send a message to the app via a service and need to see if things changed the way I expected. I'd love to actually test without doing it that way, but it would require Jruby to be able to mock java objects and return those mocks in the java. If that was possible than I'd test the java directly using jruby and rspec. I have tested some java with rspec, but those java classes don't involve db calls or other communications that I'd like to mock. If the java class involves any of those communications, I just have to write an integration test with fixtures, sending the data and then testing results. Any ideas other than find a java testing tool, because I just try to avoid java but can't since it is how I have to pay the bills. :( Thanks, GregD From hooligan495 at gmail.com Fri Feb 11 11:44:28 2011 From: hooligan495 at gmail.com (Jay McGaffigan) Date: Fri, 11 Feb 2011 11:44:28 -0500 Subject: [rspec-users] testing a collection In-Reply-To: References: Message-ID: Have you looked at JTestR? I'm not sure how active it is being developed and it might not do what you are looking for... but it might be worth a shot. jay On Fri, Feb 11, 2011 at 11:28 AM, GregD wrote: > All, > > Is there away to test a collection with rspec 1.3? ?I've seen Jim > Weirich's rspec-collection, but it requires rspec 2.0. ?I'd like to go > to rspec 2.0, but have another dependency that will not work with > rspec 2.0. ?I may have to bite the bullet and see if I can update that > dependency to work wit rspec 2 and go to rspec 2. > > What I'd like to do is: > > describe "blah" do > ?subject { a-collection } > > ?subjects.each do |s| > ? ? ?subject { s } > > ? ? ?it { should pass a test } > ?end > end > > BTW: ?Using this to test a 3rd party app. ?Probably not the right > tool, but I like ruby and its tools. ?So, I have access to the app db > and send a message to the app via a service and need to see if things > changed the way I expected. ?I'd love to actually test without doing > it that way, but it would require Jruby to be able to mock java > objects and return those mocks in the java. ?If that was possible than > I'd test the java directly using jruby and rspec. ?I have tested some > java with rspec, but those java classes don't involve db calls or > other communications that I'd like to mock. ?If the java class > involves any of those communications, I just have to write an > integration test with fixtures, sending the data and then testing > results. > > Any ideas other than find a java testing tool, because I just try to > avoid java but can't since it is how I have to pay the bills. ?:( > > > Thanks, > > GregD > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From gditrick at fuse.net Fri Feb 11 12:59:51 2011 From: gditrick at fuse.net (Greg Ditrick) Date: Fri, 11 Feb 2011 12:59:51 -0500 Subject: [rspec-users] testing a collection Message-ID: <3156373.1297447191660.JavaMail.root@wmvirt99> ---- Jay McGaffigan wrote: > Have you looked at JTestR? > I'm not sure how active it is being developed and it might not do what > you are looking for... but it might be worth a shot. > Yes. I can pretty much do all of what jtestr is doing. But, I believe that when you mock a java class that mock can not be returned in another java class that you are testing. So, if I have a java class that creates a java object of a DB object, I don't think I can mock that java DB object and expect the java that I'm testing to use that mock. I don't think Jtestr can do that, because I don't believe jruby is able to that. I maybe wrong, but jtestr examples only show simple mocking of say a hash. I can do that. But, if I need to mock the java hash object that is used in a java class, it will not return that mock to the java class I am testing. Again I might be wrong about jtestr. Maybe it can do that. I know I cannot just using jruby. I have tried with db objects and pinged Nick Sieger who replied it was not possible. From matt at mattwynne.net Fri Feb 11 17:45:20 2011 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 11 Feb 2011 22:45:20 +0000 Subject: [rspec-users] Problem with rendering JSON In-Reply-To: References: Message-ID: <37F2AADF-0AA3-43AA-BE95-A05980F95A5E@mattwynne.net> On 11 Feb 2011, at 16:04, Ants Pants wrote: > You are my last resort for solving this issue as I have tried and tried to solve it myself but can't. > > I'm not even sure if it's an RSpec issue but the thing is, if I run the request from the browser, it works. Sadly, my test fails. So either there's something about Rails I don't know about (but should) or I'm doing something wrong in RSpec. > > Here is my test .... > > let(:charity) { mock_model(Charity).as_null_object } > ... > context "params[:term] has data" do > it "calls Charity::fulltext_search" do > Charity.should_receive(:fulltext_search).with(String).and_return([charity]) Why are you using the class String here, instead of an actual sample term? > xhr :get, :autocomplete_index, :term => String, :format => :json ditto. > end > end > > And this is my controller .... > > def autocomplete_index > @charities = (params[:term].blank?) ? [] : Charity.fulltext_search(params[:term]) > render :json => @charities ##.to_json(:only => [:name, :official_website]) > end > > As I said, this works from the browser but I get into a 'stack level too deep' with RSpec. > > I looked in to gems/actionpack-2.3.8/lib/action_view/paths.rb and it's responsible for finding the template. > > It raises MissingTemplate.new(self, original_template_path, format) and I printed the original_template_path (charities/) and the format (json) > > If anyone can me in the right direction, I would be v grateful. Thank you. > > -ants > > This is a snippet of the output (the bit between [[ ]] is repeated until the program quits with the 'stack level too deep' message. > > [[ > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `each' > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `map' > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoders/object.rb:4:in `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:38:in `to_json' > gems/actionpack-2.3.8/lib/action_view/paths.rb:74:in `map' > ]] > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `each' > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `map' > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoders/object.rb:4:in `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in `map' > gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' > gems/actionpack-2.3.8/lib/action_controller/base.rb:954:in `render_without_benchmark' > gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render' > gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' > gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' > gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render' > /home/anthony/Development/websites/ruby/project/trunk/app/controllers/charities_controller.rb:23:in `autocomplete_index' > gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in `send' > gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in `perform_action_without_filters' > gems/actionpack-2.3.8/lib/action_controller/filters.rb:617:in `call_filters' > gems/actionpack-2.3.8/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark' > gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' > gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' > gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' > gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' > gems/actionpack-2.3.8/lib/action_controller/rescue.rb:160:in `perform_action_without_flash' > gems/actionpack-2.3.8/lib/action_controller/flash.rb:151:in `perform_action' > gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `send' > gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `process_without_filters' > gems/actionpack-2.3.8/lib/action_controller/filters.rb:606:in `process' > gems/actionpack-2.3.8/lib/action_controller/test_process.rb:567:in `process_with_test' > gems/actionpack-2.3.8/lib/action_controller/test_process.rb:447:in `process' > gems/actionpack-2.3.8/lib/action_controller/test_process.rb:398:in `get' > gems/actionpack-2.3.8/lib/action_controller/test_process.rb:453:in `__send__' > gems/actionpack-2.3.8/lib/action_controller/test_process.rb:453:in `xhr' > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmymartin at gmail.com Fri Feb 11 18:03:27 2011 From: jimmymartin at gmail.com (James Martin) Date: Sat, 12 Feb 2011 10:03:27 +1100 Subject: [rspec-users] Current test failing? In-Reply-To: References: Message-ID: I'm trying to imagine a use case (and usage) of this. Could you give me an example of how you would want to write it and what for? On Friday, February 11, 2011, Andrew Wagner wrote: > Is there any way, within a test (e.g., in an after block), to see whether the test is currently passing, failing, or pending? Even a hack-ish kind of way? I'm just curious. > From doug+rspecuser at netinlet.com Fri Feb 11 18:05:55 2011 From: doug+rspecuser at netinlet.com (Doug Bryant) Date: Fri, 11 Feb 2011 17:05:55 -0600 Subject: [rspec-users] Controller Specs - undefined local variable or method 'app' Message-ID: On one of my projects using rspec 2.5 & rails 3.0.4, I recently moved from postgres to mongo and am using mongoid as the persistence library. I ported all the models over to the mongoid way of doing things and now have all my models passing the tests. None of the controller test work any more. They all fail with the following error message about undefined local variable or method. Failure/Error: post :create, :account => {} > NameError: > undefined local variable or method `app' for > # > # ./spec/controllers/accounts_controller_spec.rb:84:in `block (4 > levels) in ' Has anyone else run across this? Any ideas about how to fix it? Doug -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Feb 11 22:10:30 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Sat, 12 Feb 2011 04:10:30 +0100 Subject: [rspec-users] mocking an AR: ActiveRecord::AssociationTypeMismatch error Message-ID: <5fd0d9520e7ade582c6c3a46e2f340f1@ruby-forum.com> I have a Premise model with lots of validations and somewhat complex callbacks. I've already written tests for those (and they pass). I also have a MeteredService model for which premise :has_many metered_services and (of course) metered_service :belongs_to premise. Testing MeteredService doesn't require a real Premise -- all it needs is a premise_id -- so for my MeteredService tests I tried a simple mock like: premise = double("premise", :id => 1) But this fails with: Failure/Error: MeteredService.create(:premise => @premise) ActiveRecord::AssociationTypeMismatch: Premise(#2202729700) expected, got RSpec::Mocks::Mock(#2154067120) I *really* don't want to create a real Premise object unless there's a way to inhibit all the validations and callbacks. (FWIW, I use FactoryGirl for other test, but it evidently triggers validations and callbacks just like an ordinary .create()) What are my options? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Feb 12 02:22:40 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 12 Feb 2011 05:22:40 -0200 Subject: [rspec-users] mocking an AR: ActiveRecord::AssociationTypeMismatch error In-Reply-To: <5fd0d9520e7ade582c6c3a46e2f340f1@ruby-forum.com> References: <5fd0d9520e7ade582c6c3a46e2f340f1@ruby-forum.com> Message-ID: <998DB21A-8328-4823-928D-FE5AC267BE24@gmail.com> On Feb 12, 2011, at 1:10 AM, Fearless Fool wrote: > I have a Premise model with lots of validations and somewhat complex > callbacks. I've already written tests for those (and they pass). > > I also have a MeteredService model for which premise :has_many > metered_services and (of course) metered_service :belongs_to premise. > > Testing MeteredService doesn't require a real Premise -- all it needs is > a premise_id -- so for my MeteredService tests I tried a simple mock > like: > > premise = double("premise", :id => 1) > > But this fails with: > > Failure/Error: MeteredService.create(:premise => @premise) > ActiveRecord::AssociationTypeMismatch: > Premise(#2202729700) expected, got RSpec::Mocks::Mock(#2154067120) > > I *really* don't want to create a real Premise object unless there's a > way to inhibit all the validations and callbacks. (FWIW, I use > FactoryGirl for other test, but it evidently triggers validations and > callbacks just like an ordinary .create()) > > What are my options? http://relishapp.com/rspec/rspec-rails/v/2-5/dir/mocks/mock-model HTH, David From antsmailinglist at gmail.com Sat Feb 12 07:49:32 2011 From: antsmailinglist at gmail.com (Ants Pants) Date: Sat, 12 Feb 2011 13:49:32 +0100 Subject: [rspec-users] Problem with rendering JSON In-Reply-To: <37F2AADF-0AA3-43AA-BE95-A05980F95A5E@mattwynne.net> References: <37F2AADF-0AA3-43AA-BE95-A05980F95A5E@mattwynne.net> Message-ID: On 11 February 2011 23:45, Matt Wynne wrote: > > On 11 Feb 2011, at 16:04, Ants Pants wrote: > > You are my last resort for solving this issue as I have tried and tried to > solve it myself but can't. > > I'm not even sure if it's an RSpec issue but the thing is, if I run the > request from the browser, it works. Sadly, my test fails. So either there's > something about Rails I don't know about (but should) or I'm doing something > wrong in RSpec. > > Here is my test .... > > let(:charity) { mock_model(Charity).as_null_object } > ... > context "params[:term] has data" do > it "calls Charity::fulltext_search" do > > Charity.should_receive(:fulltext_search).with(String).and_return([charity]) > > > Why are you using the class String here, instead of an actual sample term? > > xhr :get, :autocomplete_index, :term => String, :format => :json > > > ditto. > > end > end > > And this is my controller .... > > def autocomplete_index > @charities = (params[:term].blank?) ? [] : > Charity.fulltext_search(params[:term]) > render :json => @charities ##.to_json(:only => [:name, > :official_website]) > end > > As I said, this works from the browser but I get into a 'stack level too > deep' with RSpec. > > I looked in to gems/actionpack-2.3.8/lib/action_view/paths.rb and it's > responsible for finding the template. > > It raises MissingTemplate.new(self, original_template_path, format) and I > printed the original_template_path (charities/) and the format (json) > > If anyone can me in the right direction, I would be v grateful. Thank you. > > -ants > > This is a snippet of the output (the bit between [[ ]] is repeated until > the program quits with the 'stack level too deep' message. > > [[ > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in > `each' > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in > `map' > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in > `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in > `__send__' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoders/object.rb:4:in > `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in > `__send__' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:38:in > `to_json' > *gems/actionpack-2.3.8/lib/action_view/paths.rb:74:in `map'* > ]] > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in > `each' > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in > `map' > gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in > `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in > `__send__' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoders/object.rb:4:in > `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in > `__send__' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in > `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in > `map' > gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in > `to_json' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in > `__send__' > gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' > gems/actionpack-2.3.8/lib/action_controller/base.rb:954:in > `render_without_benchmark' > gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render' > gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in > `ms' > gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in > `ms' > gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render' > */home/anthony/Development/websites/ruby/project/trunk/app/controllers/charities_controller.rb:23:in > `autocomplete_index'* > gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in `send' > gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in > `perform_action_without_filters' > gems/actionpack-2.3.8/lib/action_controller/filters.rb:617:in > `call_filters' > gems/actionpack-2.3.8/lib/action_controller/filters.rb:610:in > `perform_action_without_benchmark' > gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in > `perform_action_without_rescue' > gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in > `ms' > gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in > `ms' > gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in > `perform_action_without_rescue' > gems/actionpack-2.3.8/lib/action_controller/rescue.rb:160:in > `perform_action_without_flash' > gems/actionpack-2.3.8/lib/action_controller/flash.rb:151:in > `perform_action' > gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `send' > gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in > `process_without_filters' > gems/actionpack-2.3.8/lib/action_controller/filters.rb:606:in `process' > gems/actionpack-2.3.8/lib/action_controller/test_process.rb:567:in > `process_with_test' > gems/actionpack-2.3.8/lib/action_controller/test_process.rb:447:in > `process' > gems/actionpack-2.3.8/lib/action_controller/test_process.rb:398:in `get' > gems/actionpack-2.3.8/lib/action_controller/test_process.rb:453:in > `__send__' > gems/actionpack-2.3.8/lib/action_controller/test_process.rb:453:in `xhr' > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Hi, The reason why I'm using String is because I'm not bothered about return values and I'm using it more as a bit more documentation - fulltext_search accepts a string and returns an array of charity records. Also, in this example, I don't even need with() nor and_return() as all I'm really interested in is if fulltext_search is called. If I'm interested in the return value, then I will use real values. Otherwise I'll just use generic Fixnum/String etc. Now I've explained that, am I using it wrong? For me, it works but like I say, If I'm doing something dangerously wrong, then I will change my way of working. -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sat Feb 12 11:14:21 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Sat, 12 Feb 2011 17:14:21 +0100 Subject: [rspec-users] mocking an AR: ActiveRecord::AssociationTypeMismatch error In-Reply-To: <998DB21A-8328-4823-928D-FE5AC267BE24@gmail.com> References: <5fd0d9520e7ade582c6c3a46e2f340f1@ruby-forum.com> <998DB21A-8328-4823-928D-FE5AC267BE24@gmail.com> Message-ID: <90094aa2c61205df82b92e5e74203818@ruby-forum.com> David Chelimsky wrote in post #981239: > http://relishapp.com/rspec/rspec-rails/v/2-5/dir/mocks/mock-model > HTH, > David Boy howdy, TH to the max. (How did I miss that???) Thanks. - ff -- Posted via http://www.ruby-forum.com/. From rdpoor at gmail.com Wed Feb 9 18:36:28 2011 From: rdpoor at gmail.com (Robert Poor) Date: Wed, 9 Feb 2011 15:36:28 -0800 Subject: [rspec-users] using before(:all) for cheap benchmark? Message-ID: I'm a new (and complete) convert to RSpec, especially when coupled with autotest. I notice when automate processes my entire spec directory it takes about eight minutes. I have many more tests to add before I'm done, so eventually I'll want to streamline my tests. Is there a quick and dirty way log the amount of time spent on each file to a log? That would give me a place to start looking for optimizations. (For extra credit: is there a way to log the time spent on each individual test?) I'll look into using before(:all) and after(:all) for doing this, but if you've already created a benchmark hook for rspec, I'm happy to use your code. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolfram at rubyfocus.biz Thu Feb 10 15:19:55 2011 From: wolfram at rubyfocus.biz (Wolfram Arnold, RubyFocus) Date: Thu, 10 Feb 2011 12:19:55 -0800 (PST) Subject: [rspec-users] Control order of spec files for an integration test? Message-ID: <6be0b57b-37f2-4b2d-b98d-e2ac53bb089d@y36g2000pra.googlegroups.com> Hi, I'm using RSpec2 with Capybara and Celerity for an integration test. I'd like to use some of the tests (e.g. user registration) to run as a prerequisite to other steps. I was hoping that by naming files in the correct alphabetical order, RSpec would run them in alphabetical order. RSpec 1.x used to do that, I believe, and also supported a -- loadby flag. Background: I realize that test dependency is usually considered a bug in general TDD methodology and I wholeheartedly agree to this for standard test coverage (models, controllers, etc...). Our (emerging) integration framework is a stand-alone application that pings live (staging) servers and is a sort of sanity check. Our full environment involves multiple servers that communicate over API's, and our design goal with the sanity check suite is to go as close to the user perspective as possible, and bridge gaps in test coverage that is caused by mocking out remote API's. Our sanity suite is actually designed to have some steps build on top of each other and some are expensive (i.e. slow) to run and also involve outside resources (e.g. credit card gateways) that we don't want to over-burden by repeating setup for each example. My actual question is to find out if there is anything that would speak against patching RSpec so that it supports file ordering per command line flags or options configuration. Thanks, Wolf From dchelimsky at gmail.com Sat Feb 12 14:55:44 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 12 Feb 2011 17:55:44 -0200 Subject: [rspec-users] hash form of stub_chain returning nil for chains with shared first message In-Reply-To: <90633953-a366-4bc0-9506-27163fca3319@1g2000yqq.googlegroups.com> References: <4AA94B44-94C3-4B2E-AD2E-D47196B31187@gmail.com> <798774CD-7291-46E1-81EE-4188A878AF22@gmail.com> <90633953-a366-4bc0-9506-27163fca3319@1g2000yqq.googlegroups.com> Message-ID: <4731245A-8FF2-4798-84C0-3727503A956D@gmail.com> On Feb 11, 2011, at 7:51 AM, Frederick Cheung wrote: > On Feb 10, 7:30 pm, David Chelimsky wrote: >> On Feb 10, 2011, at 12:40 PM, Frederick Cheung wrote: >> >>> I'm new using rspec, so please forgive me if I'm barking up the wrong tree, but... >> >>> I'd expect this to pass (using rspec 2.5.1) >> >>> describe 'stub_chain' do >>> it "returns expected value from two chains with hash" do >>> subject = Object.new >>> subject.stub_chain(:msg1, :msg2 => :first) >>> subject.stub_chain(:msg1, :msg3 => :second) >> >> This ^^ is not documented to work. Seehttp://relishapp.com/rspec/rspec-mocks/v/2-5/dir/method-stubs/stub-a-.... >> >> Try: >> >> subject.stub_chain(:msg1, :msg2).and_return(:first) >> >> If that works, feel free to submit a feature request to support the format you were using. >> > > Fair enough. I'd been reading stub_chain_spec.rb (which does do stuff > like @subject.stub_chain(:msg1, :msg2, :msg3, :msg4 => :return_value)) > rather than stub_chain.feature and had taken that (as well as > https://github.com/rspec/rspec-mocks/commit/2c23b86cc5aaa99557df456054765e95aa1a0d5a > ) to mean that subject.stub_chain(:msg1, :msg2 => :first) was official I was wrong. I'd consider this documented, and that what you are experiencing is a bug. Please submit an issue (https://github.com/rspec/rspec-mocks/issues). Thx, David > > Fred > >> Cheers, >> David >> >> >> >> >> >>> subject.msg1.msg2.should equal(:first) >>> subject.msg1.msg3.should equal(:second) >>> end >>> end >> >>> But it doesn't - subject.msg1.msg3 returns nil >> >>> I think this is because in stub_chain (in rspec-mocks/lib/rspec/mocks/methods.rb, line 43) there is >> >>> if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, chain[0].to_sym) >>> chain.shift >>> matching_stub.invoke.stub_chain(*chain) >>> else >> >>> ie blk isn't used in any way. Changing this to matching_stub.invoke.stub_chain(*chain, &blk) makes my example pass >>> Is this true or am I just misusing rspec? >> >>> Fred >> >>> _______________________________________________ >>> 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From jimmymartin at gmail.com Sat Feb 12 15:39:10 2011 From: jimmymartin at gmail.com (James Martin) Date: Sun, 13 Feb 2011 07:39:10 +1100 Subject: [rspec-users] Controller Specs - undefined local variable or method 'app' In-Reply-To: References: Message-ID: Not 100% sure, but that failure looks suspiciously like something you get when using rack-test; which expects an 'app' method to be defined that returns an instance of your rack-compatible application. On Saturday, February 12, 2011, Doug Bryant wrote: > On one of my projects using rspec 2.5 & rails 3.0.4, I recently moved from postgres to mongo and am using mongoid as the persistence library. > I ported all the models over to the mongoid way of doing things and now have all my models passing the tests. > > > None of the controller test work any more. ?They all fail with the following error message about undefined local variable or method. > > > ??Failure/Error: post :create, :account => {} > ?? ? NameError: > ?? ? ? undefined local variable or method `app' for # > ?? ? # ./spec/controllers/accounts_controller_spec.rb:84:in `block (4 levels) in ' > > > > > Has anyone else run across this? ?Any ideas about how to fix it? > Doug > From dchelimsky at gmail.com Sat Feb 12 15:43:41 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 12 Feb 2011 18:43:41 -0200 Subject: [rspec-users] hash form of stub_chain returning nil for chains with shared first message In-Reply-To: <4731245A-8FF2-4798-84C0-3727503A956D@gmail.com> References: <4AA94B44-94C3-4B2E-AD2E-D47196B31187@gmail.com> <798774CD-7291-46E1-81EE-4188A878AF22@gmail.com> <90633953-a366-4bc0-9506-27163fca3319@1g2000yqq.googlegroups.com> <4731245A-8FF2-4798-84C0-3727503A956D@gmail.com> Message-ID: <9D922B60-1889-4C32-B36A-550F496F5087@gmail.com> On Feb 12, 2011, at 5:55 PM, David Chelimsky wrote: > > On Feb 11, 2011, at 7:51 AM, Frederick Cheung wrote: > >> On Feb 10, 7:30 pm, David Chelimsky wrote: >>> On Feb 10, 2011, at 12:40 PM, Frederick Cheung wrote: >>> >>>> I'm new using rspec, so please forgive me if I'm barking up the wrong tree, but... >>> >>>> I'd expect this to pass (using rspec 2.5.1) >>> >>>> describe 'stub_chain' do >>>> it "returns expected value from two chains with hash" do >>>> subject = Object.new >>>> subject.stub_chain(:msg1, :msg2 => :first) >>>> subject.stub_chain(:msg1, :msg3 => :second) >>> >>> This ^^ is not documented to work. Seehttp://relishapp.com/rspec/rspec-mocks/v/2-5/dir/method-stubs/stub-a-.... >>> >>> Try: >>> >>> subject.stub_chain(:msg1, :msg2).and_return(:first) >>> >>> If that works, feel free to submit a feature request to support the format you were using. >>> >> >> Fair enough. I'd been reading stub_chain_spec.rb (which does do stuff >> like @subject.stub_chain(:msg1, :msg2, :msg3, :msg4 => :return_value)) >> rather than stub_chain.feature and had taken that (as well as >> https://github.com/rspec/rspec-mocks/commit/2c23b86cc5aaa99557df456054765e95aa1a0d5a >> ) to mean that subject.stub_chain(:msg1, :msg2 => :first) was official > > I was wrong. I'd consider this documented, and that what you are experiencing is a bug. > > Please submit an issue (https://github.com/rspec/rspec-mocks/issues). FYI - I've already fixed this: https://github.com/rspec/rspec-mocks/commit/ca2d83712fe329affbe4334c8c292c40ae74e5ce Feel free to submit an issue anyhow if you like, and I'll note this commit in the issue. Cheers, David > > Thx, > David > > >> >> Fred >> >>> Cheers, >>> David >>> >>> >>> >>> >>> >>>> subject.msg1.msg2.should equal(:first) >>>> subject.msg1.msg3.should equal(:second) >>>> end >>>> end >>> >>>> But it doesn't - subject.msg1.msg3 returns nil >>> >>>> I think this is because in stub_chain (in rspec-mocks/lib/rspec/mocks/methods.rb, line 43) there is >>> >>>> if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, chain[0].to_sym) >>>> chain.shift >>>> matching_stub.invoke.stub_chain(*chain) >>>> else >>> >>>> ie blk isn't used in any way. Changing this to matching_stub.invoke.stub_chain(*chain, &blk) makes my example pass >>>> Is this true or am I just misusing rspec? >>> >>>> Fred From dchelimsky at gmail.com Sat Feb 12 15:59:11 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 12 Feb 2011 18:59:11 -0200 Subject: [rspec-users] using before(:all) for cheap benchmark? In-Reply-To: References: Message-ID: <78B7D2C3-2731-4EEF-B6DD-C4A2FCAF6A3F@gmail.com> On Feb 9, 2011, at 9:36 PM, Robert Poor wrote: > I'm a new (and complete) convert to RSpec, especially when coupled with autotest. > > I notice when automate processes my entire spec directory it takes about eight minutes. I have many more tests to add before I'm done, so eventually I'll want to streamline my tests. > > Is there a quick and dirty way log the amount of time spent on each file to a log? That would give me a place to start looking for optimizations. (For extra credit: is there a way to log the time spent on each individual test?) > > I'll look into using before(:all) and after(:all) for doing this, but if you've already created a benchmark hook for rspec, I'm happy to use your code. Run the rspec command with the --help flag, like this: rspec --help It lists all of the available options, including --profile, which lists the 10 slowest examples. Doesn't give you exactly what you're saying you want, but it probably sets you in the right direction. HTH, David From doug+rspecuser at netinlet.com Sat Feb 12 17:08:59 2011 From: doug+rspecuser at netinlet.com (Doug Bryant) Date: Sat, 12 Feb 2011 16:08:59 -0600 Subject: [rspec-users] Controller Specs - undefined local variable or method 'app' In-Reply-To: References: Message-ID: Your hunch looks correct - I ran it through the debugger last night and found the spot where it was failing in rack-test although I don't know why it was failing. I removed this line from my spec_helper.rb: > config.include Rack::Test::Methods and it magically started working again. Thanks for taking the time to look at it. Doug On Sat, Feb 12, 2011 at 2:39 PM, James Martin wrote: > Not 100% sure, but that failure looks suspiciously like something you > get when using rack-test; which expects an 'app' method to be defined > that returns an instance of your rack-compatible application. > > On Saturday, February 12, 2011, Doug Bryant > wrote: > > On one of my projects using rspec 2.5 & rails 3.0.4, I recently moved > from postgres to mongo and am using mongoid as the persistence library. > > I ported all the models over to the mongoid way of doing things and now > have all my models passing the tests. > > > > > > None of the controller test work any more. They all fail with the > following error message about undefined local variable or method. > > > > > > Failure/Error: post :create, :account => {} > > NameError: > > undefined local variable or method `app' for > # > > # ./spec/controllers/accounts_controller_spec.rb:84:in `block (4 > levels) in ' > > > > > > > > > > Has anyone else run across this? Any ideas about how to fix it? > > Doug > > > _______________________________________________ > 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 frederick.cheung at gmail.com Sun Feb 13 02:41:42 2011 From: frederick.cheung at gmail.com (Frederick Cheung) Date: Sat, 12 Feb 2011 23:41:42 -0800 (PST) Subject: [rspec-users] hash form of stub_chain returning nil for chains with shared first message In-Reply-To: <9D922B60-1889-4C32-B36A-550F496F5087@gmail.com> References: <4AA94B44-94C3-4B2E-AD2E-D47196B31187@gmail.com> <798774CD-7291-46E1-81EE-4188A878AF22@gmail.com> <90633953-a366-4bc0-9506-27163fca3319@1g2000yqq.googlegroups.com> <4731245A-8FF2-4798-84C0-3727503A956D@gmail.com> <9D922B60-1889-4C32-B36A-550F496F5087@gmail.com> Message-ID: On Feb 12, 8:43?pm, David Chelimsky wrote: > > > I was wrong. I'd consider this documented, and that what you are experiencing is a bug. > > > Please submit an issue (https://github.com/rspec/rspec-mocks/issues). > > FYI - I've already fixed this:https://github.com/rspec/rspec-mocks/commit/ca2d83712fe329affbe4334c8... > > Feel free to submit an issue anyhow if you like, and I'll note this commit in the issue. > Sweet! I created https://github.com/rspec/rspec-mocks/issues/issue/38 (and nice to see that the fix was what I thought it was!) Fred From matt at mattwynne.net Sun Feb 13 06:39:55 2011 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 13 Feb 2011 11:39:55 +0000 Subject: [rspec-users] Problem with rendering JSON In-Reply-To: References: <37F2AADF-0AA3-43AA-BE95-A05980F95A5E@mattwynne.net> Message-ID: <05BE565A-6DA1-42D0-A808-B17A0780E7C8@mattwynne.net> On 12 Feb 2011, at 12:49, Ants Pants wrote: > > > On 11 February 2011 23:45, Matt Wynne wrote: > > On 11 Feb 2011, at 16:04, Ants Pants wrote: > >> You are my last resort for solving this issue as I have tried and tried to solve it myself but can't. >> >> I'm not even sure if it's an RSpec issue but the thing is, if I run the request from the browser, it works. Sadly, my test fails. So either there's something about Rails I don't know about (but should) or I'm doing something wrong in RSpec. >> >> Here is my test .... >> >> let(:charity) { mock_model(Charity).as_null_object } >> ... >> context "params[:term] has data" do >> it "calls Charity::fulltext_search" do >> Charity.should_receive(:fulltext_search).with(String).and_return([charity]) > > Why are you using the class String here, instead of an actual sample term? > >> xhr :get, :autocomplete_index, :term => String, :format => :json > > ditto. > >> end >> end >> >> And this is my controller .... >> >> def autocomplete_index >> @charities = (params[:term].blank?) ? [] : Charity.fulltext_search(params[:term]) >> render :json => @charities ##.to_json(:only => [:name, :official_website]) >> end >> >> As I said, this works from the browser but I get into a 'stack level too deep' with RSpec. >> >> I looked in to gems/actionpack-2.3.8/lib/action_view/paths.rb and it's responsible for finding the template. >> >> It raises MissingTemplate.new(self, original_template_path, format) and I printed the original_template_path (charities/) and the format (json) >> >> If anyone can me in the right direction, I would be v grateful. Thank you. >> >> -ants >> >> This is a snippet of the output (the bit between [[ ]] is repeated until the program quits with the 'stack level too deep' message. >> >> [[ >> gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `each' >> gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `map' >> gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `to_json' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' >> gems/activesupport-2.3.8/lib/active_support/json/encoders/object.rb:4:in `to_json' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' >> gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:38:in `to_json' >> gems/actionpack-2.3.8/lib/action_view/paths.rb:74:in `map' >> ]] >> gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `each' >> gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `map' >> gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in `to_json' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' >> gems/activesupport-2.3.8/lib/active_support/json/encoders/object.rb:4:in `to_json' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' >> gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in `to_json' >> gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in `map' >> gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in `to_json' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in `encode' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `__send__' >> gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in `encode' >> gems/actionpack-2.3.8/lib/action_controller/base.rb:954:in `render_without_benchmark' >> gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render' >> gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' >> gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' >> gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render' >> /home/anthony/Development/websites/ruby/project/trunk/app/controllers/charities_controller.rb:23:in `autocomplete_index' >> gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in `send' >> gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in `perform_action_without_filters' >> gems/actionpack-2.3.8/lib/action_controller/filters.rb:617:in `call_filters' >> gems/actionpack-2.3.8/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark' >> gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' >> gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' >> gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' >> gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' >> gems/actionpack-2.3.8/lib/action_controller/rescue.rb:160:in `perform_action_without_flash' >> gems/actionpack-2.3.8/lib/action_controller/flash.rb:151:in `perform_action' >> gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `send' >> gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `process_without_filters' >> gems/actionpack-2.3.8/lib/action_controller/filters.rb:606:in `process' >> gems/actionpack-2.3.8/lib/action_controller/test_process.rb:567:in `process_with_test' >> gems/actionpack-2.3.8/lib/action_controller/test_process.rb:447:in `process' >> gems/actionpack-2.3.8/lib/action_controller/test_process.rb:398:in `get' >> gems/actionpack-2.3.8/lib/action_controller/test_process.rb:453:in `__send__' >> gems/actionpack-2.3.8/lib/action_controller/test_process.rb:453:in `xhr' >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Hi, > > The reason why I'm using String is because I'm not bothered about return values and I'm using it more as a bit more documentation - fulltext_search accepts a string and returns an array of charity records. > > Also, in this example, I don't even need with() nor and_return() as all I'm really interested in is if fulltext_search is called. > > If I'm interested in the return value, then I will use real values. Otherwise I'll just use generic Fixnum/String etc. > > Now I've explained that, am I using it wrong? For me, it works but like I say, If I'm doing something dangerously wrong, then I will change my way of working. Well, the error you're getting seems to be coming from deep within the bowels of Rails, where it's trying to encode a hash as JSON. I have no idea what that code will try to do if you give it a String class as a value within the Hash, but I can imagine it might cause the kind of weirdness you're experiencing. What I'd do in a simliar situation is to use a more realistic value (i.e. something that actually is an instance of String) that still explains to the reader that it's of low importance to the test case. For example: Charity.should_receive(:fulltext_search).with('a query term').and_return([charity]) Sometimes I even push these off into let blocks. cheers, Matt matt at mattwynne.net 07974 430184 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Feb 13 23:21:57 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Feb 2011 02:21:57 -0200 Subject: [rspec-users] feedback on feature request requested Message-ID: <24C86065-ED14-4939-9293-CE7C4966D624@gmail.com> Hey all, There is a feature request that would break compatibility for some rspec suites using older conventions. I'm in favor of adding the feature in 3.0 release when we get there, but would appreciate hearing from those that would be inconvenienced by this change. Please comment in the issue whether for or against: https://github.com/rspec/rspec-core/issues/304. Cheers, David From lists at ruby-forum.com Mon Feb 14 13:31:05 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Mon, 14 Feb 2011 19:31:05 +0100 Subject: [rspec-users] stubbing out after_create AR method? Message-ID: I have a Premise model with an after_create method, along the lines of: class Premise < ActiveRecord::Base ... after_create :etl_attributes ... end In production code, etl_attributes accesses the web. For testing I'm using WebMock and VCR in cases where I want to test the etl_attributes function -- works like a champ. For all other tests, I want to create a real Premise object (I need it for HABTM associations), but I want to stub out the call to etl_attributes. My problem is that I haven't figured out the right way to do so. The following DOESN'T work (it should be clear that I'm using FactoryGirl as well): mock_model(Premise) Premise.stub!(:etl_attributes) @premise = Factory.create(:premise) ... this still calls etl_attributes and WebMock gets appropriately mad. What am I missing? - ff -- Posted via http://www.ruby-forum.com/. From jko170 at gmail.com Mon Feb 14 14:53:22 2011 From: jko170 at gmail.com (Justin Ko) Date: Mon, 14 Feb 2011 11:53:22 -0800 (PST) Subject: [rspec-users] stubbing out after_create AR method? In-Reply-To: References: Message-ID: <7457929e-95d2-49a3-9e99-2a8dcecf7cd3@q2g2000pre.googlegroups.com> On Feb 14, 11:31?am, Fearless Fool wrote: > I have a Premise model with an after_create method, along the lines of: > > class Premise < ActiveRecord::Base > ? ... > ? after_create :etl_attributes > ? ... > end > > In production code, etl_attributes accesses the web. ?For testing I'm > using WebMock and VCR in cases where I want to test the etl_attributes > function -- works like a champ. > > For all other tests, I want to create a real Premise object (I need it > for HABTM associations), but I want to stub out the call to > etl_attributes. ?My problem is that I haven't figured out the right way > to do so. ?The following DOESN'T work (it should be clear that I'm using > FactoryGirl as well): > > ? ? ? mock_model(Premise) > ? ? ? Premise.stub!(:etl_attributes) > ? ? ? @premise = Factory.create(:premise) > > ... this still calls etl_attributes and WebMock gets appropriately mad. > > What am I missing? > > - ff > > -- > Posted viahttp://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users etl_attributes is an instance method, not a class method. So, you want to stub the method on the Premise instance. Since you're using rspec- mocks, I would recommend something like this: @premise = Factory.build(:premise) @premise.stub(:etl_attributes) @premise.save! For more info using pure mock objects, checkout these pages: http://relishapp.com/rspec/rspec-rails/v/2-5/dir/mocks/mock-model http://relishapp.com/rspec/rspec-rails/v/2-5/dir/mocks/stub-model From lists at ruby-forum.com Mon Feb 14 16:08:23 2011 From: lists at ruby-forum.com (Kane Baccigalupi) Date: Mon, 14 Feb 2011 22:08:23 +0100 Subject: [rspec-users] (Bad) Memory Leak in RSpec 2 Message-ID: We have had a really great integrated javascripting testing in our very large, very javascripty Sinatra application. Our testing setup uses a custom version of harmony (http://github.com/baccigalupi/harmony), that reduces the out of control memory we were seeing in the original gem. The trade off has been performance, but it has been worth it since harmony without these modifications get above 2G of memory consumption. That was bringing our development box to its knees. The custom version of harmony creates individual window objects with each request which can then be garbage collected at the end of usage. It worked great in rspec 1.x. Here was our setup: describe 'some javascript class' do before :all do @dom = Harmony::Page.new(my_ruby_view) @dom.load(some_js_files) end it 'should do something' do @dom.execute_js('javascript here').should == what_we_expect end end We are upgrading to RSpec 2, which has been a lot more involved and undocumented than we had hoped. Our biggest issue though is that the memory reduction measures that we added to the harmony gem are no longer working. Presumably this is because RSpec 2 is hanging on to the variables somewhere that we cannot find. Setting our harmony Page objects to nil is not working: # in the spec_helper Rspec.configure block: config.after(:all) do puts 'about to cleanup' @dom = nil GC.start # trying to cleanup via Ruby puts Johnson.evaluate <<-JS Johnson.runtime.gc(); // trying to cleanup via JS JS end We have tried a lot of ordering combinations in our garbage collection to see if anything will work, but instead the memory is climbing out of control with each suite. In version RSpec 1.x we didn't have to do any manual garbage collection. Does anyone have an idea of where the variable might be referenced in RSpec 2 and how we can demand cleanup? For now we are going to have to make a rake task that runs each spec separately, which will lead to a not very useful testing task. Better than nothing, but it will cost us a lot in developer time, going through all the output to find the failures. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Feb 14 17:01:45 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Feb 2011 20:01:45 -0200 Subject: [rspec-users] (Bad) Memory Leak in RSpec 2 In-Reply-To: References: Message-ID: <9207F571-91A5-4723-A900-8BE5725FFB6A@gmail.com> On Feb 14, 2011, at 7:08 PM, Kane Baccigalupi wrote: > We have had a really great integrated javascripting testing in our very > large, very javascripty Sinatra application. Our testing setup uses a > custom version of harmony (http://github.com/baccigalupi/harmony), that > reduces the out of control memory we were seeing in the original gem. > The trade off has been performance, but it has been worth it since > harmony without these modifications get above 2G of memory consumption. > That was bringing our development box to its knees. The custom version > of harmony creates individual window objects with each request which can > then be garbage collected at the end of usage. It worked great in rspec > 1.x. Here was our setup: > > describe 'some javascript class' do > before :all do > @dom = Harmony::Page.new(my_ruby_view) > @dom.load(some_js_files) > end > > it 'should do something' do > @dom.execute_js('javascript here').should == what_we_expect > end > end > > We are upgrading to RSpec 2, which has been a lot more involved and > undocumented than we had hoped. Please let me know what is not yet documented on the following pages: http://relishapp.com/rspec/rspec-core/v/2-5/file/upgrade http://relishapp.com/rspec/rspec-expectations/v/2-5/file/upgrade http://relishapp.com/rspec/rspec-mocks/v/2-5/file/upgrade http://relishapp.com/rspec/rspec-rails/v/2-5/file/upgrade > Our biggest issue though is that the memory reduction measures that we > added to the harmony gem are no longer working. Presumably this is > because RSpec 2 is hanging on to the variables somewhere that we cannot > find. Setting our harmony Page objects to nil is not working: > > # in the spec_helper Rspec.configure block: > config.after(:all) do > puts 'about to cleanup' > @dom = nil > GC.start # trying to cleanup via Ruby > puts Johnson.evaluate <<-JS > Johnson.runtime.gc(); // trying to cleanup via JS > JS > end > > We have tried a lot of ordering combinations in our garbage collection > to see if anything will work, but instead the memory is climbing out of > control with each suite. In version RSpec 1.x we didn't have to do any > manual garbage collection. Nor should you have to. Can you use after(:each) instead of after all? config.after(:each) { @dom = nil } From lists at ruby-forum.com Mon Feb 14 17:20:42 2011 From: lists at ruby-forum.com (Kane Baccigalupi) Date: Mon, 14 Feb 2011 23:20:42 +0100 Subject: [rspec-users] (Bad) Memory Leak in RSpec 2 In-Reply-To: <9207F571-91A5-4723-A900-8BE5725FFB6A@gmail.com> References: <9207F571-91A5-4723-A900-8BE5725FFB6A@gmail.com> Message-ID: <52ddc71861c2ac5a18a1fa7122c8d317@ruby-forum.com> David Chelimsky wrote in post #981651: I am happy to get back to you about the documentation a little later. I want to take the time to fully describe the problems we had. > Please let me know what is not yet documented on the following pages: > > http://relishapp.com/rspec/rspec-core/v/2-5/file/upgrade > http://relishapp.com/rspec/rspec-expectations/v/2-5/file/upgrade > http://relishapp.com/rspec/rspec-mocks/v/2-5/file/upgrade > http://relishapp.com/rspec/rspec-rails/v/2-5/file/upgrade > >> puts Johnson.evaluate <<-JS >> Johnson.runtime.gc(); // trying to cleanup via JS >> JS >> end >> >> We have tried a lot of ordering combinations in our garbage collection >> to see if anything will work, but instead the memory is climbing out of >> control with each suite. In version RSpec 1.x we didn't have to do any >> manual garbage collection. > > Nor should you have to. Can you use after(:each) instead of after all? > > config.after(:each) { @dom = nil } We set up our @dom in a before :all block and reuse it through out the file. We don't want to eliminate it after each test, just once per block/file/whatever we set up. The problem isn't that the block isn't getting called at the right time. The problem is that dereferencing the instance variable doesn't seem to be releasing the variable for garbage collection like it was happening in version 1.x. We don't know why, and what might be different about RSpec 2 variable references. More important, we are looking for a good solution, any solution, to the memory problem. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Feb 14 17:58:55 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Feb 2011 20:58:55 -0200 Subject: [rspec-users] (Bad) Memory Leak in RSpec 2 In-Reply-To: <52ddc71861c2ac5a18a1fa7122c8d317@ruby-forum.com> References: <9207F571-91A5-4723-A900-8BE5725FFB6A@gmail.com> <52ddc71861c2ac5a18a1fa7122c8d317@ruby-forum.com> Message-ID: <24B4F698-7B17-4F70-8192-85993EF6520D@gmail.com> On Feb 14, 2011, at 20:20, Kane Baccigalupi wrote: > David Chelimsky wrote in post #981651: > > I am happy to get back to you about the documentation a little later. I > want to take the time to fully describe the problems we had. Much appreciated. > >> Please let me know what is not yet documented on the following pages: >> >> http://relishapp.com/rspec/rspec-core/v/2-5/file/upgrade >> http://relishapp.com/rspec/rspec-expectations/v/2-5/file/upgrade >> http://relishapp.com/rspec/rspec-mocks/v/2-5/file/upgrade >> http://relishapp.com/rspec/rspec-rails/v/2-5/file/upgrade >> >>> puts Johnson.evaluate <<-JS >>> Johnson.runtime.gc(); // trying to cleanup via JS >>> JS >>> end >>> >>> We have tried a lot of ordering combinations in our garbage collection >>> to see if anything will work, but instead the memory is climbing out of >>> control with each suite. In version RSpec 1.x we didn't have to do any >>> manual garbage collection. >> >> Nor should you have to. Can you use after(:each) instead of after all? >> >> config.after(:each) { @dom = nil } > > We set up our @dom in a before :all block and reuse it through out the > file. We don't want to eliminate it after each test, just once per > block/file/whatever we set up. > > The problem isn't that the block isn't getting called at the right time. > The problem is that dereferencing the instance variable doesn't seem to > be releasing the variable for garbage collection like it was happening > in version 1.x. We don't know why, and what might be different about > RSpec 2 variable references. The instance vars in after(:all) are copies, so setting them to nil there has no real effect. This was true in rspec 1 as well, so what you are experiencing is unrelated. As a workaround, how about setting a global? Not a perm solution, but might get your suite working for the moment. > More important, we are looking for a good > solution, any solution, to the memory problem. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mmazur at gmail.com Mon Feb 14 18:00:19 2011 From: mmazur at gmail.com (Mike Mazur) Date: Tue, 15 Feb 2011 07:00:19 +0800 Subject: [rspec-users] stubbing out after_create AR method? In-Reply-To: References: Message-ID: Hi, On Tue, Feb 15, 2011 at 02:31, Fearless Fool wrote: > I have a Premise model with an after_create method, along the lines of: > > class Premise < ActiveRecord::Base > ?... > ?after_create :etl_attributes > ?... > end > > In production code, etl_attributes accesses the web. ?For testing I'm > using WebMock and VCR in cases where I want to test the etl_attributes > function -- works like a champ. > > For all other tests, I want to create a real Premise object (I need it > for HABTM associations), but I want to stub out the call to > etl_attributes. ?My problem is that I haven't figured out the right way > to do so. ?The following DOESN'T work (it should be clear that I'm using > FactoryGirl as well): > > ? ? ?mock_model(Premise) > ? ? ?Premise.stub!(:etl_attributes) > ? ? ?@premise = Factory.create(:premise) > > ... this still calls etl_attributes and WebMock gets appropriately mad. > > What am I missing? Perhaps one way to approach this is to have WebMock return an appropriate success message in response to the network call that :etl_attributes makes. Mike From lists at ruby-forum.com Mon Feb 14 18:39:01 2011 From: lists at ruby-forum.com (Kane Baccigalupi) Date: Tue, 15 Feb 2011 00:39:01 +0100 Subject: [rspec-users] (Bad) Memory Leak in RSpec 2 In-Reply-To: <24B4F698-7B17-4F70-8192-85993EF6520D@gmail.com> References: <9207F571-91A5-4723-A900-8BE5725FFB6A@gmail.com> <52ddc71861c2ac5a18a1fa7122c8d317@ruby-forum.com> <24B4F698-7B17-4F70-8192-85993EF6520D@gmail.com> Message-ID: <022ab7a018d7d85a7f5619f0a92de75c@ruby-forum.com> David Chelimsky wrote in post #981667: > The instance vars in after(:all) are copies, so setting them to nil > there has no real effect. This was true in rspec 1 as well, so what you > are experiencing is unrelated. > > As a workaround, how about setting a global? Not a perm solution, but > might get your suite working for the moment. We didn't have to release our @dom variable in version 1.x, whether the Harmony page object was defined in an :all or an :each block. The variable just got released for garbage collection on its own at the end of the file, and now it is not. Is it an impossibility to dereference these variables if they are defined initially in an :all block? We can try a global, but it isn't an ideal situation. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Feb 14 18:53:18 2011 From: lists at ruby-forum.com (Kane Baccigalupi) Date: Tue, 15 Feb 2011 00:53:18 +0100 Subject: [rspec-users] (Bad) Memory Leak in RSpec 2 In-Reply-To: <022ab7a018d7d85a7f5619f0a92de75c@ruby-forum.com> References: <9207F571-91A5-4723-A900-8BE5725FFB6A@gmail.com> <52ddc71861c2ac5a18a1fa7122c8d317@ruby-forum.com> <24B4F698-7B17-4F70-8192-85993EF6520D@gmail.com> <022ab7a018d7d85a7f5619f0a92de75c@ruby-forum.com> Message-ID: <1385c757623776f08ed8e6188c39210c@ruby-forum.com> Kane Baccigalupi wrote in post #981670: > We can try a global, but it isn't an ideal situation. So, we did replace @dom with $dom. That meant we could go back to doing no manual garbage collection, and in fact we didn't even have to set the global to nil between test files. Doesn't that imply that RSpec 2 is holding on to stuff that could lead to memory leaks in big tests for other folks too? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Feb 14 19:58:45 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Feb 2011 22:58:45 -0200 Subject: [rspec-users] (Bad) Memory Leak in RSpec 2 In-Reply-To: <1385c757623776f08ed8e6188c39210c@ruby-forum.com> References: <9207F571-91A5-4723-A900-8BE5725FFB6A@gmail.com> <52ddc71861c2ac5a18a1fa7122c8d317@ruby-forum.com> <24B4F698-7B17-4F70-8192-85993EF6520D@gmail.com> <022ab7a018d7d85a7f5619f0a92de75c@ruby-forum.com> <1385c757623776f08ed8e6188c39210c@ruby-forum.com> Message-ID: <273F7C57-6C20-4D41-BF1F-F37CF030D380@gmail.com> On Feb 14, 2011, at 21:53, Kane Baccigalupi wrote: > Kane Baccigalupi wrote in post #981670: > >> We can try a global, but it isn't an ideal situation. > > So, we did replace @dom with $dom. That meant we could go back to doing > no manual garbage collection, and in fact we didn't even have to set the > global to nil between test files. > > Doesn't that imply that RSpec 2 is holding on to stuff that could lead > to memory leaks in big tests for other folks too? Clearly. That's why I said "workaround" :) Would you do me a favor and submit an issue to http://github.com/rspec/rspec-core/issues? Thx, David From lists at ruby-forum.com Mon Feb 14 19:59:09 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Tue, 15 Feb 2011 01:59:09 +0100 Subject: [rspec-users] stubbing out after_create AR method? In-Reply-To: References: Message-ID: Mike Mazur wrote in post #981665: > Perhaps one way to approach this is to have WebMock return an > appropriate success message in response to the network call that > :etl_attributes makes. > > Mike Ah - good point. With all the options for stubbing and mocking, I'd forgotten that one. Factory Girl is creating premise objects that will generate different URLs, but I can use the regex option for WebMock to catch them. Thanks for getting me unstuck! - ff -- Posted via http://www.ruby-forum.com/. From andrei at andreimaxim.ro Tue Feb 15 06:11:23 2011 From: andrei at andreimaxim.ro (Andrei Maxim) Date: Tue, 15 Feb 2011 13:11:23 +0200 Subject: [rspec-users] Not loading RSpec::Rails::MailerExampleGroup Message-ID: Hi all, I'm working on Rails 3 application with ActiveRecord and ActionMailer stripped out (I've commented out the respective lines in config/application.rb), but I'm running into some problems when I'm running the specs either via the `rake spec` command or by running `autotest`. I could not find a way to tell RSpec to not load the ActionMailer-related modules and classes. Is there a setting in the configuration that will do that? Or is this a bug? Thanks, Andrei From dchelimsky at gmail.com Tue Feb 15 07:56:52 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Feb 2011 10:56:52 -0200 Subject: [rspec-users] Not loading RSpec::Rails::MailerExampleGroup In-Reply-To: References: Message-ID: On Feb 15, 2011, at 9:11 AM, Andrei Maxim wrote: > Hi all, > > I'm working on Rails 3 application with ActiveRecord and ActionMailer stripped out (I've commented out the respective lines in config/application.rb), but I'm running into some problems when I'm running the specs either via the `rake spec` command or by running `autotest`. > > I could not find a way to tell RSpec to not load the ActionMailer-related modules and classes. Is there a setting in the configuration that will do that? Or is this a bug? This was fixed in rspec-rails-2.5 (http://relishapp.com/rspec/rspec-rails/v/2-5/file/changelog). Cheers, David From andrei at andreimaxim.ro Tue Feb 15 08:50:14 2011 From: andrei at andreimaxim.ro (Andrei Maxim) Date: Tue, 15 Feb 2011 15:50:14 +0200 Subject: [rspec-users] Not loading RSpec::Rails::MailerExampleGroup References: Message-ID: On 2011-02-15 14:56:52 +0200, David Chelimsky said: > On Feb 15, 2011, at 9:11 AM, Andrei Maxim wrote: > >> I could not find a way to tell RSpec to not load the >> ActionMailer-related modules and classes. Is there a setting in the >> configuration that will do that? Or is this a bug? > > This was fixed in rspec-rails-2.5 > (http://relishapp.com/rspec/rspec-rails/v/2-5/file/changelog). > > Cheers, > David Very nice, thanks! Andrei From jeffdeville at gmail.com Tue Feb 15 10:22:29 2011 From: jeffdeville at gmail.com (JDeville) Date: Tue, 15 Feb 2011 07:22:29 -0800 (PST) Subject: [rspec-users] tcmalloc error running rspec spec using ree Message-ID: <74034268-551d-4805-a840-59c7fe28a7d2@d23g2000prj.googlegroups.com> I'm using ree via rvm. Everything was just installed. In autotest, the tests won't even start to run. When I run rspec spec, the tests will run, but will crash at some point here: src/tcmalloc.cc:390] Attempt to free invalid pointer: 0x10022d9a0 I'm not really sure where to look. Any recommendations? From chs at proactive.cc Tue Feb 15 11:35:58 2011 From: chs at proactive.cc (Christoph Schiessl) Date: Tue, 15 Feb 2011 17:35:58 +0100 Subject: [rspec-users] Stubbing Scopes Message-ID: Hi! I'm trying to test the following (simplified) model: class Allocation < ActiveRecord::Base scope :in_interval, (proc do |start_of_interval, end_of_interval| params = {:s => start_of_interval, :e => end_of_interval} where("(starts_at > :s AND starts_at < :e) OR (ends_at > :s AND ends_at < :e) OR (starts_at <= :s AND ends_at >= :e)", params) end) scope :on_day, (proc do |day| day = day.to_time.beginning_of_day in_interval(day, day + 1.day) end) # validations and other scopes... end I wrote a lot of specs for :in_interval - however testing :on_day is kind of problem. I don't want to duplicate any :in_interval specs - therefore I'm trying to stub :in_interval like this: let(:start_of_day) { Time.zone.now.beginning_of_day } it do Allocation.should_receive(:in_interval).with(start_of_day, start_of_day + 1.day).and_return("result") # working assertion - the :in_interval stub seems to get called as expected: # Allocation.on_day(start_of_day + 3.hours) # failing assertion: Allocation.on_day(start_of_day + 3.hours).should == "result" end RSpec Output: Failure/Error: Allocation.on_day(start_of_day + 3.hours).should == "result" NoMethodError: undefined method `includes_values' for "result":String I'm using Rails 3.0.4 and RSpec 2.5 (latest versions). Best regards, Christoph Schiessl From jko170 at gmail.com Tue Feb 15 12:51:03 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 15 Feb 2011 09:51:03 -0800 (PST) Subject: [rspec-users] Stubbing Scopes In-Reply-To: References: Message-ID: <89e67f8c-2047-46a9-8935-b318aba057a2@f36g2000pri.googlegroups.com> Your expectation (should_receive) is expecting "start_of_day", which uses Time.zone. The actual "on_day" scope does "day.to_time.beginning_of_day", which does not use any time zone. Therefore, the arguments to in_interval are not the same as the expectation. And because they are not the same, the mock does not get set. They must be exactly the same, since you are using a specific values. You are not seeing a "the in_interval method was not called" expectation ouput message because of the "includes_values" error. This is because RSpec is comparing "result" with an array. This is because Rails scopes return arrays, not strings (it is not returning a string because the mock was never set). Are you setting the time zone in a before block? Here are two really nice gems for dealing with Time sensitive code: https://github.com/jtrupiano/timecop https://github.com/bebanjo/delorean On Feb 15, 9:35?am, Christoph Schiessl wrote: > Hi! > > I'm trying to test the following (simplified) model: > > class Allocation < ActiveRecord::Base > ? scope :in_interval, (proc do |start_of_interval, end_of_interval| > ? ? params = {:s => start_of_interval, :e => end_of_interval} > ? ? where("(starts_at > :s AND starts_at < :e) OR (ends_at > :s AND ends_at < :e) OR (starts_at <= :s AND ends_at >= :e)", params) > ? end) > > ? scope :on_day, (proc do |day| > ? ? day = day.to_time.beginning_of_day > ? ? in_interval(day, day + 1.day) > ? end) > > ? # validations and other scopes... > end > > I wrote a lot of specs for :in_interval - however testing :on_day is kind of problem. I don't want to duplicate any :in_interval specs - therefore I'm trying to stub :in_interval like this: > > let(:start_of_day) { Time.zone.now.beginning_of_day } > it do > ? Allocation.should_receive(:in_interval).with(start_of_day, start_of_day + 1.day).and_return("result") > > ? # working assertion - the :in_interval stub seems to get called as expected: > ? # Allocation.on_day(start_of_day + 3.hours) > > ? # failing assertion: > ? Allocation.on_day(start_of_day + 3.hours).should == "result" > end > > RSpec Output: > > ? Failure/Error: Allocation.on_day(start_of_day + 3.hours).should == "result" > ? NoMethodError: > ? ? undefined method `includes_values' for "result":String > > I'm using Rails 3.0.4 and RSpec 2.5 (latest versions). > > Best regards, > Christoph Schiessl > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From chs at proactive.cc Tue Feb 15 13:14:06 2011 From: chs at proactive.cc (Christoph Schiessl) Date: Tue, 15 Feb 2011 19:14:06 +0100 Subject: [rspec-users] Stubbing Scopes In-Reply-To: <89e67f8c-2047-46a9-8935-b318aba057a2@f36g2000pri.googlegroups.com> References: <89e67f8c-2047-46a9-8935-b318aba057a2@f36g2000pri.googlegroups.com> Message-ID: <7AEAD8C9-3C6C-427B-A337-6A000F316A18@proactive.cc> Thanks for your suggestion Justin, but I don't believe that the problem is time zone related. Time objects usually don't "loose" their Time Zone when performing operations on them. Here's an example for illustration: $ rails console Loading development environment (Rails 3.0.4) ruby-1.8.7-p330 :001 > Time.zone.name => "Vienna" ruby-1.8.7-p330 :002 > t = Time.zone.now.beginning_of_month => Tue, 01 Feb 2011 00:00:00 CET +01:00 ruby-1.8.7-p330 :003 > t += 3.hours => Tue, 01 Feb 2011 03:00:00 CET +01:00 ruby-1.8.7-p330 :004 > t.beginning_of_day => Tue, 01 Feb 2011 00:00:00 CET +01:00 If the should_receive arguments and actual arguments wouldn't be the same, then I would expect both examples below to fail. context ".on_day" do let(:start_of_day) { Time.zone.now.beginning_of_day } before { Interval.should_receive(:in_interval).with(start_of_day, start_of_day + 1.day).and_return("result") } # (1) Passing example: it { Interval.on_day(start_of_day + 3.hours) } # (2) Failing example: it { Interval.on_day(start_of_day + 3.hours).should == "result" } end However, (1) is passing and (2) is failing. Output as before: >> Failure/Error: Allocation.on_day(start_of_day + 3.hours).should == "result" >> NoMethodError: >> undefined method `includes_values' for "result":String Any ideas? Best regards, Christoph Schiessl On Feb 15, 2011, at 18:51 , Justin Ko wrote: > Your expectation (should_receive) is expecting "start_of_day", which > uses Time.zone. The actual "on_day" scope does > "day.to_time.beginning_of_day", which does not use any time zone. > Therefore, the arguments to in_interval are not the same as the > expectation. And because they are not the same, the mock does not get > set. They must be exactly the same, since you are using a specific > values. > > You are not seeing a "the in_interval method was not called" > expectation ouput message because of the "includes_values" error. This > is because RSpec is comparing "result" with an array. This is because > Rails scopes return arrays, not strings (it is not returning a string > because the mock was never set). > > Are you setting the time zone in a before block? > > Here are two really nice gems for dealing with Time sensitive code: > https://github.com/jtrupiano/timecop > https://github.com/bebanjo/delorean > > On Feb 15, 9:35 am, Christoph Schiessl wrote: >> Hi! >> >> I'm trying to test the following (simplified) model: >> >> class Allocation < ActiveRecord::Base >> scope :in_interval, (proc do |start_of_interval, end_of_interval| >> params = {:s => start_of_interval, :e => end_of_interval} >> where("(starts_at > :s AND starts_at < :e) OR (ends_at > :s AND ends_at < :e) OR (starts_at <= :s AND ends_at >= :e)", params) >> end) >> >> scope :on_day, (proc do |day| >> day = day.to_time.beginning_of_day >> in_interval(day, day + 1.day) >> end) >> >> # validations and other scopes... >> end >> >> I wrote a lot of specs for :in_interval - however testing :on_day is kind of problem. I don't want to duplicate any :in_interval specs - therefore I'm trying to stub :in_interval like this: >> >> let(:start_of_day) { Time.zone.now.beginning_of_day } >> it do >> Allocation.should_receive(:in_interval).with(start_of_day, start_of_day + 1.day).and_return("result") >> >> # working assertion - the :in_interval stub seems to get called as expected: >> # Allocation.on_day(start_of_day + 3.hours) >> >> # failing assertion: >> Allocation.on_day(start_of_day + 3.hours).should == "result" >> end >> >> RSpec Output: >> >> Failure/Error: Allocation.on_day(start_of_day + 3.hours).should == "result" >> NoMethodError: >> undefined method `includes_values' for "result":String >> >> I'm using Rails 3.0.4 and RSpec 2.5 (latest versions). >> >> Best regards, >> Christoph Schiessl >> _______________________________________________ >> 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 jko170 at gmail.com Tue Feb 15 15:34:47 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 15 Feb 2011 12:34:47 -0800 (PST) Subject: [rspec-users] Stubbing Scopes In-Reply-To: <7AEAD8C9-3C6C-427B-A337-6A000F316A18@proactive.cc> References: <89e67f8c-2047-46a9-8935-b318aba057a2@f36g2000pri.googlegroups.com> <7AEAD8C9-3C6C-427B-A337-6A000F316A18@proactive.cc> Message-ID: On Feb 15, 11:14?am, Christoph Schiessl wrote: > Thanks for your suggestion Justin, but I don't believe that the problem is time zone related. Time objects usually don't "loose" their Time Zone when performing operations on them. Here's an example for illustration: > > $ rails console > Loading development environment (Rails 3.0.4) > ruby-1.8.7-p330 :001 > Time.zone.name > ?=> "Vienna" > ruby-1.8.7-p330 :002 > t = Time.zone.now.beginning_of_month > ?=> Tue, 01 Feb 2011 00:00:00 CET +01:00 > ruby-1.8.7-p330 :003 > t += 3.hours > ?=> Tue, 01 Feb 2011 03:00:00 CET +01:00 > ruby-1.8.7-p330 :004 > t.beginning_of_day > ?=> Tue, 01 Feb 2011 00:00:00 CET +01:00 > > If the should_receive arguments and actual arguments wouldn't be the same, then I would expect both examples below to fail. > > ? context ".on_day" do > ? ? let(:start_of_day) { Time.zone.now.beginning_of_day } > ? ? before { Interval.should_receive(:in_interval).with(start_of_day, start_of_day + 1.day).and_return("result") } > ? ? # (1) Passing example: > ? ? it { Interval.on_day(start_of_day + 3.hours) } > ? ? # (2) Failing example: > ? ? it { Interval.on_day(start_of_day + 3.hours).should == "result" } > ? end > > However, (1) is passing and (2) is failing. Output as before: > > >> ? Failure/Error: Allocation.on_day(start_of_day + 3.hours).should == "result" > >> ? NoMethodError: > >> ? ? undefined method `includes_values' for "result":String > > Any ideas? > > Best regards, > Christoph Schiessl > > On Feb 15, 2011, at 18:51 , Justin Ko wrote: > > > > > > > Your expectation (should_receive) is expecting "start_of_day", which > > uses Time.zone. The actual "on_day" scope does > > "day.to_time.beginning_of_day", which does not use any time zone. > > Therefore, the arguments to in_interval are not the same as the > > expectation. And because they are not the same, the mock does not get > > set. They must be exactly the same, since you are using a specific > > values. > > > You are not seeing a "the in_interval method was not called" > > expectation ouput message because of the "includes_values" error. This > > is because RSpec is comparing "result" with an array. This is because > > Rails scopes return arrays, not strings (it is not returning a string > > because the mock was never set). > > > Are you setting the time zone in a before block? > > > Here are two really nice gems for dealing with Time sensitive code: > >https://github.com/jtrupiano/timecop > >https://github.com/bebanjo/delorean > > > On Feb 15, 9:35 am, Christoph Schiessl wrote: > >> Hi! > > >> I'm trying to test the following (simplified) model: > > >> class Allocation < ActiveRecord::Base > >> ? scope :in_interval, (proc do |start_of_interval, end_of_interval| > >> ? ? params = {:s => start_of_interval, :e => end_of_interval} > >> ? ? where("(starts_at > :s AND starts_at < :e) OR (ends_at > :s AND ends_at < :e) OR (starts_at <= :s AND ends_at >= :e)", params) > >> ? end) > > >> ? scope :on_day, (proc do |day| > >> ? ? day = day.to_time.beginning_of_day > >> ? ? in_interval(day, day + 1.day) > >> ? end) > > >> ? # validations and other scopes... > >> end > > >> I wrote a lot of specs for :in_interval - however testing :on_day is kind of problem. I don't want to duplicate any :in_interval specs - therefore I'm trying to stub :in_interval like this: > > >> let(:start_of_day) { Time.zone.now.beginning_of_day } > >> it do > >> ? Allocation.should_receive(:in_interval).with(start_of_day, start_of_day + 1.day).and_return("result") > > >> ? # working assertion - the :in_interval stub seems to get called as expected: > >> ? # Allocation.on_day(start_of_day + 3.hours) > > >> ? # failing assertion: > >> ? Allocation.on_day(start_of_day + 3.hours).should == "result" > >> end > > >> RSpec Output: > > >> ? Failure/Error: Allocation.on_day(start_of_day + 3.hours).should == "result" > >> ? NoMethodError: > >> ? ? undefined method `includes_values' for "result":String > > >> I'm using Rails 3.0.4 and RSpec 2.5 (latest versions). > > >> Best regards, > >> Christoph Schiessl > >> _______________________________________________ > >> 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 Maybe because the scope is being called within a scope, it is wrapping it in an array: ["results"] Either way, report back what this code returns: it { raise Interval.on_day(start_of_day + 3.hours).inspect } From TTS at rainleader.com Tue Feb 15 20:43:37 2011 From: TTS at rainleader.com (Trenton Scott) Date: Tue, 15 Feb 2011 17:43:37 -0800 (PST) Subject: [rspec-users] RSpec Error - "Invalid Option" Message-ID: <03521a31-59f2-4c87-9886-5ac7e54dca58@o32g2000prb.googlegroups.com> I keep getting an issue when running RSpec with Autotest. My ~/.autotest file looks like this: ==FILE BEGINS== require 'autotest/growl' require 'autotest/fsevent' Autotest.add_hook :initialize do |autotest| autotest.add_mapping(/^spec\/requests\/.*_spec\.rb$/) do autotest.files_matching(/^spec\/requests\/.*_spec\.rb$/) end end ==FILE ENDS== Any thoughts on what I'm doing wrong? ==ERROR BEGINS== bundle exec /Users/TTS/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -S / Users/ TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.3.1/bin/rspec --tty '/ Users/TTS/Rails/sample_app/spec/controllers/pages_controller_spec.rb' '/Users/TTS/Rails/sample_app/spec/controllers/ sessions_controller_spec.rb' '/Users/TTS/Rails/sample_app/spec/ controllers/users_controller_spec.rb' '/Users/TTS/Rails/sample_app/ spec/models/user_spec.rb' '/Users/TTS/Rails/sample_app/spec/requests/ layout_links_spec.rb' '/Users/TTS/Rails/sample_app/spec/requests/ users_spec.rb' /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/rspec/ core/option_parser.rb:18:in `parse!': invalid option: --tty (OptionParser::InvalidOption) from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec- core-2.0.1/lib/ rspec/core/option_parser.rb:4:in `parse!' from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec- core-2.0.1/lib/ rspec/core/configuration_options.rb:64:in `parse_command_line_options' from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec- core-2.0.1/lib/ rspec/core/configuration_options.rb:46:in `parse_options' from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec- core-2.0.1/lib/ rspec/core/runner.rb:41:in `run' from /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec- core-2.0.1/lib/ rspec/core/runner.rb:10:in `block in autorun' ==ERROR ENDS== From lists at ruby-forum.com Wed Feb 16 00:54:43 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Wed, 16 Feb 2011 06:54:43 +0100 Subject: [rspec-users] stubbing gets undone? Message-ID: <77729a86a45422a8547fce65b21ba21a@ruby-forum.com> I'm looking at an example where a stub seems to work sometimes, and sometimes appears to become "unstubbed". I haven't boiled it down to a minimal example, but it goes something like this: ---- the model: class Premise << ActiveRecord::Base def lookup_stuff_on_the_web $stderr.puts("entering lookup_stuff_on_the_web with #{self}") ... end end ---- the rspec test file: describe Analysis do before(:each) do @premise = Factory(:premise) @premise.stub(:lookup_things_on_the_web) $stderr.puts("just stubbed #{@premise.inspect}") end it "should not hit the web" do @premise.lookup_things_on_the_web.should_not raise_exception end end ---- When I run the test, I see: just stubbed # entering lookup_stuff_on_the_web with # Failure/Error: ... WebMock::NetConnectNotAllowedError: As far as I can see, the Premise that's being stubbed and the Premise whose lookup_stuff_on_the_web method is getting called are one and the same. What I can't figure out is why the stub isn't being honored. (FWIW, the same setup code is working in other tests.) Are there any known gotchas I should be looking for? Or specific things I should try to uncover the cause? TIA. - ff -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Feb 16 01:09:31 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Wed, 16 Feb 2011 07:09:31 +0100 Subject: [rspec-users] stubbing gets undone? In-Reply-To: <77729a86a45422a8547fce65b21ba21a@ruby-forum.com> References: <77729a86a45422a8547fce65b21ba21a@ruby-forum.com> Message-ID: <4ee571de3148b6f3cb3019cc96af9e46@ruby-forum.com> Hmm - when I print puts(premise) rather than puts(premise.inspect), I can see that they actually have different addresses, so they're not really equal: just stubbed # entering lookup_stuff_on_the_web with # Now my problem is figuring out why/where the other Premise is getting created. In other words, move along...nothing to see here. :) - ff -- Posted via http://www.ruby-forum.com/. From scott at railsnewbie.com Wed Feb 16 01:51:46 2011 From: scott at railsnewbie.com (Scott Taylor) Date: Wed, 16 Feb 2011 01:51:46 -0500 Subject: [rspec-users] stubbing gets undone? In-Reply-To: <77729a86a45422a8547fce65b21ba21a@ruby-forum.com> References: <77729a86a45422a8547fce65b21ba21a@ruby-forum.com> Message-ID: <4EDDC70B-3644-4BEC-B0A8-981B7FF360C2@railsnewbie.com> Is #unstub being called at any point? Scott On Feb 16, 2011, at 12:54 AM, Fearless Fool wrote: > I'm looking at an example where a stub seems to work sometimes, and > sometimes appears to become "unstubbed". I haven't boiled it down to a > minimal example, but it goes something like this: > ---- the model: > class Premise << ActiveRecord::Base > def lookup_stuff_on_the_web > $stderr.puts("entering lookup_stuff_on_the_web with #{self}") > ... > end > end > ---- the rspec test file: > describe Analysis do > before(:each) do > @premise = Factory(:premise) > @premise.stub(:lookup_things_on_the_web) > $stderr.puts("just stubbed #{@premise.inspect}") > end > > it "should not hit the web" do > @premise.lookup_things_on_the_web.should_not raise_exception > end > end > ---- > When I run the test, I see: > > just stubbed # > entering lookup_stuff_on_the_web with # > Failure/Error: ... > WebMock::NetConnectNotAllowedError: > > As far as I can see, the Premise that's being stubbed and the Premise > whose lookup_stuff_on_the_web method is getting called are one and the > same. What I can't figure out is why the stub isn't being honored. > (FWIW, the same setup code is working in other tests.) > > Are there any known gotchas I should be looking for? Or specific things > I should try to uncover the cause? > > TIA. > > - ff > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Feb 16 02:53:08 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 16 Feb 2011 05:53:08 -0200 Subject: [rspec-users] RSpec Error - "Invalid Option" In-Reply-To: <03521a31-59f2-4c87-9886-5ac7e54dca58@o32g2000prb.googlegroups.com> References: <03521a31-59f2-4c87-9886-5ac7e54dca58@o32g2000prb.googlegroups.com> Message-ID: <2E9AAEF6-5822-42D3-8A05-522C5E467CF2@gmail.com> On Feb 15, 2011, at 11:43 PM, Trenton Scott wrote: > I keep getting an issue when running RSpec with Autotest. My > ~/.autotest file looks like this: > Any thoughts on what I'm doing wrong? > ==ERROR BEGINS== > bundle exec /Users/TTS/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -S / > Users/ > TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.3.1/bin/rspec --tty > '/ ^^ rspec-core-2.3.1 ^^ > Users/TTS/Rails/sample_app/spec/controllers/pages_controller_spec.rb' > '/Users/TTS/Rails/sample_app/spec/controllers/ > sessions_controller_spec.rb' '/Users/TTS/Rails/sample_app/spec/ > controllers/users_controller_spec.rb' '/Users/TTS/Rails/sample_app/ > spec/models/user_spec.rb' '/Users/TTS/Rails/sample_app/spec/requests/ > layout_links_spec.rb' '/Users/TTS/Rails/sample_app/spec/requests/ > users_spec.rb' > /Users/TTS/.rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.0.1/lib/rspec/ > core/option_parser.rb:18:in `parse!': invalid option: --tty ^^ rspec-core-2.0.1 ^^ See Gotchas section on http://relishapp.com/rspec/rspec-core/v/2-5/file/autotest for an explanation and solution. Cheers, David From lists at ruby-forum.com Wed Feb 16 14:37:45 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Wed, 16 Feb 2011 20:37:45 +0100 Subject: [rspec-users] stubbing gets undone? In-Reply-To: <4EDDC70B-3644-4BEC-B0A8-981B7FF360C2@railsnewbie.com> References: <77729a86a45422a8547fce65b21ba21a@ruby-forum.com> <4EDDC70B-3644-4BEC-B0A8-981B7FF360C2@railsnewbie.com> Message-ID: Scott Taylor wrote in post #981963: > Is #unstub being called at any point? > Scott No, but I think I see what's happening: I'm stubbing a particular (in-memory) instance of an AR. Later on in my code, the same AR is fetched, but now has a different in-memory address, and thus isn't subject to stubbing. (Is my analysis plausible?) So my new question is: can I stub Premise#lookup_stuff_on_the_web for all objects? (I could just set up WebMock to return a specific response, but it's a complex data structure and it would be much cleaner to stub Premise#lookup_stuff_on_the_web instead.) - ff -- Posted via http://www.ruby-forum.com/. From threadhead at gmail.com Wed Feb 16 17:07:50 2011 From: threadhead at gmail.com (Karl Smith) Date: Wed, 16 Feb 2011 15:07:50 -0700 Subject: [rspec-users] TypeError: can't convert RSpec::Mocks::Mock to Hash Message-ID: # controller def create @money_order = current_user.money_orders.build(params[:money_order]) if @money_order.save @money_orders = current_user.money_orders.staged flash.now[:msg_ok] = "Added money order for: #{number_to_currency(@money_order.amount)}" end respond_with(@money_order) end #controller spec describe "POST create" do describe "with valid params" do it "assigns a newly created money_order as @money_order" do MoneyOrder.stub(:new).with({'these' => 'params'}) { mock_money_order(:save => true) } post :create, :money_order => {'these' => 'params'} assigns(:money_order).should be(mock_money_order) end end end #returns this error Failure/Error: post :create, :money_order => {'these' => 'params'} TypeError: can't convert RSpec::Mocks::Mock to Hash (RSpec::Mocks::Mock#to_hash gives RSpec::Mocks::Mock) #gems rails (3.0.4) rspec (2.5.0) rspec-core (2.5.1) rspec-expectations (2.5.0) rspec-mocks (2.5.0) rspec-rails (2.5.0) ... and a few others Must be missing something simple, but I just don't see it. What is causing the error? From codehacker at comcast.net Wed Feb 16 18:31:46 2011 From: codehacker at comcast.net (LesNightingill) Date: Wed, 16 Feb 2011 15:31:46 -0800 (PST) Subject: [rspec-users] Order of execution of specs Message-ID: ...trying to debug some interaction between my model specs, a particular spec passes by itself but fails when I run all my model specs. I can't figure out how the execution sequence is performed when I do spec spec/models. Does anybody know what the criterion is for the execution sequence? thanks in advance Les From threadhead at gmail.com Tue Feb 15 12:25:51 2011 From: threadhead at gmail.com (Karl) Date: Tue, 15 Feb 2011 09:25:51 -0800 (PST) Subject: [rspec-users] TypeError: can't convert RSpec::Mocks::Mock to Hash Message-ID: <4b042b2f-b04e-481c-bca8-2c551eafd0a9@y36g2000pra.googlegroups.com> In MoneyOrdersController controller: def create @money_order = current_user.money_orders.build(params[:money_order]) if @money_order.save flash.now[:msg_ok] = "Added money order for: #{number_to_currency(@money_order.amount)}" end respond_with(@money_order) end In MoneyOrdersController spec: describe "POST create" do describe "with valid params" do it "assigns a newly created money_order as @money_order" do MoneyOrder.stub(:new).with({'these' => 'params'}) { mock_money_order(:save => true) } post :create, :money_order => {'these' => 'params'} assigns(:money_order).should be(mock_money_order) end end It always throws this error: Failure/Error: post :create, :money_order => {'these' => 'params'} TypeError: can't convert RSpec::Mocks::Mock to Hash (RSpec::Mocks::Mock#to_hash gives RSpec::Mocks::Mock) I'm sure the reason is simple, why I am getting this TypeError? From yurokle at gmail.com Wed Feb 16 07:24:45 2011 From: yurokle at gmail.com (Yuriy Naidyon) Date: Wed, 16 Feb 2011 14:24:45 +0200 Subject: [rspec-users] [rspec-rails] Exception catching in controller Message-ID: Hi folks. I'm currently using rspec-2.4.0 and rspec-rails-2.4.1. In the controller I have the code like this (at least at two different places): def some_action raise Exception if some_falsy_value rescue @message = 'Error' end but when I do testing with rspec this exception doesn't proceeded by controller, and I'm getting the following: 1) SignupsController GET confirm_email should proceed unexpected errors Failure/Error: get :confirm_email, @params Exception: Exception # ./app/controllers/signups_controller.rb:251:in `confirm_email' # ./spec/controllers/signups_controller_spec.rb:168:in `block (3 levels) in ' I saw in examples that we can do exceptions catching by contoller filters like (rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found) but I don't want to use this way, con my exceptions aren't controller wide, they only related to some single action. Also, it's my first email to mailing group, if I composed it incorrectly, someone please let me know. Yuriy -------------- next part -------------- An HTML attachment was scrubbed... URL: From ajvargo at gmail.com Wed Feb 16 09:34:42 2011 From: ajvargo at gmail.com (Andrew Vargo) Date: Wed, 16 Feb 2011 06:34:42 -0800 (PST) Subject: [rspec-users] it_behaves_like and running single examples Message-ID: Hello, I am running rspec 2 and rails 3 in a project. When I have a shared example being used in a spec file, I loose the ability to run a single test in that file. rspec spec/controllers/proposals_controller_spec.rb:13 for instance will always give me a green '..', even if I put uparsable junk in that example like it "should choke" do asdfasdfasdfasfd end Running the file w/o the line number works ace. When I remove the shared example line: it_behaves_like "...", all goes back to normal. Any thoughts? Even if where to start diagnosing it? My shared example is in a rb file in spec/support. Thanks, Andrew From wagner.andrew at gmail.com Thu Feb 17 08:10:59 2011 From: wagner.andrew at gmail.com (Andrew Wagner) Date: Thu, 17 Feb 2011 08:10:59 -0500 Subject: [rspec-users] it_behaves_like and running single examples In-Reply-To: References: Message-ID: To diagnose this, I would start to try to isolate the problem as much as possible. Get it all the way down to one file, outside of rails, with one test that exemplifies the behavior, if need be. And if you get to that point and still see the strangeness...send us a pastebin of it :) On Wed, Feb 16, 2011 at 9:34 AM, Andrew Vargo wrote: > Hello, > > I am running rspec 2 and rails 3 in a project. > > When I have a shared example being used in a spec file, I loose the > ability to run a single test in that file. > rspec spec/controllers/proposals_controller_spec.rb:13 for instance > will always give me a green '..', even if I put uparsable junk in that > example like > it "should choke" do > asdfasdfasdfasfd > end > > Running the file w/o the line number works ace. > > When I remove the shared example line: it_behaves_like "...", all goes > back to normal. > > Any thoughts? Even if where to start diagnosing it? My shared > example is in a rb file in spec/support. > > Thanks, > Andrew > _______________________________________________ > 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 groups at inbox.avdi.org Thu Feb 17 09:36:22 2011 From: groups at inbox.avdi.org (Avdi Grimm) Date: Thu, 17 Feb 2011 09:36:22 -0500 Subject: [rspec-users] [rspec-rails] Exception catching in controller In-Reply-To: References: Message-ID: On Wed, Feb 16, 2011 at 7:24 AM, Yuriy Naidyon wrote: > def some_action > ??raise Exception if some_falsy_value > rescue > ??@message = 'Error' > end Don't raise Exception. Raise some descendant of StandardError, like RuntimeError (the default if you don't specify a class) or (even better) your own StandardError-derived exception class. A straight-up exception will bypass all default "rescue" clauses and in general indicates that something has gone badly wrong and the program should end. -- Avdi Grimm http://avdi.org From jko170 at gmail.com Thu Feb 17 11:46:11 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 17 Feb 2011 08:46:11 -0800 (PST) Subject: [rspec-users] [rspec-rails] Exception catching in controller In-Reply-To: References: Message-ID: On Feb 17, 7:36?am, Avdi Grimm wrote: > On Wed, Feb 16, 2011 at 7:24 AM, Yuriy Naidyon wrote: > > def some_action > > ??raise Exception if some_falsy_value > > rescue > > ??@message = 'Error' > > end > > Don't raise Exception. Raise some descendant of StandardError, like > RuntimeError (the default if you don't specify a class) or (even > better) your own StandardError-derived exception class. > > A straight-up exception will bypass all default "rescue" clauses and > in general indicates that something has gone badly wrong and the > program should end. > > -- > Avdi Grimmhttp://avdi.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users "A straight-up exception will bypass all default "rescue" clauses" - I learn something everyday! From jko170 at gmail.com Thu Feb 17 12:57:10 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 17 Feb 2011 09:57:10 -0800 (PST) Subject: [rspec-users] it_behaves_like and running single examples In-Reply-To: References: Message-ID: <4bfa3127-0b42-49e1-8d19-a73441c9d1bb@q2g2000pre.googlegroups.com> On Feb 16, 7:34?am, Andrew Vargo wrote: > Hello, > > I am running rspec 2 and rails 3 in a project. > > When I have a shared example being used in a spec file, I loose the > ability to run a single test in that file. > rspec spec/controllers/proposals_controller_spec.rb:13 ?for instance > will always give me a green '..', even if I put uparsable junk in that > example like > it "should choke" do > ? asdfasdfasdfasfd > end > > Running the file w/o the line number works ace. > > When I remove the shared example line: it_behaves_like "...", all goes > back to normal. > > Any thoughts? ?Even if where to start diagnosing it? ?My shared > example is in a rb file in spec/support. > > Thanks, > Andrew > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users Since there is no code for us to look at, the best I can recommend for you is to use the "-e" or "--example" option instead of the line number option. Example: describe User do context "that is invalid" do it "has an error" do end end end rspec spec/models/user_spec.rb -e "that is invalid" rspec spec/models/user_spec.rb -e "has an error" Hope that helps. From jko170 at gmail.com Thu Feb 17 16:07:08 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 17 Feb 2011 13:07:08 -0800 (PST) Subject: [rspec-users] Order of execution of specs In-Reply-To: References: Message-ID: On Feb 16, 4:31?pm, LesNightingill wrote: > ...trying to debug some interaction between my model specs, a > particular spec passes by itself but fails when I run all my model > specs. Whenever this happens to me, 90% of the time the cause of the problem is database state. The state of the database is different for that particular spec when you run it singularly versus with the suite. I would suggest starting there. Hope that helps. I can't figure out how the execution sequence is performed when > I do spec spec/models. Does anybody know what the criterion is for the > execution sequence? > > thanks in advance > > Les > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From groups at inbox.avdi.org Thu Feb 17 21:34:35 2011 From: groups at inbox.avdi.org (Avdi Grimm) Date: Thu, 17 Feb 2011 21:34:35 -0500 Subject: [rspec-users] [rspec-rails] Exception catching in controller In-Reply-To: References: Message-ID: On Thu, Feb 17, 2011 at 11:46 AM, Justin Ko wrote: > "A straight-up exception will bypass all default "rescue" clauses" - I > learn something everyday! If you will forgive a brief moment of self-promotion, I recently posted an entire talk I did on Ruby exception handling: http://avdi.org/devblog/exceptional-ruby/ Cheers, -- Avdi Grimm http://avdi.org From mdemetrios at gmail.com Thu Feb 17 16:59:34 2011 From: mdemetrios at gmail.com (Meltemi) Date: Thu, 17 Feb 2011 13:59:34 -0800 (PST) Subject: [rspec-users] New, clueless, confused...and thinking JQuery+MongoID is breaking my template code examples... Message-ID: If this is the wrong forum for this type of question please let me know...I don't want to ruffle any feathers... I've been teaching myself RSpec and quite enjoying the 'new' book...but as I try to put it into practice I get tripped up. Now, this may not be RSpec's fault. I'm also relatively new to Rails and MongoDB and HAML and... I realize this is a long question but probably a very easy answer...if you're familiar with all the pieces. Warning: it will probably require downloading a really basic (1 scaffold) project from github so don't bother reading further if you don't have the time or will... That said. I'm just trying to get a stable platform from which to 'grow' upon. And as I slowly put together my 'kit' I watch my boilerplate (template) specs at each turn. Now they're failing and I want to know why before I continue. Seems reasonable...but I've exhausted my resources...so looking for some insight. Short of a "here's the answer to your problem and now the template specs all pass" I'm also looking for approaches as to how to begin troubleshooting this for myself. Failed specs are great and largely informative but I'm not sure, yet, how to dig deeper...so though this issue may not be RSpec's 'fault' I'd like to know how to interpret the failures so I can uncover the 'failure'...if that makes any sense?!? What I've done is create a new project: $ rails new destroid -T -O # yes, dumb name but initially my issue was with resource_controller.spec.rb#destroy. And, in hindsight I should probably have used the -J flag. though same "problem" seems to exist regardless... then installed RSpec and MongoID... (yes, built similar project w/out MongoID and tests all pass...so I *think* MongoDB (or MongoID) may have something to do with my problem though I don't know how/where and won't see failures until after jquery:install) then... $ rails g scaffold resource name:string refactor the (also poorly named) controller (resources_controller.rb) to utilize respond_with (resources_controller.rb.with). (though not sure now that this has anything to do with it...though appeal of respond_with is what's led me to dig into this issue). $ rspec spec tests all pass then... $ rails generate jquery:install and 3 of the template code examples now fail...and I'm not sure why? If I switch back to the scaffold installed RESTful controller (resources_controller.rb.default) the code examples *still* fail...so issue apparently not (as I had originally thought) with 'responds_with'. anyway, my code (useless project only for my troubleshooting purposes) is on github should anyone who is familiar with all these pieces want to help a poor sod learn a thing or two... it will require MongoID as with standard SQL there doesn't seem to be a problem. best. From jko170 at gmail.com Sat Feb 19 01:49:37 2011 From: jko170 at gmail.com (Justin Ko) Date: Fri, 18 Feb 2011 22:49:37 -0800 (PST) Subject: [rspec-users] [rspec-rails] Exception catching in controller In-Reply-To: References: Message-ID: <121ba38c-5776-47e9-9834-0152be69fad4@u23g2000pro.googlegroups.com> On Feb 17, 7:34?pm, Avdi Grimm wrote: > On Thu, Feb 17, 2011 at 11:46 AM, Justin Ko wrote: > > "A straight-up exception will bypass all default "rescue" clauses" - I > > learn something everyday! > > If you will forgive a brief moment of self-promotion, I recently > posted an entire talk I did on Ruby exception handling:http://avdi.org/devblog/exceptional-ruby/ > > Cheers, > -- > Avdi Grimmhttp://avdi.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users @Avdi - watched the whole video, great stuff! From rodrigo3n at gmail.com Sun Feb 20 14:54:28 2011 From: rodrigo3n at gmail.com (Rodrigo Alves Vieira) Date: Sun, 20 Feb 2011 13:54:28 -0600 Subject: [rspec-users] What are all available config options? Message-ID: Hello everyone, what are all the configuration options available for the .rspec file? Currently I only know --colour. Thanks! Rodrigo Alves Vieira http://rodrigo3n.com | http://github.com/rodrigo3n | http://linkedin.com/in/rodrigo3n | http://twitter.com/rodrigo3n -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Sun Feb 20 17:10:25 2011 From: jko170 at gmail.com (Justin Ko) Date: Sun, 20 Feb 2011 14:10:25 -0800 (PST) Subject: [rspec-users] What are all available config options? In-Reply-To: References: Message-ID: On Feb 20, 12:54?pm, Rodrigo Alves Vieira wrote: > Hello everyone, what are all the configuration options available for the > .rspec file? Currently I only know --colour. > > Thanks! > > Rodrigo Alves Vieirahttp://rodrigo3n.com|http://github.com/rodrigo3n|http://linkedin.com/in/rodrigo3n |http://twitter.com/rodrigo3n > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users Hello! Please run the following command: rspec --help From lists at ruby-forum.com Sun Feb 20 18:12:48 2011 From: lists at ruby-forum.com (Samantha John) Date: Mon, 21 Feb 2011 00:12:48 +0100 Subject: [rspec-users] rspec not loading rails files- uninitialized constant error Message-ID: <7153371fd91835e21ba3ca841d3f5bc5@ruby-forum.com> I am new to rspec. I followed a few tutorials and set it up to test my existing rails project. I ran the rspec generators and created spec/user_spec.rb to test my user.rb model. The user.rb file starts with: class User < ActiveRecord::Base The user_spec.rb file starts with: describe User do When I run the test (using rake spec, bundle exec autotest, rspec spec/user_spec.rb ) I get the error: `const_missing': uninitialized constant User (NameError) within the following trace: loading autotest/rspec2 bundle exec /Users/Sam/.rvm/rubies/ruby-1.8.7-p330/bin/ruby -S /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/bin/rspec --tty '/Users/Sam/Documents/Development/Friend-Mapper/friend_mapper_rails/spec/user_spec.rb' /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/backward_compatibility.rb:20:in `const_missing': uninitialized constant User (NameError) from /Users/Sam/Documents/Development/Friend-Mapper/friend_mapper_rails/spec/user_spec.rb:1 from /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/configuration.rb:386:in `load' from /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/configuration.rb:386:in `load_spec_files' from /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/configuration.rb:386:in `map' from /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/configuration.rb:386:in `load_spec_files' from /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/command_line.rb:18:in `run' from /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/runner.rb:55:in `run_in_process' from /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/runner.rb:46:in `run' from /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/runner.rb:10:in `autorun' from /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/bin/rspec:4 I tried a sample app (http://relishapp.com/rspec/file/twominutetutorial) which worked fine. I suspect that the issue is that rspec is not loading up the files from my rails project. Which configurations do I need to fix for this to work? Thanks! -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Feb 20 19:01:44 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 20 Feb 2011 21:01:44 -0300 Subject: [rspec-users] rspec not loading rails files- uninitialized constant error In-Reply-To: <7153371fd91835e21ba3ca841d3f5bc5@ruby-forum.com> References: <7153371fd91835e21ba3ca841d3f5bc5@ruby-forum.com> Message-ID: On Feb 20, 2011, at 8:12 PM, Samantha John wrote: > I am new to rspec. Welcome! > I followed a few tutorials and set it up to test my > existing rails project. I ran the rspec generators and created > spec/user_spec.rb to test my user.rb model. > > The user.rb file starts with: > > class User < ActiveRecord::Base > > > The user_spec.rb file starts with: > > describe User do > > When I run the test (using rake spec, bundle exec autotest, rspec > spec/user_spec.rb ) > I get the error: > > `const_missing': uninitialized constant User (NameError) > > within the following trace: > > loading autotest/rspec2 > bundle exec /Users/Sam/.rvm/rubies/ruby-1.8.7-p330/bin/ruby -S > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/bin/rspec > --tty > '/Users/Sam/Documents/Development/Friend-Mapper/friend_mapper_rails/spec/user_spec.rb' > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/backward_compatibility.rb:20:in > `const_missing': uninitialized constant User (NameError) > from > /Users/Sam/Documents/Development/Friend-Mapper/friend_mapper_rails/spec/user_spec.rb:1 > from > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/configuration.rb:386:in > `load' > from > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/configuration.rb:386:in > `load_spec_files' > from > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/configuration.rb:386:in > `map' > from > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/configuration.rb:386:in > `load_spec_files' > from > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/command_line.rb:18:in > `run' > from > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/runner.rb:55:in > `run_in_process' > from > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/runner.rb:46:in > `run' > from > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/lib/rspec/core/runner.rb:10:in > `autorun' > from > /Users/Sam/.rvm/gems/ruby-1.8.7-p330/bundler/gems/rspec-core-011b1ce34016/bin/rspec:4 > > I tried a sample app (http://relishapp.com/rspec/file/twominutetutorial) > which worked fine. I suspect that the issue is that rspec is not loading > up the files from my rails project. Which configurations do I need to > fix for this to work? When you run the rspec:install generator, it creates a spec/spec_helper.rb file that loads the Rails environment. This file needs to be required from your user_spec.rb file, which should be spec/models/user_spec.rb, not spec/user_spec.rb. HTH, David From lists at ruby-forum.com Sun Feb 20 19:07:59 2011 From: lists at ruby-forum.com (Samantha John) Date: Mon, 21 Feb 2011 01:07:59 +0100 Subject: [rspec-users] rspec not loading rails files- uninitialized constant error In-Reply-To: <7153371fd91835e21ba3ca841d3f5bc5@ruby-forum.com> References: <7153371fd91835e21ba3ca841d3f5bc5@ruby-forum.com> Message-ID: <9bf2f3901cfa7ebec0eb696d55c4c4a9@ruby-forum.com> Additional info: Rails 3.0.3 Ruby 1.8.7 Gemfile: gem "rspec-rails", ">= 2.0.0.beta.10", :git => "git://github.com/rspec/rspec-rails.git" gem "rspec", ">= 2.0.0.beta.10", :git => "git://github.com/rspec/rspec.git" gem "rspec-core", ">= 2.0.0.beta.10", :git => "git://github.com/rspec/rspec-core.git" gem "rspec-expectations", ">= 2.0.0.beta.10", :git => "git://github.com/rspec/rspec-expectations.git" gem "rspec-mocks", ">= 2.0.0.beta.10", :git => "git://github.com/rspec/rspec-mocks.git" -- Posted via http://www.ruby-forum.com/. From jko170 at gmail.com Sun Feb 20 19:35:10 2011 From: jko170 at gmail.com (Justin Ko) Date: Sun, 20 Feb 2011 16:35:10 -0800 (PST) Subject: [rspec-users] rspec not loading rails files- uninitialized constant error In-Reply-To: <9bf2f3901cfa7ebec0eb696d55c4c4a9@ruby-forum.com> References: <7153371fd91835e21ba3ca841d3f5bc5@ruby-forum.com> <9bf2f3901cfa7ebec0eb696d55c4c4a9@ruby-forum.com> Message-ID: <912ea363-569e-4a21-a4cb-0c062957995e@q40g2000prh.googlegroups.com> On Feb 20, 5:07?pm, Samantha John wrote: > Additional info: > > Rails 3.0.3 > Ruby 1.8.7 > > Gemfile: > gem "rspec-rails", ? ? ? ?">= 2.0.0.beta.10", :git => > "git://github.com/rspec/rspec-rails.git" > gem "rspec", ? ? ? ? ? ? ?">= 2.0.0.beta.10", :git => > "git://github.com/rspec/rspec.git" > gem "rspec-core", ? ? ? ? ">= 2.0.0.beta.10", :git => > "git://github.com/rspec/rspec-core.git" > gem "rspec-expectations", ">= 2.0.0.beta.10", :git => > "git://github.com/rspec/rspec-expectations.git" > gem "rspec-mocks", ? ? ? ?">= 2.0.0.beta.10", :git => > "git://github.com/rspec/rspec-mocks.git" > > -- > Posted viahttp://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users Hi Samantha, since you're using Rails, you'll need to run the "rspec rails installer". Take a look at the "Configure" section on this page: http://relishapp.com/rspec/rspec-rails Let us know if that works. From jko170 at gmail.com Sun Feb 20 19:40:06 2011 From: jko170 at gmail.com (Justin Ko) Date: Sun, 20 Feb 2011 16:40:06 -0800 (PST) Subject: [rspec-users] TypeError: can't convert RSpec::Mocks::Mock to Hash In-Reply-To: <4b042b2f-b04e-481c-bca8-2c551eafd0a9@y36g2000pra.googlegroups.com> References: <4b042b2f-b04e-481c-bca8-2c551eafd0a9@y36g2000pra.googlegroups.com> Message-ID: <17f9d0fc-4b61-46bf-ab25-1518a15d9a1f@y31g2000prd.googlegroups.com> On Feb 15, 10:25?am, Karl wrote: > In MoneyOrdersController controller: > > def create > ? @money_order = current_user.money_orders.build(params[:money_order]) > ? if @money_order.save > ? ? flash.now[:msg_ok] = "Added money order for: > #{number_to_currency(@money_order.amount)}" > ? end > ? respond_with(@money_order) > end > > In MoneyOrdersController spec: > > describe "POST create" do > ? describe "with valid params" do > ? ? it "assigns a newly created money_order as @money_order" do > ? ? ? MoneyOrder.stub(:new).with({'these' => 'params'}) > { mock_money_order(:save => true) } > ? ? ? post :create, :money_order => {'these' => 'params'} > ? ? ? assigns(:money_order).should be(mock_money_order) > ? ? end > end > > It always throws this error: > > Failure/Error: post :create, :money_order => {'these' => 'params'} > TypeError: > ? ?can't convert RSpec::Mocks::Mock to Hash > (RSpec::Mocks::Mock#to_hash gives RSpec::Mocks::Mock) > > I'm sure the reason is simple, why I am getting this TypeError? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users Hmmm....what is the "mock_money_order" method doing? Care to paste it? From daniel.amselem at gmail.com Mon Feb 21 07:18:17 2011 From: daniel.amselem at gmail.com (Daniel Salmeron Amselem) Date: Mon, 21 Feb 2011 04:18:17 -0800 (PST) Subject: [rspec-users] object_instance.reload and print out a message placed in the model Message-ID: <17303913.925.1298290697348.JavaMail.geo-discussion-forums@yqmi40> I'm trying to test this with Ruby 1.9.2, RSpec 2.5.0, and Rails 3.0.4: context "toggle_resource method" do it "should remove the resource from the group" do group = Factory(:unique_group) user = Factory(:unique_user, :account => group.account) group.add_resource(user) group.reload group.should have(1).users group.toggle_resource(user) group.reload group.should have(0).users end end and I had to add 'group.reload' in order to make this thing work. I would appreciate if anyone could explain to me why do I need to do it, and why I can't see a message that it's in the model, something like the following: def add_resource(resource) p "HEY" GroupResource.create(:resource => resource, :group => self) end The message "HEY" doesn't appear in the console after running 'rspec spec/models/group_spec.rb'. Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Mon Feb 21 13:29:54 2011 From: lists at ruby-forum.com (Samantha John) Date: Mon, 21 Feb 2011 19:29:54 +0100 Subject: [rspec-users] rspec not loading rails files- uninitialized constant error In-Reply-To: <7153371fd91835e21ba3ca841d3f5bc5@ruby-forum.com> References: <7153371fd91835e21ba3ca841d3f5bc5@ruby-forum.com> Message-ID: <179b8c43b9d64b8869e8e3bd3c829afe@ruby-forum.com> Thanks David, this was exactly what I needed. Per your advice I have moved user_spec.rb to the model, I was experimenting with moving it around to see if that would change anything. Thanks again, rspec is a really nice piece of software. Sam -- Posted via http://www.ruby-forum.com/. From curtis.schofield at gmail.com Mon Feb 21 14:45:35 2011 From: curtis.schofield at gmail.com (Curtis j Schofield) Date: Mon, 21 Feb 2011 11:45:35 -0800 Subject: [rspec-users] Rspec is swallowing undefined methods in it's method_missing and looping forever Message-ID: Has anyone else encountered this? It will end up printing this : 1) Applications Scribd api requests should always be private Failure/Error: Unable to find matching line from backtrace SystemStackError: stack level too deep # /Users/o_o/.rvm/gems/ruby-1.9.2-p0 at capr3 /gems/rspec-expectations-2.5.0/lib/rspec/matchers/method_missing.rb:7 We noticed this. Curtis Schofield & Anita Kuno -- make haste slowly \ festina lente \ - mobile +1_415_632_6001 curtis at robotarmyma.de http://robotarmyma.de -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Mon Feb 21 20:25:28 2011 From: jko170 at gmail.com (Justin Ko) Date: Mon, 21 Feb 2011 18:25:28 -0700 Subject: [rspec-users] object_instance.reload and print out a message placed in the model In-Reply-To: <17303913.925.1298290697348.JavaMail.geo-discussion-forums@yqmi40> References: <17303913.925.1298290697348.JavaMail.geo-discussion-forums@yqmi40> Message-ID: On Mon, Feb 21, 2011 at 5:18 AM, Daniel Salmeron Amselem < daniel.amselem at gmail.com> wrote: > I'm trying to test this with Ruby 1.9.2, RSpec 2.5.0, and Rails 3.0.4: > > context "toggle_resource method" do > it "should remove the resource from the group" do > group = Factory(:unique_group) > user = Factory(:unique_user, :account => group.account) > > group.add_resource(user) > group.reload > group.should have(1).users > > group.toggle_resource(user) > group.reload > group.should have(0).users > end > end > > and I had to add 'group.reload' in order to make this thing work. I would > appreciate if anyone could explain to me why do I need to do it, and why I > can't see a message that it's in the model, something like the following: > > def add_resource(resource) > p "HEY" > GroupResource.create(:resource => resource, :group => self) > end > > The message "HEY" doesn't appear in the console after running 'rspec > spec/models/group_spec.rb'. Thanks in advance. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users You have to call "reload" to clear activerecord caches. Destroying an associated record does not affect the cache. One way you could write your spec is like this: expect { group.add_resource(user) }.to change(group, :users).by(1) expect { group.toggle_resource(user) }.to change(group, :users).by(-1) Let us know if that works for you. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmymartin at gmail.com Tue Feb 22 06:13:19 2011 From: jimmymartin at gmail.com (James Martin) Date: Tue, 22 Feb 2011 22:13:19 +1100 Subject: [rspec-users] Stubbing Sleep Message-ID: I've recently been playing around with some code that re-runs a block until either the block returns a non-false value, or a timeout expires: https://gist.github.com/838520 At first, I thought this was working, as I was just checking the timing of the examples when returning a true value, however, now it looks like sleep isn't being stubbed as I expect. In the final example, the output from RSpec shows the time taken is 1 second, even though it's sleeping for at least the full 10 seconds specified in the first argument to #do_this. I can kind of imagine this not working at all, as the code relies on calculations between two instances of Time.now. Is there a better way to do this? I'm really keen to get away from the whole Time.now/sleep combination in my tests if possible. I was thinking that perhaps a virtual clock would be better, but then I've still got the sleep issue to deal with. Thanks, James. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Feb 22 10:19:07 2011 From: lists at ruby-forum.com (Peter Schrammel) Date: Tue, 22 Feb 2011 16:19:07 +0100 Subject: [rspec-users] Stubbed static methods are bleeding over into other specs and making them fail Message-ID: rspec (1.3.1) rspec-rails (1.3.3) rails (2.3.3) Hi, there was another thread with this topic but with rspec 2.0 so I'll start a new one for the "old" branch. I have a workling class (working with method missing on "async_"). When I stub an async call: Catalog::PublisherWorker.should_receive(:async_update).with(....) The old method missing is not available in the following specs: undefined method `async_update' for Object:Class So I think the old class behavior is not reset correctly. Can anybody confirm this? Or even help ? THX Peter -- Posted via http://www.ruby-forum.com/. From daniel.amselem at gmail.com Tue Feb 22 12:08:22 2011 From: daniel.amselem at gmail.com (=?UTF-8?Q?Daniel_Salmer=C3=B3n_Amselem?=) Date: Tue, 22 Feb 2011 18:08:22 +0100 Subject: [rspec-users] object_instance.reload and print out a message placed in the model In-Reply-To: References: <17303913.925.1298290697348.JavaMail.geo-discussion-forums@yqmi40> Message-ID: Thanks, I'll try that. I just have the feeling ActiveRecord caches are being a pain in the ass. For example, the toggle_resource method removes or adds a resource to a group, and when just after that I check the resources on that group, I still get the same ones before the toggle_resource method was called. I had to change "self.resources" to "self.resources.all" in order to force Activerecord to update the cache. Is there any way I can test this weird behavior? I would love if I could understand better the way ARel works. On Tue, Feb 22, 2011 at 2:25 AM, Justin Ko wrote: > > > On Mon, Feb 21, 2011 at 5:18 AM, Daniel Salmeron Amselem < > daniel.amselem at gmail.com> wrote: > >> I'm trying to test this with Ruby 1.9.2, RSpec 2.5.0, and Rails 3.0.4: >> >> context "toggle_resource method" do >> it "should remove the resource from the group" do >> group = Factory(:unique_group) >> user = Factory(:unique_user, :account => group.account) >> >> group.add_resource(user) >> group.reload >> group.should have(1).users >> >> group.toggle_resource(user) >> group.reload >> group.should have(0).users >> end >> end >> >> and I had to add 'group.reload' in order to make this thing work. I would >> appreciate if anyone could explain to me why do I need to do it, and why I >> can't see a message that it's in the model, something like the following: >> >> def add_resource(resource) >> p "HEY" >> GroupResource.create(:resource => resource, :group => self) >> end >> >> The message "HEY" doesn't appear in the console after running 'rspec >> spec/models/group_spec.rb'. Thanks in advance. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > You have to call "reload" to clear activerecord caches. Destroying an > associated record does not affect the cache. > > One way you could write your spec is like this: > > expect { group.add_resource(user) }.to change(group, :users).by(1) > expect { group.toggle_resource(user) }.to change(group, :users).by(-1) > > Let us know if that works for you. Thanks. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- > You received this message because you are subscribed to the Google Groups > "rspec" group. > To post to this group, send email to rspec at googlegroups.com. > To unsubscribe from this group, send email to > rspec+unsubscribe at googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rspec?hl=en. > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Tue Feb 22 12:23:04 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 22 Feb 2011 10:23:04 -0700 Subject: [rspec-users] object_instance.reload and print out a message placed in the model In-Reply-To: References: <17303913.925.1298290697348.JavaMail.geo-discussion-forums@yqmi40> Message-ID: On Tue, Feb 22, 2011 at 10:08 AM, Daniel Salmer?n Amselem < daniel.amselem at gmail.com> wrote: > Thanks, I'll try that. I just have the feeling ActiveRecord caches are > being a pain in the ass. For example, the toggle_resource method removes or > adds a resource to a group, and when just after that I check the resources > on that group, I still get the same ones before the toggle_resource method > was called. I had to change "self.resources" to "self.resources.all" in > order to force Activerecord to update the cache. > > Is there any way I can test this weird behavior? I would love if I could > understand better the way ARel works. > > > > On Tue, Feb 22, 2011 at 2:25 AM, Justin Ko wrote: > >> >> >> On Mon, Feb 21, 2011 at 5:18 AM, Daniel Salmeron Amselem < >> daniel.amselem at gmail.com> wrote: >> >>> I'm trying to test this with Ruby 1.9.2, RSpec 2.5.0, and Rails 3.0.4: >>> >>> context "toggle_resource method" do >>> it "should remove the resource from the group" do >>> group = Factory(:unique_group) >>> user = Factory(:unique_user, :account => group.account) >>> >>> group.add_resource(user) >>> group.reload >>> group.should have(1).users >>> >>> group.toggle_resource(user) >>> group.reload >>> group.should have(0).users >>> end >>> end >>> >>> and I had to add 'group.reload' in order to make this thing work. I would >>> appreciate if anyone could explain to me why do I need to do it, and why I >>> can't see a message that it's in the model, something like the following: >>> >>> def add_resource(resource) >>> p "HEY" >>> GroupResource.create(:resource => resource, :group => self) >>> end >>> >>> The message "HEY" doesn't appear in the console after running 'rspec >>> spec/models/group_spec.rb'. Thanks in advance. >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> You have to call "reload" to clear activerecord caches. Destroying an >> associated record does not affect the cache. >> >> One way you could write your spec is like this: >> >> expect { group.add_resource(user) }.to change(group, :users).by(1) >> expect { group.toggle_resource(user) }.to change(group, :users).by(-1) >> >> Let us know if that works for you. Thanks. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> -- >> You received this message because you are subscribed to the Google Groups >> "rspec" group. >> To post to this group, send email to rspec at googlegroups.com. >> To unsubscribe from this group, send email to >> rspec+unsubscribe at googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/rspec?hl=en. >> >> >> > You can call "self.resources.reload" rather than "self.resources.all". As far testing those methods, the "expect { }.to change().by()" functionality should do the trick. Let us know if it works or not. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mguterl at gmail.com Tue Feb 22 14:37:47 2011 From: mguterl at gmail.com (Michael Guterl) Date: Tue, 22 Feb 2011 14:37:47 -0500 Subject: [rspec-users] Stubbing Sleep In-Reply-To: References: Message-ID: On Tue, Feb 22, 2011 at 6:13 AM, James Martin wrote: > I've recently been playing around with some code that re-runs a block until > either the block returns a non-false value, or a timeout expires: > https://gist.github.com/838520 > At first, I thought this was working, as I was just checking the timing of > the examples when returning a true value, however, now it looks like sleep > isn't being stubbed as I expect. > In the final example, the output from RSpec shows the time taken is 1 > second, even though it's sleeping for at least the full 10 seconds specified > in the first argument to #do_this. > I can kind of imagine this not working at all, as the code relies on > calculations between two instances of Time.now. > Is there a better way to do this? > I'm really keen to get away from the whole Time.now/sleep combination in my > tests if possible. I was thinking that perhaps a virtual clock would be > better, but then I've still got the sleep issue to deal with. > Eric Hodel recently blogged about this: http://blog.segment7.net/2011/01/06/how-to-sleep-in-tests Best, Michael Guterl From jason.nah at gmail.com Tue Feb 22 21:35:50 2011 From: jason.nah at gmail.com (Jason Nah) Date: Wed, 23 Feb 2011 13:35:50 +1100 Subject: [rspec-users] Rake generate - not generating spec files Message-ID: Howdy, I'm running the following stack: - rails 3.0.4 - - rake (0.8.7) - rspec 2.5.0 - rspec-rails 2.5.0 I created the rails app, and I didn't tell rails to exclude the default Test mechanisms. I installed it using rails generate rspec:install When I type rake g model User I get this: invoke active_record create db/migrate/20110223022101_create_users.rb create app/models/user.rb invoke test_unit create test/unit/user_test.rb create test/fixtures/users.yml No specs. When I type rake -T I don't see any spec targets. When I run rake spec, nothing happens. Is there something I've missed? Cheers, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Feb 22 21:38:49 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Feb 2011 20:38:49 -0600 Subject: [rspec-users] Rake generate - not generating spec files In-Reply-To: References: Message-ID: On Feb 22, 2011, at 8:35 PM, Jason Nah wrote: > Howdy, > > I'm running the following stack: > rails 3.0.4 > rake (0.8.7) > rspec 2.5.0 > rspec-rails 2.5.0 > I created the rails app, and I didn't tell rails to exclude the default Test mechanisms. > > I installed it using > > rails generate rspec:install > > When I type > rake g model User > > I get this: > invoke active_record > create db/migrate/20110223022101_create_users.rb > create app/models/user.rb > invoke test_unit > create test/unit/user_test.rb > create test/fixtures/users.yml > > No specs. > > When I type > rake -T > > I don't see any spec targets. > > When I run rake spec, nothing happens. > > > Is there something I've missed? Is rspec-rails in your Gemfile? group :test, :development do gem "rspec-rails", "~> 2.5" end -------------- next part -------------- An HTML attachment was scrubbed... URL: From thecatwasnot at gmail.com Tue Feb 22 21:46:00 2011 From: thecatwasnot at gmail.com (Pixel) Date: Tue, 22 Feb 2011 20:46:00 -0600 Subject: [rspec-users] Rake generate - not generating spec files In-Reply-To: References: Message-ID: On Tue, Feb 22, 2011 at 8:35 PM, Jason Nah wrote: > Howdy, > I'm running the following stack: > > rails 3.0.4 > rake (0.8.7) > rspec 2.5.0 > rspec-rails 2.5.0 > > I created the rails app, and I didn't tell rails to exclude the default Test > mechanisms. > I installed it using > rails generate rspec:install > When I type > rake g model User I've got a similar stack to yours. I've always run 'rails g model User' (note rails not rake) but if I try 'rake g' it spits out an error, so if you're running the rails script instead, I could be wrong. > I get this: > ?? ? ?invoke ?active_record > ?? ? ?create ? ?db/migrate/20110223022101_create_users.rb > ?? ? ?create ? ?app/models/user.rb > ?? ? ?invoke ? ?test_unit > ?? ? ?create ? ? ?test/unit/user_test.rb > ?? ? ?create ? ? ?test/fixtures/users.yml > No specs. > When I type > rake -T > I don't see any spec targets. > When I run rake spec, nothing happens. > Is rspec-rails in both your :test and :development groups in your Gemfile? It needs to be in :development to provide the rake tasks and generators. See David's blog [1] for more info. > Is there something I've missed? > Cheers, > Jason > -Cole [1] http://blog.davidchelimsky.net/tag/generators/ From jimmymartin at gmail.com Tue Feb 22 22:13:28 2011 From: jimmymartin at gmail.com (James Martin) Date: Wed, 23 Feb 2011 14:13:28 +1100 Subject: [rspec-users] Stubbing Sleep In-Reply-To: References: Message-ID: Thanks, Michael: That's a useful article. I attempted to emulate the example in RSpec but still found that stubbing sleep with any of the built in rspec-mocks wasn't working the way I hoped. I was probably doing something wrong. In the end I wrote a little module (Sleepy) that I can include in RSpec.configure, which adds the #within method to the DSL. So now I can say something like this: RSpec.configure do |c| c.include(Sleepy) end describe "some long running method" do it "takes no longer than thirty seconds to do its work" do within 30.seconds do some_long_running_method.should do_what_we_expect end end end And yes; I committed horrible atrocities duck punching Fixnum and Float to get the syntax reading nicely! :) I suppose what I really wanted to be able to say was something like: some_long_running_method.should_eventually do_what_we_expect And be able to configure the maximum timeout of #should_eventually Anyway, if this looks interesting or helpful for someone else I'll throw it in a Gist. Cheers, James. On Wed, Feb 23, 2011 at 6:37 AM, Michael Guterl wrote: > > > Eric Hodel recently blogged about this: > http://blog.segment7.net/2011/01/06/how-to-sleep-in-tests > > Best, > Michael Guterl > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Feb 23 08:23:03 2011 From: lists at ruby-forum.com (DI d.) Date: Wed, 23 Feb 2011 14:23:03 +0100 Subject: [rspec-users] Error Testing a view in RSpec 2 In-Reply-To: <2eff9aff-febb-48e2-b152-f5a2a7c0a21b@k10g2000yqa.googlegroups.com> References: <2eff9aff-febb-48e2-b152-f5a2a7c0a21b@k10g2000yqa.googlegroups.com> Message-ID: Rafael Felix wrote in post #949668: > > I don't know what method we use to check my views? > > thanks for all > regards if you want to test views with have_tag and rspec2 try this gem: https://rubygems.org/gems/rspec2-rails-views-matchers -- Posted via http://www.ruby-forum.com/. From daniel.amselem at gmail.com Wed Feb 23 08:47:30 2011 From: daniel.amselem at gmail.com (Daniel Salmeron Amselem) Date: Wed, 23 Feb 2011 05:47:30 -0800 (PST) Subject: [rspec-users] object_instance.reload and print out a message placed in the model In-Reply-To: Message-ID: <1442056.1608.1298468850243.JavaMail.geo-discussion-forums@vbhw19> That seems to work Justin, thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tmilewski at gmail.com Wed Feb 23 10:29:50 2011 From: tmilewski at gmail.com (Tom Milewski) Date: Wed, 23 Feb 2011 07:29:50 -0800 (PST) Subject: [rspec-users] Validations aren't being performed when running 'rspec spec' Message-ID: <1e67c7bb-27fc-46f7-8c24-698c12af814c@a8g2000pri.googlegroups.com> Hello, When I run 'rspec spec/models' everything runs beautifully. When I run 'rspec spec/controllers' everything also runs beautifully. When I run 'rspec spec' the models seem to forget that the records need to pass the validations before being saved to the database. This is consistent across all model tests which are checking validations. Model: validates_presence_of :name, :location, :email... Test: it "should ensure that name is present" do Factory.build(:public_agent, :name => nil).should have(1).error_on(:name) end All of these tests do not return errors and do add the invalid records to the database. Has anyone else had this happen? Suggestions? Thanks! From shamaoke at hotmail.com Thu Feb 24 01:35:51 2011 From: shamaoke at hotmail.com (Shamaoke) Date: Wed, 23 Feb 2011 22:35:51 -0800 (PST) Subject: [rspec-users] RSpec doesn't see the DATA constant Message-ID: <8b7dd53e-3b0d-4daa-8c9f-1acf72917c58@8g2000prt.googlegroups.com> Hi. In Ruby there's the `DATA` constant which contains the lines following the `__END__` keyword in the source file. For some reason RSpec doesn't see it. Here's the example: ~~~ # data_spec.rb requre 'rspec' describe 'DATA' do it 'contains lines following the __END__ keyword' do DATA.read.should == "Hello from underground!\n" end end __END__ Hello from underground! ~~~ If then I run `$ rspec data_spec.rb`, I'm getting 'NameError: uninitialized constant RSpec::Core::ExampleGroup::Nested_1::DATA'. However, if I use `$ ruby data_spec.rb` all works fine. Why RSpec doesn't see the constant when I use the `rspec` command? How can I solve the problem? Thanks. Debian GNU/Linux 5.0.7; Ruby 1.9.2; RSpec 2.5.0. From cdemyanovich at gmail.com Thu Feb 24 08:48:33 2011 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Thu, 24 Feb 2011 08:48:33 -0500 Subject: [rspec-users] Validations aren't being performed when running 'rspec spec' In-Reply-To: <1e67c7bb-27fc-46f7-8c24-698c12af814c@a8g2000pri.googlegroups.com> References: <1e67c7bb-27fc-46f7-8c24-698c12af814c@a8g2000pri.googlegroups.com> Message-ID: On Wed, Feb 23, 2011 at 10:29 AM, Tom Milewski wrote: > Model: > > validates_presence_of :name, :location, :email... > > Test: > > it "should ensure that name is present" do > Factory.build(:public_agent, :name => nil).should > have(1).error_on(:name) > end > > All of these tests do not return errors and do add the invalid records > to the database. > > Has anyone else had this happen? Suggestions? Though I'm still using RSpec 1, I do use FactoryGirl. Factory.build only instantiates a new record; it does not save it. Thus, the example that you shared should not create a record. Are you sure that the invalid records that you're seeing in the database are from this example? Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Feb 24 08:48:53 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Feb 2011 07:48:53 -0600 Subject: [rspec-users] Validations aren't being performed when running 'rspec spec' In-Reply-To: <1e67c7bb-27fc-46f7-8c24-698c12af814c@a8g2000pri.googlegroups.com> References: <1e67c7bb-27fc-46f7-8c24-698c12af814c@a8g2000pri.googlegroups.com> Message-ID: <44B33905-71D0-4913-920B-7B3C1E095071@gmail.com> On Feb 23, 2011, at 9:29 AM, Tom Milewski wrote: > Hello, > > When I run 'rspec spec/models' everything runs beautifully. > When I run 'rspec spec/controllers' everything also runs beautifully. > When I run 'rspec spec' the models seem to forget that the records > need to pass the validations before being saved to the database. > > This is consistent across all model tests which are checking > validations. > > Model: > > validates_presence_of :name, :location, :email... > > Test: > > it "should ensure that name is present" do > Factory.build(:public_agent, :name => nil).should have(1).error_on(:name) Factory.build ^^ doesn't even save records to the database in the first place, so it would be surprising if this were the example that is causing trouble. Do you have any other specs besides models and controllers? helpers, mailers, requests, etc? I've seen cases in which data was set up in before(:all) (which does not run in a transaction and is therefore not rolled back), and uniqueness validations would fail in other places. What specific failure messages are you seeing? > end > > All of these tests do not return errors and do add the invalid records > to the database. > > Has anyone else had this happen? Suggestions? > > Thanks! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From lists at ruby-forum.com Thu Feb 24 12:55:18 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Thu, 24 Feb 2011 18:55:18 +0100 Subject: [rspec-users] ordering dependency in tests? Message-ID: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> I'm baffled. If I do: $ bundle exec ruby -S rspec --tty A_spec.rb $ bundle exec ruby -S rspec --tty B_spec.rb I get no errors. But then if I do: $ bundle exec ruby -S rspec --tty A_spec.rb B_spec.rb I get an error on B_spec. And if I reverse the order: $ bundle exec ruby -S rspec --tty B_spec.rb A_spec.rb I get an entirely different error on A_spec. I swear that I'm not doing any before(:all) anywhere, but clearly there's some state that is persisting between the two spec files. I've tried inserting $stderr.puts() messages to gain some insight as to what's happening, but they seem to be suppressed (is that expected?). So: any ideas of gotchas to look out for? In the meantime, I'm going to start commenting out blocks of tests in A_spec and see when B_spec stops failing. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Feb 24 13:09:20 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Feb 2011 12:09:20 -0600 Subject: [rspec-users] ordering dependency in tests? In-Reply-To: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> References: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> Message-ID: <3EC9459E-37CD-478F-B35A-80A8F42DA930@gmail.com> On Feb 24, 2011, at 11:55 AM, Fearless Fool wrote: > I'm baffled. If I do: > > $ bundle exec ruby -S rspec --tty A_spec.rb > $ bundle exec ruby -S rspec --tty B_spec.rb > > I get no errors. But then if I do: > > $ bundle exec ruby -S rspec --tty A_spec.rb B_spec.rb > > I get an error on B_spec. And if I reverse the order: > > $ bundle exec ruby -S rspec --tty B_spec.rb A_spec.rb > > I get an entirely different error on A_spec. What are the failures you're seeing? > I swear that I'm not doing > any before(:all) anywhere, but clearly there's some state that is > persisting between the two spec files. I've tried inserting > $stderr.puts() messages to gain some insight as to what's happening, but > they seem to be suppressed (is that expected?). > > So: any ideas of gotchas to look out for? > > In the meantime, I'm going to start commenting out blocks of tests in > A_spec and see when B_spec stops failing. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From patmaddox at me.com Thu Feb 24 13:29:15 2011 From: patmaddox at me.com (Pat Maddox) Date: Thu, 24 Feb 2011 10:29:15 -0800 Subject: [rspec-users] ordering dependency in tests? In-Reply-To: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> References: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> Message-ID: cattr_accessor, class vars / class instance vars, constants, globals...all things that maintain state across test runs, and so could lead to errors like this. I'd start looking there. Pat On Feb 24, 2011, at 9:55 AM, Fearless Fool wrote: > I'm baffled. If I do: > > $ bundle exec ruby -S rspec --tty A_spec.rb > $ bundle exec ruby -S rspec --tty B_spec.rb > > I get no errors. But then if I do: > > $ bundle exec ruby -S rspec --tty A_spec.rb B_spec.rb > > I get an error on B_spec. And if I reverse the order: > > $ bundle exec ruby -S rspec --tty B_spec.rb A_spec.rb > > I get an entirely different error on A_spec. I swear that I'm not doing > any before(:all) anywhere, but clearly there's some state that is > persisting between the two spec files. I've tried inserting > $stderr.puts() messages to gain some insight as to what's happening, but > they seem to be suppressed (is that expected?). > > So: any ideas of gotchas to look out for? > > In the meantime, I'm going to start commenting out blocks of tests in > A_spec and see when B_spec stops failing. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Feb 24 13:36:48 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Thu, 24 Feb 2011 19:36:48 +0100 Subject: [rspec-users] ordering dependency in tests? In-Reply-To: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> References: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> Message-ID: A little additional information: every time I run the tests, it creates a new PremiseGroup model. Shouldn't the db get rolled back between tests? Here is PremiseGroup, listed here in its entirety: class PremiseGroup < ActiveRecord::Base has_many :premise_group_members, :dependent => :destroy has_many :premises, :through => :premise_group_members RESIDENTIAL = self.create(:name => "residential") end When I put in a debugging statement: before(:each) do $stderr.puts("PremiseGroup count = #{PremiseGroup.count}" end ... it reports that there are 151 PremiseGroups, then 152 on the next run, then 153 on the next. Naturally, calling 'rake db:test:prepare' resets it, but shouldn't the database be rolled back between tests regardless? I'm not 100% sure this is the cause of my problems, but it smells like it... -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Feb 24 13:37:06 2011 From: lists at ruby-forum.com (Costi G.) Date: Thu, 24 Feb 2011 19:37:06 +0100 Subject: [rspec-users] RSpec doesn't see the DATA constant In-Reply-To: <8b7dd53e-3b0d-4daa-8c9f-1acf72917c58@8g2000prt.googlegroups.com> References: <8b7dd53e-3b0d-4daa-8c9f-1acf72917c58@8g2000prt.googlegroups.com> Message-ID: <0a429777e191829e4b2649ee3b80f9ae@ruby-forum.com> P. A. wrote in post #983523: > Hi. > > In Ruby there's the `DATA` constant which contains the lines following > the `__END__` keyword in the source file. For some reason RSpec > doesn't see it. > > Here's the example: > > ~~~ > # data_spec.rb > > requre 'rspec' > > describe 'DATA' do > it 'contains lines following the __END__ keyword' do > DATA.read.should == "Hello from underground!\n" > end > end > > __END__ > Hello from underground! > ~~~ > > If then I run `$ rspec data_spec.rb`, I'm getting 'NameError: > uninitialized constant RSpec::Core::ExampleGroup::Nested_1::DATA'. > However, if I use `$ ruby data_spec.rb` all works fine. DATA works only on the first file called by the interpreter. first.rb: require 'second' second.rb: p DATA.read __END__ BAM! ruby first.rb ./second.rb:1: uninitialized constant DATA (NameError) from first.rb:1:in `require' from first.rb:1 ruby second.rb "BAM!\n" > > Why RSpec doesn't see the constant when I use the `rspec` command? How > can I solve the problem? The restriction on DATA notwithstanding, DATA in that context will by ambiguous. Think about it, is the DATA from the rspec file or the DATA from the tested file? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Feb 24 13:44:44 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Thu, 24 Feb 2011 19:44:44 +0100 Subject: [rspec-users] ordering dependency in tests? In-Reply-To: <3EC9459E-37CD-478F-B35A-80A8F42DA930@gmail.com> References: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> <3EC9459E-37CD-478F-B35A-80A8F42DA930@gmail.com> Message-ID: <933b9ae02fb9ac81f40a112e8cc79171@ruby-forum.com> David Chelimsky wrote in post #983675: > On Feb 24, 2011, at 11:55 AM, Fearless Fool wrote: > What are the failures you're seeing? When running A before B, B's assertion that: @common_options[:premise_group].premises.size.should == 3 fails because premise_group.premises.size == 5 (even though only 3 premises have been created). When running B before A, A's assertion that: e1.ranking(premises[0]).should be_within(0.0001).of(0.0) fails because a call to sort() fails because there is a nil in some list that ought to be a Float. (I haven't dug deeper into that one.) But to reiterate, either tests completes without error when run alone. Still digging... - ff -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Feb 24 13:48:59 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Feb 2011 12:48:59 -0600 Subject: [rspec-users] ordering dependency in tests? In-Reply-To: References: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> Message-ID: <20801DFA-FBC5-4529-8CC2-AC2C55680C2D@gmail.com> On Feb 24, 2011, at 12:36 PM, Fearless Fool wrote: > A little additional information: every time I run the tests, it creates > a new PremiseGroup model. Shouldn't the db get rolled back between > tests? > > Here is PremiseGroup, listed here in its entirety: > > class PremiseGroup < ActiveRecord::Base > has_many :premise_group_members, :dependent => :destroy > has_many :premises, :through => :premise_group_members > RESIDENTIAL = self.create(:name => "residential") ^^ this is probably the problem ^^ This line creates a new record in the database every time premise_group.rb is evaluated by the Ruby interpreter. This happens as the app is being bootstrapped and outside any transactions controlled by the Rails testing infrastructure (which RSpec sits on top of). Options include making that a method instead of a const: def self.residential find_or_create_by_name(:name => "residential") end HTH, David > end > > When I put in a debugging statement: > > before(:each) do > $stderr.puts("PremiseGroup count = #{PremiseGroup.count}" > end > > ... it reports that there are 151 PremiseGroups, then 152 on the next > run, then 153 on the next. Naturally, calling 'rake db:test:prepare' > resets it, but shouldn't the database be rolled back between tests > regardless? I'm not 100% sure this is the cause of my problems, but it > smells like it... > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Feb 24 13:53:09 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Thu, 24 Feb 2011 19:53:09 +0100 Subject: [rspec-users] ordering dependency in tests? In-Reply-To: <933b9ae02fb9ac81f40a112e8cc79171@ruby-forum.com> References: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> <3EC9459E-37CD-478F-B35A-80A8F42DA930@gmail.com> <933b9ae02fb9ac81f40a112e8cc79171@ruby-forum.com> Message-ID: yet more info... The two errors appear to be closely related. When run as individual files, PremiseGroup#premises is returning expected values. When run together, premise_group.premises returns "phantom" premises (which show up as nil values). For test B, the phantoms causes the count to be wrong. For test A, the nil values cause nils to show up in a list that is passed to sort(). I'm still baffled, but I must be closer to the answer. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Feb 24 13:58:03 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Thu, 24 Feb 2011 19:58:03 +0100 Subject: [rspec-users] ordering dependency in tests? In-Reply-To: <20801DFA-FBC5-4529-8CC2-AC2C55680C2D@gmail.com> References: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> <20801DFA-FBC5-4529-8CC2-AC2C55680C2D@gmail.com> Message-ID: <09060460e3c51137f85894c24cfaead5@ruby-forum.com> David Chelimsky wrote in post #983690: >> RESIDENTIAL = self.create(:name => "residential") > ^^ this is probably the problem ^^ > ... Ah! got it. FWIW, I wrote a query to the Rails group several months ago wondering if this construct was legit and got feedback that it was legit. Your explanation makes good sense. I'll change that and see what happens. If you don't hear back from me, assume it's working! ;) And thanks in advance. - ff -- Posted via http://www.ruby-forum.com/. From tmilewski at gmail.com Thu Feb 24 14:07:35 2011 From: tmilewski at gmail.com (Tom Milewski) Date: Thu, 24 Feb 2011 11:07:35 -0800 (PST) Subject: [rspec-users] Validations aren't being performed when running 'rspec spec' In-Reply-To: <44B33905-71D0-4913-920B-7B3C1E095071@gmail.com> References: <1e67c7bb-27fc-46f7-8c24-698c12af814c@a8g2000pri.googlegroups.com> <44B33905-71D0-4913-920B-7B3C1E095071@gmail.com> Message-ID: Thanks for the replies. Here's the error I'm seeing when running all specs (.build and .create): Agent while creating should ensure that name is present Failure/Error: Factory(:public_agent, :name => nil).should have(1).error_on(:name) expected 1 error on :name, got 0 # ./spec/models/agent_spec.rb:35:in `block (3 levels) in ' Here's what I'm seeing when running model specs with .create: Agent while creating should ensure that name is present Failure/Error: Factory(:public_agent, :name => nil).should have(1).error_on(:name) ActiveRecord::RecordInvalid: Validation failed: Name can't be blank # ./spec/models/agent_spec.rb:35:in `block (3 levels) in ' Everything passes when running model specs with .build. Thanks again! On Feb 24, 8:48?am, David Chelimsky wrote: > On Feb 23, 2011, at 9:29 AM, Tom Milewski wrote: > > > > > > > > > > > Hello, > > > When I run 'rspec spec/models' everything runs beautifully. > > When I run 'rspec spec/controllers' everything also runs beautifully. > > When I run 'rspec spec' the models seem to forget that the records > > need to pass the validations before being saved to the database. > > > This is consistent across all model tests which are checking > > validations. > > > Model: > > > validates_presence_of :name, :location, :email... > > > Test: > > > it "should ensure that name is present" do > > ? ? ?Factory.build(:public_agent, :name => nil).should have(1).error_on(:name) > > Factory.build ^^ doesn't even save records to the database in the first place, so it would be surprising if this were the example that is causing trouble. > > Do you have any other specs besides models and controllers? helpers, mailers, requests, etc? I've seen cases in which data was set up in before(:all) (which does not run in a transaction and is therefore not rolled back), and uniqueness validations would fail in other places. > > What specific failure messages are you seeing? > > > end > > > All of these tests do not return errors and do add the invalid records > > to the database. > > > Has anyone else had this happen? Suggestions? > > > Thanks! > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Feb 24 14:19:33 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Feb 2011 13:19:33 -0600 Subject: [rspec-users] ordering dependency in tests? In-Reply-To: <09060460e3c51137f85894c24cfaead5@ruby-forum.com> References: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> <20801DFA-FBC5-4529-8CC2-AC2C55680C2D@gmail.com> <09060460e3c51137f85894c24cfaead5@ruby-forum.com> Message-ID: <34FCF022-1368-47C9-AF65-0B7AC161E943@gmail.com> On Feb 24, 2011, at 12:58 PM, Fearless Fool wrote: > David Chelimsky wrote in post #983690: >>> RESIDENTIAL = self.create(:name => "residential") >> ^^ this is probably the problem ^^ >> ... > > Ah! got it. FWIW, I wrote a query to the Rails group several months > ago wondering if this construct was legit and got feedback that it was > legit. I think it's OK as a const with find_or_create, but with find, it is clearly problematic. Cheers, David > Your explanation makes good sense. I'll change that and see > what happens. > > If you don't hear back from me, assume it's working! ;) And thanks in > advance. > From lists at ruby-forum.com Thu Feb 24 14:24:19 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Thu, 24 Feb 2011 20:24:19 +0100 Subject: [rspec-users] ordering dependency in tests? In-Reply-To: <09060460e3c51137f85894c24cfaead5@ruby-forum.com> References: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> <20801DFA-FBC5-4529-8CC2-AC2C55680C2D@gmail.com> <09060460e3c51137f85894c24cfaead5@ruby-forum.com> Message-ID: <6edd3b1ad7ac556852d37c289355fd24@ruby-forum.com> @Pat: thanks for the suggestions. It's perhaps not only what David suggested -- I seem to be suffering from some cached AR value. I changed my constant declaration to: RESIDENTIAL = find_or_create_by_name("residential") This keeps the number of instances down to a 1. That's good. But if I put this in the setup of my test: puts(@premise_group.premises.size) @premise_group.reload puts(@premise_group.premises.size I get 8 0 Since my setup code is pushing elements onto @premise_group.premises, I can see that this would cause trouble when @premise_group is written out to the DB. My head hurts just thinking about where I need to sprinkle reload() statements in my code -- maybe the coffee will kick in and clarity will result. -- Posted via http://www.ruby-forum.com/. From cdemyanovich at gmail.com Thu Feb 24 14:26:55 2011 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Thu, 24 Feb 2011 14:26:55 -0500 Subject: [rspec-users] Validations aren't being performed when running 'rspec spec' In-Reply-To: References: <1e67c7bb-27fc-46f7-8c24-698c12af814c@a8g2000pri.googlegroups.com> <44B33905-71D0-4913-920B-7B3C1E095071@gmail.com> Message-ID: On Thu, Feb 24, 2011 at 2:07 PM, Tom Milewski wrote: > Thanks for the replies. > > Here's the error I'm seeing when running all specs (.build > and .create): > > Agent while creating should ensure that name is present > Failure/Error: Factory(:public_agent, :name => nil).should > have(1).error_on(:name) > expected 1 error on :name, got 0 > # ./spec/models/agent_spec.rb:35:in `block (3 levels) in (required)>' > > Here's what I'm seeing when running model specs with .create: > > Agent while creating should ensure that name is present > Failure/Error: Factory(:public_agent, :name => nil).should > have(1).error_on(:name) > ActiveRecord::RecordInvalid: > Validation failed: Name can't be blank > # ./spec/models/agent_spec.rb:35:in `block (3 levels) in (required)>' > > Everything passes when running model specs with .build. > Have you tried with Agent.new and/or Agent.create? Maybe factory_girl is doing something strange. Also, what versions of rails, rspec-rails, rspec and factory_girl are you using? Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From tmilewski at gmail.com Thu Feb 24 14:34:21 2011 From: tmilewski at gmail.com (Tom Milewski) Date: Thu, 24 Feb 2011 11:34:21 -0800 (PST) Subject: [rspec-users] Validations aren't being performed when running 'rspec spec' In-Reply-To: <44B33905-71D0-4913-920B-7B3C1E095071@gmail.com> References: <1e67c7bb-27fc-46f7-8c24-698c12af814c@a8g2000pri.googlegroups.com> <44B33905-71D0-4913-920B-7B3C1E095071@gmail.com> Message-ID: I should also note that if I replace ".should have(1).error_on(:name)" with, simply, ".should be_valid". The same issues occur. All specs (except when only running models) pass when they shouldn't be. On Feb 24, 8:48?am, David Chelimsky wrote: > On Feb 23, 2011, at 9:29 AM, Tom Milewski wrote: > > > > > > > > > > > Hello, > > > When I run 'rspec spec/models' everything runs beautifully. > > When I run 'rspec spec/controllers' everything also runs beautifully. > > When I run 'rspec spec' the models seem to forget that the records > > need to pass the validations before being saved to the database. > > > This is consistent across all model tests which are checking > > validations. > > > Model: > > > validates_presence_of :name, :location, :email... > > > Test: > > > it "should ensure that name is present" do > > ? ? ?Factory.build(:public_agent, :name => nil).should have(1).error_on(:name) > > Factory.build ^^ doesn't even save records to the database in the first place, so it would be surprising if this were the example that is causing trouble. > > Do you have any other specs besides models and controllers? helpers, mailers, requests, etc? I've seen cases in which data was set up in before(:all) (which does not run in a transaction and is therefore not rolled back), and uniqueness validations would fail in other places. > > What specific failure messages are you seeing? > > > end > > > All of these tests do not return errors and do add the invalid records > > to the database. > > > Has anyone else had this happen? Suggestions? > > > Thanks! > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Feb 24 14:38:07 2011 From: lists at ruby-forum.com (Fearless Fool) Date: Thu, 24 Feb 2011 20:38:07 +0100 Subject: [rspec-users] ordering dependency in tests? In-Reply-To: <6edd3b1ad7ac556852d37c289355fd24@ruby-forum.com> References: <3e359d188aea6051ba920757a44bacc7@ruby-forum.com> <20801DFA-FBC5-4529-8CC2-AC2C55680C2D@gmail.com> <09060460e3c51137f85894c24cfaead5@ruby-forum.com> <6edd3b1ad7ac556852d37c289355fd24@ruby-forum.com> Message-ID: <34c222e4aa1e2e79442da667ed109d17@ruby-forum.com> SOLVED -- it was an AR caching problem. I had Factory code that was essentially doing: def make_me_a_premise(opts = {}) opts = MODEL_PREMISE_DEFAULTS.merge(opts) premise = Factory(:premise) Factory(:premise_group_member, :premise => premise, :premise_group => opts[:premise_group]) ... premise end ... which was properly creating a premise <=> premise_group association, but not informing the in-memory premise_group about the new association. adding: opts[:premise_group].reload fixed everything. @David and @Pat, thanks for helping point the way. - ff [PS: Is there a more Rails-y way do make the association that won't run into this problem? And what about the case where the association carries a value with it -- you can't just do a push.] -- Posted via http://www.ruby-forum.com/. From chs at proactive.cc Thu Feb 24 15:34:58 2011 From: chs at proactive.cc (Christoph Schiessl) Date: Thu, 24 Feb 2011 21:34:58 +0100 Subject: [rspec-users] Stubbing Scopes In-Reply-To: References: <89e67f8c-2047-46a9-8935-b318aba057a2@f36g2000pri.googlegroups.com> <7AEAD8C9-3C6C-427B-A337-6A000F316A18@proactive.cc> Message-ID: So... I settled for testing with message expectations without return values. Guess that's good enough for now. Thank you anyway! Best regards, Christoph Schiessl On Feb 15, 2011, at 21:34 , Justin Ko wrote: > > > On Feb 15, 11:14 am, Christoph Schiessl wrote: >> Thanks for your suggestion Justin, but I don't believe that the problem is time zone related. Time objects usually don't "loose" their Time Zone when performing operations on them. Here's an example for illustration: >> >> $ rails console >> Loading development environment (Rails 3.0.4) >> ruby-1.8.7-p330 :001 > Time.zone.name >> => "Vienna" >> ruby-1.8.7-p330 :002 > t = Time.zone.now.beginning_of_month >> => Tue, 01 Feb 2011 00:00:00 CET +01:00 >> ruby-1.8.7-p330 :003 > t += 3.hours >> => Tue, 01 Feb 2011 03:00:00 CET +01:00 >> ruby-1.8.7-p330 :004 > t.beginning_of_day >> => Tue, 01 Feb 2011 00:00:00 CET +01:00 >> >> If the should_receive arguments and actual arguments wouldn't be the same, then I would expect both examples below to fail. >> >> context ".on_day" do >> let(:start_of_day) { Time.zone.now.beginning_of_day } >> before { Interval.should_receive(:in_interval).with(start_of_day, start_of_day + 1.day).and_return("result") } >> # (1) Passing example: >> it { Interval.on_day(start_of_day + 3.hours) } >> # (2) Failing example: >> it { Interval.on_day(start_of_day + 3.hours).should == "result" } >> end >> >> However, (1) is passing and (2) is failing. Output as before: >> >>>> Failure/Error: Allocation.on_day(start_of_day + 3.hours).should == "result" >>>> NoMethodError: >>>> undefined method `includes_values' for "result":String >> >> Any ideas? >> >> Best regards, >> Christoph Schiessl >> >> On Feb 15, 2011, at 18:51 , Justin Ko wrote: >> >> >> >> >> >>> Your expectation (should_receive) is expecting "start_of_day", which >>> uses Time.zone. The actual "on_day" scope does >>> "day.to_time.beginning_of_day", which does not use any time zone. >>> Therefore, the arguments to in_interval are not the same as the >>> expectation. And because they are not the same, the mock does not get >>> set. They must be exactly the same, since you are using a specific >>> values. >> >>> You are not seeing a "the in_interval method was not called" >>> expectation ouput message because of the "includes_values" error. This >>> is because RSpec is comparing "result" with an array. This is because >>> Rails scopes return arrays, not strings (it is not returning a string >>> because the mock was never set). >> >>> Are you setting the time zone in a before block? >> >>> Here are two really nice gems for dealing with Time sensitive code: >>> https://github.com/jtrupiano/timecop >>> https://github.com/bebanjo/delorean >> >>> On Feb 15, 9:35 am, Christoph Schiessl wrote: >>>> Hi! >> >>>> I'm trying to test the following (simplified) model: >> >>>> class Allocation < ActiveRecord::Base >>>> scope :in_interval, (proc do |start_of_interval, end_of_interval| >>>> params = {:s => start_of_interval, :e => end_of_interval} >>>> where("(starts_at > :s AND starts_at < :e) OR (ends_at > :s AND ends_at < :e) OR (starts_at <= :s AND ends_at >= :e)", params) >>>> end) >> >>>> scope :on_day, (proc do |day| >>>> day = day.to_time.beginning_of_day >>>> in_interval(day, day + 1.day) >>>> end) >> >>>> # validations and other scopes... >>>> end >> >>>> I wrote a lot of specs for :in_interval - however testing :on_day is kind of problem. I don't want to duplicate any :in_interval specs - therefore I'm trying to stub :in_interval like this: >> >>>> let(:start_of_day) { Time.zone.now.beginning_of_day } >>>> it do >>>> Allocation.should_receive(:in_interval).with(start_of_day, start_of_day + 1.day).and_return("result") >> >>>> # working assertion - the :in_interval stub seems to get called as expected: >>>> # Allocation.on_day(start_of_day + 3.hours) >> >>>> # failing assertion: >>>> Allocation.on_day(start_of_day + 3.hours).should == "result" >>>> end >> >>>> RSpec Output: >> >>>> Failure/Error: Allocation.on_day(start_of_day + 3.hours).should == "result" >>>> NoMethodError: >>>> undefined method `includes_values' for "result":String >> >>>> I'm using Rails 3.0.4 and RSpec 2.5 (latest versions). >> >>>> Best regards, >>>> Christoph Schiessl >>>> _______________________________________________ >>>> 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 > > Maybe because the scope is being called within a scope, it is wrapping > it in an array: ["results"] > > Either way, report back what this code returns: it { raise > Interval.on_day(start_of_day + 3.hours).inspect } > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From shamaoke at hotmail.com Thu Feb 24 19:26:47 2011 From: shamaoke at hotmail.com (Shamaoke) Date: Thu, 24 Feb 2011 16:26:47 -0800 (PST) Subject: [rspec-users] RSpec doesn't see the DATA constant In-Reply-To: <0a429777e191829e4b2649ee3b80f9ae@ruby-forum.com> References: <8b7dd53e-3b0d-4daa-8c9f-1acf72917c58@8g2000prt.googlegroups.com> <0a429777e191829e4b2649ee3b80f9ae@ruby-forum.com> Message-ID: <3ebccf1e-c5fb-4ca7-85c8-40287985d030@u6g2000vbh.googlegroups.com> Thanks for the explanations, Costi G. I didn't thought that the `DATA` constant isn't seen by the interpreter if it is in the required file. The only solution that I can think of right now is the following: ~~~ # data_spec.rb describe 'DATA' do it 'contains lines following the __END__ keyword' do data = File.read(__FILE__).split("__END__\n")[-1] data.should == "Hello from the underground!\n" end end __END__ Hello from the underground! ~~~ Costi G.: > P. A. wrote in post #983523: > > Hi. > > > > In Ruby there's the `DATA` constant which contains the lines following > > the `__END__` keyword in the source file. For some reason RSpec > > doesn't see it. > > > > Here's the example: > > > > ~~~ > > # data_spec.rb > > > > requre 'rspec' > > > > describe 'DATA' do > > it 'contains lines following the __END__ keyword' do > > DATA.read.should == "Hello from underground!\n" > > end > > end > > > > __END__ > > Hello from underground! > > ~~~ > > > > If then I run `$ rspec data_spec.rb`, I'm getting 'NameError: > > uninitialized constant RSpec::Core::ExampleGroup::Nested_1::DATA'. > > However, if I use `$ ruby data_spec.rb` all works fine. > > DATA works only on the first file called by the interpreter. > > first.rb: > require 'second' > > second.rb: > p DATA.read > > __END__ > BAM! > > > ruby first.rb > ./second.rb:1: uninitialized constant DATA (NameError) > from first.rb:1:in `require' > from first.rb:1 > > ruby second.rb > "BAM!\n" > > > > > > Why RSpec doesn't see the constant when I use the `rspec` command? How > > can I solve the problem? > > > The restriction on DATA notwithstanding, DATA in that context will by > ambiguous. Think about it, is the DATA from the rspec file or the DATA > from the tested file? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rosskaff at gmail.com Thu Feb 24 11:39:05 2011 From: rosskaff at gmail.com (Ross Kaffenberger) Date: Thu, 24 Feb 2011 08:39:05 -0800 (PST) Subject: [rspec-users] Support for rspec-2 and rails 2.3.x Message-ID: <2725550.737.1298565545494.JavaMail.geo-discussion-forums@vbhw19> Anyone have rspec-2 working with rails 2.3.x? We're looking at this route as an incremental step towards upgrading to rails 3. I saw David C mention in the rpec-2 release notes this might be on the roadmap... curious to see if there's any progress on that front or how we can contribute. Cheers, Ross Weplay -------------- next part -------------- An HTML attachment was scrubbed... URL: From wilsonb at gmail.com Thu Feb 24 21:09:39 2011 From: wilsonb at gmail.com (Wilson Bilkovich) Date: Thu, 24 Feb 2011 18:09:39 -0800 Subject: [rspec-users] Support for rspec-2 and rails 2.3.x In-Reply-To: <2725550.737.1298565545494.JavaMail.geo-discussion-forums@vbhw19> References: <2725550.737.1298565545494.JavaMail.geo-discussion-forums@vbhw19> Message-ID: On Thu, Feb 24, 2011 at 8:39 AM, Ross Kaffenberger wrote: > Anyone have rspec-2 working with rails 2.3.x? We're looking at this route as > an incremental step towards upgrading to rails 3. > I saw David C mention?in the rpec-2 release notes?this might be on the > roadmap... curious to see if there's any progress on that front or how we > can contribute. To my knowledge this isn't even a twinkle in the repo's eye, and is going to take some serious effort. This is part of the traditional "every rspec release breaks everything" experience that has been such a pleasure since 0.8.x. From dchelimsky at gmail.com Thu Feb 24 23:08:50 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Feb 2011 22:08:50 -0600 Subject: [rspec-users] Support for rspec-2 and rails 2.3.x In-Reply-To: References: <2725550.737.1298565545494.JavaMail.geo-discussion-forums@vbhw19> Message-ID: <5D50CE2E-3059-4C09-9195-87F01896AAA7@gmail.com> On Feb 24, 2011, at 8:09 PM, Wilson Bilkovich wrote: > On Thu, Feb 24, 2011 at 8:39 AM, Ross Kaffenberger wrote: >> Anyone have rspec-2 working with rails 2.3.x? We're looking at this route as >> an incremental step towards upgrading to rails 3. >> I saw David C mention in the rpec-2 release notes this might be on the >> roadmap... curious to see if there's any progress on that front or how we >> can contribute. > > To my knowledge this isn't even a twinkle in the repo's eye, Very poetic. > and is > going to take some serious effort. Yes - it basically requires a re-write of the existing rspec-rails-1.3 gem backed by RSpec-2. The thing is, even if such a thing were to come into being, it would not really make the Rails-3 transition any simpler. You'd still have to upgrade from rspec-rails-2-for-rails-2 to rspec-rails-2, and it would only save you a couple of upgrade steps. And that's largely due to changes in Rails 3, not just changes in RSpec. The good news is that the rspec-rails-2 gem has significantly less monkey patching than the rspec-rails-1 gems did, so the likelihood that future Rails releases will force RSpec releases is seriously diminished. > This is part of the traditional "every rspec release breaks > everything" experience that has been such a pleasure since 0.8.x. While I appreciate that RSpec has such a history, this is simply no longer the case. Since the 2.0 release there has only been one breaking change, and it was related to an integration point between RSpec, Autotest, and Bundler. There have been no breaking API changes, nor will there be any planned before a 3.0 release. Cheers, David From tmilewski at gmail.com Fri Feb 25 11:58:14 2011 From: tmilewski at gmail.com (Tom Milewski) Date: Fri, 25 Feb 2011 08:58:14 -0800 (PST) Subject: [rspec-users] Validations aren't being performed when running 'rspec spec' In-Reply-To: References: <1e67c7bb-27fc-46f7-8c24-698c12af814c@a8g2000pri.googlegroups.com> <44B33905-71D0-4913-920B-7B3C1E095071@gmail.com> Message-ID: <0e066d91-779d-4dd7-a11a-ffae07cad8cf@x4g2000prf.googlegroups.com> Thanks for all of your insight guys. As it turned out the culprit was ".any_instance.stubs(:valid?).returns(false)" which was being run in the controllers. I changed some things around any now everything is working as expected. I was using the following: Rails 3.0.0 RSpec 2.4.0 RSpec Rails 2.4.1 Factory Girl 2.0.0.beta1 Thanks again! On Feb 24, 2:26?pm, Craig Demyanovich wrote: > On Thu, Feb 24, 2011 at 2:07 PM, Tom Milewski wrote: > > Thanks for the replies. > > > Here's the error I'm seeing when running all specs (.build > > and .create): > > > Agent while creating should ensure that name is present > > ? ? Failure/Error: Factory(:public_agent, :name => nil).should > > have(1).error_on(:name) > > ? ? ? ?expected 1 error on :name, got 0 > > ? ? # ./spec/models/agent_spec.rb:35:in `block (3 levels) in > (required)>' > > > Here's what I'm seeing when running model specs with .create: > > > Agent while creating should ensure that name is present > > ? ? Failure/Error: Factory(:public_agent, :name => nil).should > > have(1).error_on(:name) > > ? ? ?ActiveRecord::RecordInvalid: > > ? ? ? Validation failed: Name can't be blank > > ? ? # ./spec/models/agent_spec.rb:35:in `block (3 levels) in > (required)>' > > > Everything passes when running model specs with .build. > > Have you tried with Agent.new and/or Agent.create? Maybe factory_girl is > doing something strange. > > Also, what versions of rails, rspec-rails, rspec and factory_girl are you > using? > > Craig > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Fri Feb 25 16:30:58 2011 From: lists at ruby-forum.com (Radhesh Kamath) Date: Fri, 25 Feb 2011 22:30:58 +0100 Subject: [rspec-users] Rspec2 for rails 2.3.8? Message-ID: Hi experts, I picked up a copy of the rspec book and wrote some tests in spec/lib and spec/models for my Rails 2.3.8 code. I was using rspec 2.5.1, rspec-core 2.5.0, rspec-expectations 2.5.0 et. al. But I realised that the rspec-rails version I am using is meant for Rails3. Which version of rspec-rails should I use for Rails 2.3.8? Best, Radhesh -- Posted via http://www.ruby-forum.com/. From cdemyanovich at gmail.com Fri Feb 25 16:58:33 2011 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Fri, 25 Feb 2011 16:58:33 -0500 Subject: [rspec-users] Rspec2 for rails 2.3.8? In-Reply-To: References: Message-ID: On Fri, Feb 25, 2011 at 4:30 PM, Radhesh Kamath wrote: > Which version of rspec-rails should I use for Rails 2.3.8? rspec-rails 1.3.3 is currently the latest release for Rails 2.3.x. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Fri Feb 25 17:06:54 2011 From: jko170 at gmail.com (Justin Ko) Date: Fri, 25 Feb 2011 15:06:54 -0700 Subject: [rspec-users] Rspec2 for rails 2.3.8? In-Reply-To: References: Message-ID: On Fri, Feb 25, 2011 at 2:30 PM, Radhesh Kamath wrote: > Hi experts, > > I picked up a copy of the rspec book and wrote some tests in spec/lib > and spec/models for my Rails 2.3.8 code. > > I was using rspec 2.5.1, rspec-core 2.5.0, rspec-expectations 2.5.0 et. > al. > > But I realised that the rspec-rails version I am using is meant for > Rails3. > > Which version of rspec-rails should I use for Rails 2.3.8? > > Best, > Radhesh > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > You would need to use version 1.3.3 https://github.com/dchelimsky/rspec-rails If I were you I would try to upgrade to Rails 3 because RSpec 2 is really, really nice. Upgrading to Rails 3 is easy and not bad at all unless you have some non-upgradable gems, like searchlogic for example, then it might be a pain. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Feb 25 17:19:56 2011 From: lists at ruby-forum.com (Radhesh Kamath) Date: Fri, 25 Feb 2011 23:19:56 +0100 Subject: [rspec-users] Rspec2 for rails 2.3.8? In-Reply-To: References: Message-ID: <375b9ed206908ddfdccaa1bea34f0484@ruby-forum.com> Craig Demyanovich wrote in post #983991: > On Fri, Feb 25, 2011 at 4:30 PM, Radhesh Kamath > wrote: > >> Which version of rspec-rails should I use for Rails 2.3.8? > > > rspec-rails 1.3.3 is currently the latest release for Rails 2.3.x. > I am getting this error with my current setup, which I think, should not happen: Failure/Error: non_uniq_agg.should have(2).errors_on(:name) NoMethodError: undefined method `errors_on' for # where 'Aggregate' is a model I am testing. My gem list looks like so: *** LOCAL GEMS *** abstract (1.0.0) actionmailer (2.3.8) actionpack (2.3.8) activerecord (2.3.8) activerecord-jdbc-adapter (1.1.1) activerecord-jdbcmysql-adapter (1.1.1) activeresource (2.3.8) activesupport (2.3.8) backports (1.18.2) bouncy-castle-java (1.5.0145.2) builder (2.1.2) columnize (0.3.1) diff-lcs (1.1.2) erubis (2.6.6) facets (2.9.1) i18n (0.4.0) ipaddress (0.7.0) jdbc-mysql (5.1.13) jruby-openssl (0.7.3) macaddr (1.0.0) rack (1.2.1, 1.1.0) rack-mount (0.6.13) rack-test (0.5.7) rails (2.3.8) rake (0.8.7) rspec (2.5.0, 1.3.1) rspec-core (2.5.1) rspec-expectations (2.5.0) rspec-mocks (2.5.0) rspec-rails (1.3.3) ruby-debug (0.10.3) ruby-debug-base (0.10.3.2) sources (0.0.1) thor (0.14.6) tzinfo (0.3.24) uuid (2.3.1) And my spec_helper looks like so: ENV["RAILS_ENV"] ||= 'development' require File.expand_path("../../config/environment", __FILE__) # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| # == Mock Framework # # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: # # config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr config.mock_with :rspec # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures #config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. #config.use_transactional_fixtures = true end Is there something else I should be including? > Regards, > Craig -- Posted via http://www.ruby-forum.com/. From wilsonb at gmail.com Fri Feb 25 22:24:23 2011 From: wilsonb at gmail.com (Wilson Bilkovich) Date: Fri, 25 Feb 2011 22:24:23 -0500 Subject: [rspec-users] Support for rspec-2 and rails 2.3.x In-Reply-To: <5D50CE2E-3059-4C09-9195-87F01896AAA7@gmail.com> References: <2725550.737.1298565545494.JavaMail.geo-discussion-forums@vbhw19> <5D50CE2E-3059-4C09-9195-87F01896AAA7@gmail.com> Message-ID: On Thu, Feb 24, 2011 at 11:08 PM, David Chelimsky wrote: > largely due to changes in Rails 3, not just changes in RSpec. > > The good news is that the rspec-rails-2 gem has significantly less monkey patching than the rspec-rails-1 gems did, so the likelihood that future Rails releases will force RSpec releases is seriously diminished. > >> This is part of the traditional "every rspec release breaks >> everything" experience that has been such a pleasure since 0.8.x. > > While I appreciate that RSpec has such a history, this is simply no longer the case. Since the 2.0 release there has only been one breaking change, and it was related to an integration point between RSpec, Autotest, and Bundler. There have been no breaking API changes, nor will there be any planned before a 3.0 release. > This is totally fair. :) I've just worked through four major evolutions of rspec and three or so that broke extensions I had written. Having now read the rspec2 / rspec2-rails source, I agree that it looks a lot cleaner and probably isn't going to break again. Awesome job; I particularly like request specs and the new matcher declarations. From myron.marston at gmail.com Sat Feb 26 23:25:11 2011 From: myron.marston at gmail.com (Myron Marston) Date: Sat, 26 Feb 2011 20:25:11 -0800 (PST) Subject: [rspec-users] Rspec is swallowing undefined methods in it's method_missing and looping forever In-Reply-To: References: Message-ID: <95ab6c36-16bb-459e-b10f-26b392fadaae@o21g2000prh.googlegroups.com> On Feb 21, 11:45?am, Curtis j Schofield wrote: > Has anyone else encountered this? > > It will end up printing this : > > ?1) Applications Scribd api requests should always be private > ? ? ?Failure/Error: Unable to find matching line from backtrace > ? ? ?SystemStackError: > ? ? ? ?stack level too deep > ? ? ?# /Users/o_o/.rvm/gems/ruby-1.9.2-p0 at capr3 > /gems/rspec-expectations-2.5.0/lib/rspec/matchers/method_missing.rb:7 > > We noticed this. > > Curtis Schofield & Anita Kuno > > -- > make haste slowly \ > festina lente ?\ > - > mobile ?+1_415_632_6001 > cur... at robotarmyma.dehttp://robotarmyma.de > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users A similar issue has been reported[1]. It's a weird bug with ruby 1.9[2]. When you include RSpec::Matchers in an example group, it makes `super` recurse infinitely. The solution, for now, is to not include RSpec::Matchers in an example group. You shouldn't need to, anyway; RSpec takes care of including it for you. I'm working on a fix to work around the bug in 1.9. Myron [1] https://github.com/rspec/rspec-expectations/issues#issue/63 [2] https://gist.github.com/845896 From dchelimsky at gmail.com Sun Feb 27 15:47:57 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 27 Feb 2011 14:47:57 -0600 Subject: [rspec-users] Rspec2 for rails 2.3.8? In-Reply-To: <375b9ed206908ddfdccaa1bea34f0484@ruby-forum.com> References: <375b9ed206908ddfdccaa1bea34f0484@ruby-forum.com> Message-ID: <6024D9D7-39CB-4321-B2E9-55CD56E4937A@gmail.com> On Feb 25, 2011, at 4:19 PM, Radhesh Kamath wrote: > Craig Demyanovich wrote in post #983991: >> On Fri, Feb 25, 2011 at 4:30 PM, Radhesh Kamath >> wrote: >> >>> Which version of rspec-rails should I use for Rails 2.3.8? >> >> >> rspec-rails 1.3.3 is currently the latest release for Rails 2.3.x. >> > > I am getting this error with my current setup, which I think, should not > happen: > > Failure/Error: non_uniq_agg.should have(2).errors_on(:name) > NoMethodError: > undefined method `errors_on' for # > > where 'Aggregate' is a model I am testing. > > My gem list looks like so: > > *** LOCAL GEMS *** > > abstract (1.0.0) > actionmailer (2.3.8) > actionpack (2.3.8) > activerecord (2.3.8) > activerecord-jdbc-adapter (1.1.1) > activerecord-jdbcmysql-adapter (1.1.1) > activeresource (2.3.8) > activesupport (2.3.8) > backports (1.18.2) > bouncy-castle-java (1.5.0145.2) > builder (2.1.2) > columnize (0.3.1) > diff-lcs (1.1.2) > erubis (2.6.6) > facets (2.9.1) > i18n (0.4.0) > ipaddress (0.7.0) > jdbc-mysql (5.1.13) > jruby-openssl (0.7.3) > macaddr (1.0.0) > rack (1.2.1, 1.1.0) > rack-mount (0.6.13) > rack-test (0.5.7) > rails (2.3.8) > rake (0.8.7) > rspec (2.5.0, 1.3.1) > rspec-core (2.5.1) > rspec-expectations (2.5.0) > rspec-mocks (2.5.0) > rspec-rails (1.3.3) > ruby-debug (0.10.3) > ruby-debug-base (0.10.3.2) > sources (0.0.1) > thor (0.14.6) > tzinfo (0.3.24) > uuid (2.3.1) > > And my spec_helper looks like so: > > ENV["RAILS_ENV"] ||= 'development' > require File.expand_path("../../config/environment", __FILE__) > > # Requires supporting ruby files with custom matchers and macros, etc, > # in spec/support/ and its subdirectories. > Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} > > RSpec.configure do |config| If you're using rspec-rails-1.3.3, this line ^^ should raise an error since the RSpec constant wasn't introduced until rspec-2.0. I'm guessing that the rails app is not correctly configured to use rspec-rails-1.3.3. What's in config/environment.rb? Are you using bundler? If so, what's in Gemfile? > # == Mock Framework > # > # If you prefer to use mocha, flexmock or RR, uncomment the > appropriate line: > # > # config.mock_with :mocha > # config.mock_with :flexmock > # config.mock_with :rr > config.mock_with :rspec > > # Remove this line if you're not using ActiveRecord or ActiveRecord > fixtures > #config.fixture_path = "#{::Rails.root}/spec/fixtures" > > # If you're not using ActiveRecord, or you'd prefer not to run each of > your > # examples within a transaction, remove the following line or assign > false > # instead of true. > #config.use_transactional_fixtures = true > end > > Is there something else I should be including? > >> Regards, >> Craig > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From patmaddox at me.com Mon Feb 28 02:33:23 2011 From: patmaddox at me.com (Pat Maddox) Date: Sun, 27 Feb 2011 23:33:23 -0800 Subject: [rspec-users] Support for rspec-2 and rails 2.3.x In-Reply-To: References: <2725550.737.1298565545494.JavaMail.geo-discussion-forums@vbhw19> Message-ID: <9E0F89B2-637A-456B-A0CB-CF4EA967ADF0@me.com> On Feb 24, 2011, at 6:09 PM, Wilson Bilkovich wrote: > On Thu, Feb 24, 2011 at 8:39 AM, Ross Kaffenberger wrote: >> Anyone have rspec-2 working with rails 2.3.x? We're looking at this route as >> an incremental step towards upgrading to rails 3. >> I saw David C mention in the rpec-2 release notes this might be on the >> roadmap... curious to see if there's any progress on that front or how we >> can contribute. > > To my knowledge this isn't even a twinkle in the repo's eye, and is > going to take some serious effort. I have something started at https://github.com/patmaddox/rspec2rails2-dev but it is kind of a big nasty task in my experience so far. Because of the changes in ActiveSupport::TestCase, the approach I've taken is to basically rip out the guts of the Rails 2.x ActiveSupport::TestCase and create modules from them, and include those modules in the appropriate RSpec 2 example groups. I can't estimate when/if it will work, I've only spent time on it sporadically. Pat From charley.stran at gmail.com Sun Feb 27 22:57:47 2011 From: charley.stran at gmail.com (Charley) Date: Sun, 27 Feb 2011 19:57:47 -0800 (PST) Subject: [rspec-users] Simple Association Redirect on delete Message-ID: So am fairly new to rspec and am trying to get the hang of it, but have run into a few issues I cant figure out. Several times in my code I have model that belongs to a parent, when the model is deleted, instead of redirecting to the index action, it redirects to the show action for its parent model. Simple enough. The code in my application currently properly handles this, but I dont know how to make the test handle it. For example I have this basic auto-generated test. it "redirects to the bugs list" do Bug.stub(:find) { mock_bug } delete :destroy, :id => "1" response.should redirect_to(bugs_url) end This fails for obvious reasons. A bug belongs to a project so the redirect should go to the projects_url("someproject_id_I_dont_know") I am sure this is a fairly simple and common thing. Can anyone help put me on the right path? From cdemyanovich at gmail.com Mon Feb 28 09:21:37 2011 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Mon, 28 Feb 2011 09:21:37 -0500 Subject: [rspec-users] Simple Association Redirect on delete In-Reply-To: References: Message-ID: On Sun, Feb 27, 2011 at 10:57 PM, Charley wrote: ... > it "redirects to the bugs list" do > Bug.stub(:find) { mock_bug } > delete :destroy, :id => "1" > response.should redirect_to(bugs_url) > end > > This fails for obvious reasons. A bug belongs to a project so the > redirect should go to the projects_url("someproject_id_I_dont_know") > > I am sure this is a fairly simple and common thing. Can anyone help > put me on the right path? Make the mock_bug respond to project_id. Then verify that the request's response goes to project_path(:id => mock_bug.project_id). Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Mon Feb 28 12:18:52 2011 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 28 Feb 2011 17:18:52 +0000 Subject: [rspec-users] RSpec doesn't see the DATA constant In-Reply-To: <3ebccf1e-c5fb-4ca7-85c8-40287985d030@u6g2000vbh.googlegroups.com> References: <8b7dd53e-3b0d-4daa-8c9f-1acf72917c58@8g2000prt.googlegroups.com> <0a429777e191829e4b2649ee3b80f9ae@ruby-forum.com> <3ebccf1e-c5fb-4ca7-85c8-40287985d030@u6g2000vbh.googlegroups.com> Message-ID: On 25 Feb 2011, at 00:26, Shamaoke wrote: > Thanks for the explanations, Costi G. I didn't thought that the `DATA` > constant isn't seen by the interpreter if it is in the required file. > > The only solution that I can think of right now is the following: Why not just File.read(DATA_FILE) and keep the data in a separate file? > > ~~~ > # data_spec.rb > > describe 'DATA' do > it 'contains lines following the __END__ keyword' do > data = File.read(__FILE__).split("__END__\n")[-1] > data.should == "Hello from the underground!\n" > end > end > > __END__ > Hello from the underground! > ~~~ > > Costi G.: >> P. A. wrote in post #983523: >>> Hi. >>> >>> In Ruby there's the `DATA` constant which contains the lines following >>> the `__END__` keyword in the source file. For some reason RSpec >>> doesn't see it. >>> >>> Here's the example: >>> >>> ~~~ >>> # data_spec.rb >>> >>> requre 'rspec' >>> >>> describe 'DATA' do >>> it 'contains lines following the __END__ keyword' do >>> DATA.read.should == "Hello from underground!\n" >>> end >>> end >>> >>> __END__ >>> Hello from underground! >>> ~~~ >>> >>> If then I run `$ rspec data_spec.rb`, I'm getting 'NameError: >>> uninitialized constant RSpec::Core::ExampleGroup::Nested_1::DATA'. >>> However, if I use `$ ruby data_spec.rb` all works fine. >> >> DATA works only on the first file called by the interpreter. >> >> first.rb: >> require 'second' >> >> second.rb: >> p DATA.read >> >> __END__ >> BAM! >> >> >> ruby first.rb >> ./second.rb:1: uninitialized constant DATA (NameError) >> from first.rb:1:in `require' >> from first.rb:1 >> >> ruby second.rb >> "BAM!\n" >> >> >>> >>> Why RSpec doesn't see the constant when I use the `rspec` command? How >>> can I solve the problem? >> >> >> The restriction on DATA notwithstanding, DATA in that context will by >> ambiguous. Think about it, is the DATA from the rspec file or the DATA >> from the tested file? >> >> -- >> Posted via http://www.ruby-forum.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 cheers, Matt matt at mattwynne.net 07974 430184 From charley.stran at gmail.com Mon Feb 28 21:14:17 2011 From: charley.stran at gmail.com (Charley) Date: Mon, 28 Feb 2011 18:14:17 -0800 (PST) Subject: [rspec-users] Simple Association Redirect on delete In-Reply-To: References: Message-ID: <29365a37-d65e-420a-b349-b75c56c23b1d@o21g2000prh.googlegroups.com> I am not sure if I am properly using the respond to call as you suggested. Here is what I tried: it "redirects to the bugs parent project" do Bug.stub(:find) { mock_bug } mock_bug.should respond_to :project_id delete :destroy, :id => "1" response.should redirect_to(project_path(:id => mock_bug.project_id)) end And here is the failure message: 1) BugsController DELETE destroy redirects to the bugs parent project Failure/Error: delete :destroy, :id => "1" ActionController::RoutingError: No route matches {:action=>"show", :controller=>"projects", :id=>#} In case it would illustrate my situation better, here is my action: def destroy @bug = Bug.find(params[:id]) bugs_project = @bug.project_id @bug.destroy respond_to do |format| format.html { redirect_to(project_url(bugs_project)) } format.xml { head :ok } end end Any ideas? On Feb 28, 8:21?am, Craig Demyanovich wrote: > On Sun, Feb 27, 2011 at 10:57 PM, Charley wrote: > > ... > > > it "redirects to the bugs list" do > > ?Bug.stub(:find) { mock_bug } > > ?delete :destroy, :id => "1" > > ?response.should redirect_to(bugs_url) > > end > > > This fails for obvious reasons. A bug belongs to a project so the > > redirect should go to the projects_url("someproject_id_I_dont_know") > > > I am sure this is a fairly simple and common thing. Can anyone help > > put me on the right path? > > Make the mock_bug respond to project_id. Then verify that the request's > response goes to project_path(:id => mock_bug.project_id). > > Regards, > Craig > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users