From mortench at gmail.com Mon Jun 1 06:33:00 2009 From: mortench at gmail.com (mortench) Date: Mon, 1 Jun 2009 03:33:00 -0700 (PDT) Subject: [rspec-users] Does rspec support something like Assumptions in JUnit 4.4? Message-ID: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> JUnit 4.4+ has a feature called assumptions and I am looking for something similar in rspec so that I can express that my examples require a specific environment variable to be specified for testing to make sense. About assumptions from the readme (http://junit.sourceforge.net/doc/ ReleaseNotes4.4.html#assumptions): "Ideally, the developer writing a test has control of all of the forces that might cause a test to fail. If this isn't immediately possible, making dependencies explicit can often improve a design. For example, if a test fails when run in a different locale than the developer intended, it can be fixed by explicitly passing a locale to the domain code. However, sometimes this is not desirable or possible. It's good to be able to run a test against the code as it is currently written, implicit assumptions and all, or to write a test that exposes a known bug. For these situations, JUnit now includes the ability to express "assumptions": " /Morten From dchelimsky at gmail.com Mon Jun 1 06:58:50 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Jun 2009 05:58:50 -0500 Subject: [rspec-users] Does rspec support something like Assumptions in JUnit 4.4? In-Reply-To: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> References: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> Message-ID: <57c63afe0906010358y17cee7d1w452e80b29030e3a2@mail.gmail.com> On Mon, Jun 1, 2009 at 5:33 AM, mortench wrote: > JUnit 4.4+ has a feature called assumptions and I am looking for > something similar in rspec so that I can express that my examples > require a specific environment variable to be specified for testing to > make sense. There is no explicit support for this, but you could always just say (taking the example from the page you cited): def assume_that(expression) yield if expression end def verify_that(actual, expected) actual.should expected end it "should blah de blah" do assume_that(File::SEPARATOR == "/") do ensure_that User.new("optimus"), eql("configfiles/optimus.cfg") end end I am planning to add support for something like ensure_that (name up for grabs) in a future version of rspec, but I'd need to think about assume_that a bit. We're dealing with Ruby here, not Java, and we don't suffer things like a 'final' keyword that force us to have to make assumptions like this. Unless we add some additional feedback, like "such and such example did not run due to faulty assumptions," this seems quite dangerous to me. And even with that, it means that CI servers are going to pass examples that are never actually run. HTH, David > > About assumptions from the readme (http://junit.sourceforge.net/doc/ > ReleaseNotes4.4.html#assumptions): > "Ideally, the developer writing a test has control of all of the > forces that might cause a test to fail. If this isn't immediately > possible, making dependencies explicit can often improve a design. > For example, if a test fails when run in a different locale than the > developer intended, it can be fixed by explicitly passing a locale to > the domain code. > > However, sometimes this is not desirable or possible. > It's good to be able to run a test against the code as it is currently > written, implicit assumptions and all, or to write a test that exposes > a known bug. For these situations, JUnit now includes the ability to > express "assumptions": > " > > /Morten > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mortench at gmail.com Mon Jun 1 07:12:39 2009 From: mortench at gmail.com (mortench) Date: Mon, 1 Jun 2009 04:12:39 -0700 (PDT) Subject: [rspec-users] Does rspec support something like Assumptions in JUnit 4.4? In-Reply-To: <57c63afe0906010358y17cee7d1w452e80b29030e3a2@mail.gmail.com> References: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> <57c63afe0906010358y17cee7d1w452e80b29030e3a2@mail.gmail.com> Message-ID: <852a2dfd-98eb-4b73-af9c-fb482fc69a7f@h2g2000yqg.googlegroups.com> Hi David, Thanks for the suggestion! It indeed make sense for the Junit example... However, my particular usage case for assumption is a bit different. I am using jruby+jspec and I have a group of rspec examples that all require a java property to be set for the examples to be able to run. Besides, the examples also have an after action that will also break if the java propety is not set. Idealy, I would like to do something like. before(:all) do @org_root_prop = java.lang.System.getProperty("root") # abort all examples and after action if condition is not meet: ensure_that !rootPath.nil? && rootPath.strip.length>0 end Notice, that the assume is in a before action and not in the examples themselves + it should affect the examples and after action (none of which should run if before action assumptions are not meet). /Morten On Jun 1, 12:58?pm, David Chelimsky wrote: > On Mon, Jun 1, 2009 at 5:33 AM, mortench wrote: > > JUnit 4.4+ has a feature called assumptions and I am looking for > > something similar in rspec so that I can express that my examples > > require a specific environment variable to be specified for testing to > > make sense. > > There is no explicit support for this, but you could always just say > (taking the example from the page you cited): > > def assume_that(expression) > ? yield if expression > end > > def verify_that(actual, expected) > ? actual.should expected > end > > it "should blah de blah" do > ? assume_that(File::SEPARATOR == "/") do > ? ? ensure_that User.new("optimus"), eql("configfiles/optimus.cfg") > ? end > end > > I am planning to add support for something like ensure_that (name up > for grabs) in a future version of rspec, but I'd need to think about > assume_that a bit. We're dealing with Ruby here, not Java, and we > don't suffer things like a 'final' keyword that force us to have to > make assumptions like this. Unless we add some additional feedback, > like "such and such example did not run due to faulty assumptions," > this seems quite dangerous to me. And even with that, it means that CI > servers are going to pass examples that are never actually run. > > HTH, > David > > > > > > > About assumptions from the readme (http://junit.sourceforge.net/doc/ > > ReleaseNotes4.4.html#assumptions): > > "Ideally, the developer writing a test has control of all of the > > forces that might cause a test to fail. If this isn't immediately > > possible, making dependencies explicit can often improve a design. > > For example, if a test fails when run in a different locale than the > > developer intended, it can be fixed by explicitly passing a locale to > > the domain code. > > > However, sometimes this is not desirable or possible. > > It's good to be able to run a test against the code as it is currently > > written, implicit assumptions and all, or to write a test that exposes > > a known bug. For these situations, JUnit now includes the ability to > > express "assumptions": > > " > > > /Morten > > _______________________________________________ > > 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 mortench at gmail.com Mon Jun 1 07:26:07 2009 From: mortench at gmail.com (mortench) Date: Mon, 1 Jun 2009 04:26:07 -0700 (PDT) Subject: [rspec-users] Does rspec support something like Assumptions in JUnit 4.4? In-Reply-To: <852a2dfd-98eb-4b73-af9c-fb482fc69a7f@h2g2000yqg.googlegroups.com> References: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> <57c63afe0906010358y17cee7d1w452e80b29030e3a2@mail.gmail.com> <852a2dfd-98eb-4b73-af9c-fb482fc69a7f@h2g2000yqg.googlegroups.com> Message-ID: <320590a7-909b-410e-8eeb-3140cda4b0b5@l12g2000yqo.googlegroups.com> Correction for last msg: before(:all) do @org_root_prop = java.lang.System.getProperty("root") # abort all examples and after action if condition is not meet: ensure_that !@org_root_prop.nil? && @org_root_prop.strip.length>0 end /Morten From zach.dennis at gmail.com Mon Jun 1 09:16:23 2009 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 1 Jun 2009 09:16:23 -0400 Subject: [rspec-users] Does rspec support something like Assumptions in JUnit 4.4? In-Reply-To: <320590a7-909b-410e-8eeb-3140cda4b0b5@l12g2000yqo.googlegroups.com> References: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> <57c63afe0906010358y17cee7d1w452e80b29030e3a2@mail.gmail.com> <852a2dfd-98eb-4b73-af9c-fb482fc69a7f@h2g2000yqg.googlegroups.com> <320590a7-909b-410e-8eeb-3140cda4b0b5@l12g2000yqo.googlegroups.com> Message-ID: <85d99afe0906010616v71b6c7bn9aa9408a41ae8822@mail.gmail.com> On Mon, Jun 1, 2009 at 7:26 AM, mortench wrote: > Correction for last msg: > > before(:all) do > ? ?@org_root_prop = java.lang.System.getProperty("root") > > ? ?# abort all examples and after action if condition is not meet: > ? ?ensure_that !@org_root_prop.nil? && @org_root_prop.strip.length>0 > end You could do this check outside of the example? ie: describe "...." do def self.ensure_that(condition, &blk) yield if condition end def self.root_property_is_not_blank org_root_prop = java.lang.System.getProperty("root") org_root_prop.nil? && org_root_prop.strip.length>0 end ensure_that root_property_is_not_blank do it "...." do end end end > > /Morten > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) From pat.maddox at gmail.com Mon Jun 1 12:51:13 2009 From: pat.maddox at gmail.com (Pat Maddox) Date: Mon, 1 Jun 2009 09:51:13 -0700 Subject: [rspec-users] Does rspec support something like Assumptions in JUnit 4.4? In-Reply-To: <852a2dfd-98eb-4b73-af9c-fb482fc69a7f@h2g2000yqg.googlegroups.com> References: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> <57c63afe0906010358y17cee7d1w452e80b29030e3a2@mail.gmail.com> <852a2dfd-98eb-4b73-af9c-fb482fc69a7f@h2g2000yqg.googlegroups.com> Message-ID: <2c7e61990906010951w5b66ac2ei97401a07cafc970d@mail.gmail.com> You can put expectations in your before block, and that'll give you the behavior you want. before(:each) do @org_root_prop = java.lang.System.getProperty("root") @org_root_prop.should_not be_nil @org_root_prop.trim.should_not be_empty end If either of those expectations fail then the examples that require that property will report failures. If I were using this all over the place, I would write a custom matcher. before(:each) do java.lang.System.should have_property("root") @org_root_prop = java.lang.System.getProperty("root") end This would allow you to define your own error message and perform more sophisticated expectations (see the have_tag/with_tag example in rspec-rails). Note that you should be doing this check in before(:each) because you want it to run before each example. Also you should be using before(:each) 99% of the time anyway. Pat On Mon, Jun 1, 2009 at 4:12 AM, mortench wrote: > Hi David, > > Thanks for the suggestion! It indeed make sense for the Junit > example... However, my particular usage case for assumption is a bit > different. I am using jruby+jspec and I have a group of rspec examples > that all require a java property to be set for the examples to be able > to run. Besides, the examples also have an after action that will also > break if the java propety is not set. Idealy, I would like to do > something like. > > before(:all) do > ? ?@org_root_prop = java.lang.System.getProperty("root") > > ? ?# abort all examples and after action if condition is not meet: > ? ?ensure_that !rootPath.nil? && rootPath.strip.length>0 > end > > Notice, that the assume is in a before action and not in the examples > themselves + it should affect the examples and after action (none of > which should run if before action assumptions are not meet). > > /Morten > > > On Jun 1, 12:58?pm, David Chelimsky wrote: >> On Mon, Jun 1, 2009 at 5:33 AM, mortench wrote: >> > JUnit 4.4+ has a feature called assumptions and I am looking for >> > something similar in rspec so that I can express that my examples >> > require a specific environment variable to be specified for testing to >> > make sense. >> >> There is no explicit support for this, but you could always just say >> (taking the example from the page you cited): >> >> def assume_that(expression) >> ? yield if expression >> end >> >> def verify_that(actual, expected) >> ? actual.should expected >> end >> >> it "should blah de blah" do >> ? assume_that(File::SEPARATOR == "/") do >> ? ? ensure_that User.new("optimus"), eql("configfiles/optimus.cfg") >> ? end >> end >> >> I am planning to add support for something like ensure_that (name up >> for grabs) in a future version of rspec, but I'd need to think about >> assume_that a bit. We're dealing with Ruby here, not Java, and we >> don't suffer things like a 'final' keyword that force us to have to >> make assumptions like this. Unless we add some additional feedback, >> like "such and such example did not run due to faulty assumptions," >> this seems quite dangerous to me. And even with that, it means that CI >> servers are going to pass examples that are never actually run. >> >> HTH, >> David >> >> >> >> >> >> > About assumptions from the readme (http://junit.sourceforge.net/doc/ >> > ReleaseNotes4.4.html#assumptions): >> > "Ideally, the developer writing a test has control of all of the >> > forces that might cause a test to fail. If this isn't immediately >> > possible, making dependencies explicit can often improve a design. >> > For example, if a test fails when run in a different locale than the >> > developer intended, it can be fixed by explicitly passing a locale to >> > the domain code. >> >> > However, sometimes this is not desirable or possible. >> > It's good to be able to run a test against the code as it is currently >> > written, implicit assumptions and all, or to write a test that exposes >> > a known bug. For these situations, JUnit now includes the ability to >> > express "assumptions": >> > " >> >> > /Morten >> > _______________________________________________ >> > 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 apsmith at aps.org Mon Jun 1 14:04:39 2009 From: apsmith at aps.org (Arthur Smith) Date: Mon, 01 Jun 2009 14:04:39 -0400 Subject: [rspec-users] Does rspec support something like Assumptions in JUnit 4.4? In-Reply-To: <2c7e61990906010951w5b66ac2ei97401a07cafc970d@mail.gmail.com> References: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> <57c63afe0906010358y17cee7d1w452e80b29030e3a2@mail.gmail.com> <852a2dfd-98eb-4b73-af9c-fb482fc69a7f@h2g2000yqg.googlegroups.com> <2c7e61990906010951w5b66ac2ei97401a07cafc970d@mail.gmail.com> Message-ID: <4A241837.9090504@aps.org> I thought the point was we don't want the examples to be run at all, if the condition is not met? Though I'm wondering why not just handle something like this with a stub (on System.getProperty in this case)? Arthur Smith Pat Maddox wrote: > You can put expectations in your before block, and that'll give you > the behavior you want. > > before(:each) do > @org_root_prop = java.lang.System.getProperty("root") > > @org_root_prop.should_not be_nil > @org_root_prop.trim.should_not be_empty > end > > If either of those expectations fail then the examples that require > that property will report failures. If I were using this all over the > place, I would write a custom matcher. > > before(:each) do > java.lang.System.should have_property("root") > @org_root_prop = java.lang.System.getProperty("root") > end > > This would allow you to define your own error message and perform more > sophisticated expectations (see the have_tag/with_tag example in > rspec-rails). > > Note that you should be doing this check in before(:each) because you > want it to run before each example. Also you should be using > before(:each) 99% of the time anyway. > > Pat > > On Mon, Jun 1, 2009 at 4:12 AM, mortench wrote: > >> Hi David, >> >> Thanks for the suggestion! It indeed make sense for the Junit >> example... However, my particular usage case for assumption is a bit >> different. I am using jruby+jspec and I have a group of rspec examples >> that all require a java property to be set for the examples to be able >> to run. Besides, the examples also have an after action that will also >> break if the java propety is not set. Idealy, I would like to do >> something like. >> >> before(:all) do >> @org_root_prop = java.lang.System.getProperty("root") >> >> # abort all examples and after action if condition is not meet: >> ensure_that !rootPath.nil? && rootPath.strip.length>0 >> end >> >> Notice, that the assume is in a before action and not in the examples >> themselves + it should affect the examples and after action (none of >> which should run if before action assumptions are not meet). >> >> /Morten >> >> >> On Jun 1, 12:58 pm, David Chelimsky wrote: >> >>> On Mon, Jun 1, 2009 at 5:33 AM, mortench wrote: >>> >>>> JUnit 4.4+ has a feature called assumptions and I am looking for >>>> something similar in rspec so that I can express that my examples >>>> require a specific environment variable to be specified for testing to >>>> make sense. >>>> >>> There is no explicit support for this, but you could always just say >>> (taking the example from the page you cited): >>> >>> def assume_that(expression) >>> yield if expression >>> end >>> >>> def verify_that(actual, expected) >>> actual.should expected >>> end >>> >>> it "should blah de blah" do >>> assume_that(File::SEPARATOR == "/") do >>> ensure_that User.new("optimus"), eql("configfiles/optimus.cfg") >>> end >>> end >>> >>> I am planning to add support for something like ensure_that (name up >>> for grabs) in a future version of rspec, but I'd need to think about >>> assume_that a bit. We're dealing with Ruby here, not Java, and we >>> don't suffer things like a 'final' keyword that force us to have to >>> make assumptions like this. Unless we add some additional feedback, >>> like "such and such example did not run due to faulty assumptions," >>> this seems quite dangerous to me. And even with that, it means that CI >>> servers are going to pass examples that are never actually run. >>> >>> HTH, >>> David >>> >>> >>> >>> >>> >>> >>>> About assumptions from the readme (http://junit.sourceforge.net/doc/ >>>> ReleaseNotes4.4.html#assumptions): >>>> "Ideally, the developer writing a test has control of all of the >>>> forces that might cause a test to fail. If this isn't immediately >>>> possible, making dependencies explicit can often improve a design. >>>> For example, if a test fails when run in a different locale than the >>>> developer intended, it can be fixed by explicitly passing a locale to >>>> the domain code. >>>> >>>> However, sometimes this is not desirable or possible. >>>> It's good to be able to run a test against the code as it is currently >>>> written, implicit assumptions and all, or to write a test that exposes >>>> a known bug. For these situations, JUnit now includes the ability to >>>> express "assumptions": >>>> " >>>> >>>> /Morten >>>> _______________________________________________ >>>> 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 >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > From pat.maddox at gmail.com Mon Jun 1 14:59:24 2009 From: pat.maddox at gmail.com (Pat Maddox) Date: Mon, 1 Jun 2009 11:59:24 -0700 Subject: [rspec-users] Any way to continue on Assertion Failure In-Reply-To: <4A1C7C40.2020501@employees.org> References: <4A1C7C40.2020501@employees.org> Message-ID: <2c7e61990906011159r3b8e9fbcs846bd75b9d2d7d35@mail.gmail.com> Let's say I've got this spec: describe Team, "add_player" do it "should add a player to the team" do team = Team.new player = Player.new :name => "Pat" team.add_player player team.should have(1).players team.players.first.name.should == "Pat" end end and for some reason team.should have(1).players fails. Do I get any value from seeing the second expectation fail? What if it passes? My suggestion is to break up your long running test flow into bits that you can test individually, that run quickly and independently of each other. Get those tested, and have an integration test which makes sure that everything works together. Pat On Tue, May 26, 2009 at 4:33 PM, Gary Lin wrote: > Hi, > > I wonder if there is any way to tell the test script to continue even when > encountering an assertion failure? ?The reason I am asking this is because I > have a test flow that can take a long time to run and it would be very > useful if I can perform all verification at the end of test flow in one shot > rather than fail one and exit immediately. ?Of course, I could break each > verification point into separate test case, but then it will double or > triple the overall execution time. ?Does RSpec support this? > > Thanks, > > --Gary > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pat.maddox at gmail.com Mon Jun 1 15:52:02 2009 From: pat.maddox at gmail.com (Pat Maddox) Date: Mon, 1 Jun 2009 12:52:02 -0700 Subject: [rspec-users] Does rspec support something like Assumptions in JUnit 4.4? In-Reply-To: <4A241837.9090504@aps.org> References: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> <57c63afe0906010358y17cee7d1w452e80b29030e3a2@mail.gmail.com> <852a2dfd-98eb-4b73-af9c-fb482fc69a7f@h2g2000yqg.googlegroups.com> <2c7e61990906010951w5b66ac2ei97401a07cafc970d@mail.gmail.com> <4A241837.9090504@aps.org> Message-ID: <2c7e61990906011252p7357d9f8mbef3dc90ee90e866@mail.gmail.com> Right, and in the code example I gave, if those preconditions fail then the rest of the example won't be run. There's not really any need for a new semantic element in RSpec, it already works this way out of the box. You can do it "should do something" do some_precondition.should be_met an_object.do_something some_postcondition.should be_met end If the precondition is not met, the example fails and halts right there. If you do want to visually distinguish them for some reason, you can do so easily: def assumptions yield end it "should do something" do assumptions do some_precondition.should be_met end an_object.do_something some_postcondition.should be_met end I personally wouldn't :) but you could. I often use precondition expectations in my examples. It helps me know where an error is more quickly. I don't waste time tracking down errors that result from some precondition (assumption) being incorrect. Pat On Mon, Jun 1, 2009 at 11:04 AM, Arthur Smith wrote: > I thought the point was we don't want the examples to be run at all, if the > condition is not met? Though I'm wondering why not just handle something > like this with a stub (on System.getProperty in this case)? > > ? ? ?Arthur Smith > > Pat Maddox wrote: >> >> You can put expectations in your before block, and that'll give you >> the behavior you want. >> >> before(:each) do >> ? @org_root_prop = java.lang.System.getProperty("root") >> >> ? @org_root_prop.should_not be_nil >> ? @org_root_prop.trim.should_not be_empty >> end >> >> If either of those expectations fail then the examples that require >> that property will report failures. ?If I were using this all over the >> place, I would write a custom matcher. >> >> before(:each) do >> ?java.lang.System.should have_property("root") >> ?@org_root_prop = java.lang.System.getProperty("root") >> end >> >> This would allow you to define your own error message and perform more >> sophisticated expectations (see the have_tag/with_tag example in >> rspec-rails). >> >> Note that you should be doing this check in before(:each) because you >> want it to run before each example. ?Also you should be using >> before(:each) 99% of the time anyway. >> >> Pat >> >> On Mon, Jun 1, 2009 at 4:12 AM, mortench wrote: >> >>> >>> Hi David, >>> >>> Thanks for the suggestion! It indeed make sense for the Junit >>> example... However, my particular usage case for assumption is a bit >>> different. I am using jruby+jspec and I have a group of rspec examples >>> that all require a java property to be set for the examples to be able >>> to run. Besides, the examples also have an after action that will also >>> break if the java propety is not set. Idealy, I would like to do >>> something like. >>> >>> before(:all) do >>> ? @org_root_prop = java.lang.System.getProperty("root") >>> >>> ? # abort all examples and after action if condition is not meet: >>> ? ensure_that !rootPath.nil? && rootPath.strip.length>0 >>> end >>> >>> Notice, that the assume is in a before action and not in the examples >>> themselves + it should affect the examples and after action (none of >>> which should run if before action assumptions are not meet). >>> >>> /Morten >>> >>> >>> On Jun 1, 12:58 pm, David Chelimsky wrote: >>> >>>> >>>> On Mon, Jun 1, 2009 at 5:33 AM, mortench wrote: >>>> >>>>> >>>>> JUnit 4.4+ has a feature called assumptions and I am looking for >>>>> something similar in rspec so that I can express that my examples >>>>> require a specific environment variable to be specified for testing to >>>>> make sense. >>>>> >>>> >>>> There is no explicit support for this, but you could always just say >>>> (taking the example from the page you cited): >>>> >>>> def assume_that(expression) >>>> ?yield if expression >>>> end >>>> >>>> def verify_that(actual, expected) >>>> ?actual.should expected >>>> end >>>> >>>> it "should blah de blah" do >>>> ?assume_that(File::SEPARATOR == "/") do >>>> ? ?ensure_that User.new("optimus"), eql("configfiles/optimus.cfg") >>>> ?end >>>> end >>>> >>>> I am planning to add support for something like ensure_that (name up >>>> for grabs) in a future version of rspec, but I'd need to think about >>>> assume_that a bit. We're dealing with Ruby here, not Java, and we >>>> don't suffer things like a 'final' keyword that force us to have to >>>> make assumptions like this. Unless we add some additional feedback, >>>> like "such and such example did not run due to faulty assumptions," >>>> this seems quite dangerous to me. And even with that, it means that CI >>>> servers are going to pass examples that are never actually run. >>>> >>>> HTH, >>>> David >>>> >>>> >>>> >>>> >>>> >>>> >>>>> >>>>> About assumptions from the readme (http://junit.sourceforge.net/doc/ >>>>> ReleaseNotes4.4.html#assumptions): >>>>> "Ideally, the developer writing a test has control of all of the >>>>> forces that might cause a test to fail. If this isn't immediately >>>>> possible, making dependencies explicit can often improve a design. >>>>> For example, if a test fails when run in a different locale than the >>>>> developer intended, it can be fixed by explicitly passing a locale to >>>>> the domain code. >>>>> ? ? ? ?However, sometimes this is not desirable or possible. >>>>> It's good to be able to run a test against the code as it is currently >>>>> written, implicit assumptions and all, or to write a test that exposes >>>>> a known bug. For these situations, JUnit now includes the ability to >>>>> express "assumptions": >>>>> " >>>>> ? ? ? ?/Morten >>>>> _______________________________________________ >>>>> 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 >>> >>> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mortench at gmail.com Mon Jun 1 15:57:48 2009 From: mortench at gmail.com (mortench) Date: Mon, 1 Jun 2009 12:57:48 -0700 (PDT) Subject: [rspec-users] Does rspec support something like Assumptions in JUnit 4.4? In-Reply-To: <4A241837.9090504@aps.org> References: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> <57c63afe0906010358y17cee7d1w452e80b29030e3a2@mail.gmail.com> <852a2dfd-98eb-4b73-af9c-fb482fc69a7f@h2g2000yqg.googlegroups.com> <2c7e61990906010951w5b66ac2ei97401a07cafc970d@mail.gmail.com> <4A241837.9090504@aps.org> Message-ID: <970827e0-e79b-49c2-8bc2-db37c2de80cc@i6g2000yqj.googlegroups.com> On Jun 1, 8:04?pm, Arthur Smith wrote: > I thought the point was we don't want the examples to be run at all, if > the condition is not met? Yes. >Though I'm wondering why not just handle > something like this with a stub (on System.getProperty in this case)? Because the examples need the info in the property to work. The property provides reference values that the test use to compare against. Hence it makes no sense to stub anything out. ALL: Thanks for all the help! /Morten From matt at mattwynne.net Mon Jun 1 16:56:07 2009 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 1 Jun 2009 21:56:07 +0100 Subject: [rspec-users] Does rspec support something like Assumptions in JUnit 4.4? In-Reply-To: <2c7e61990906011252p7357d9f8mbef3dc90ee90e866@mail.gmail.com> References: <93dcccd4-bc27-427e-bbc0-c1f3ef313317@c19g2000yqc.googlegroups.com> <57c63afe0906010358y17cee7d1w452e80b29030e3a2@mail.gmail.com> <852a2dfd-98eb-4b73-af9c-fb482fc69a7f@h2g2000yqg.googlegroups.com> <2c7e61990906010951w5b66ac2ei97401a07cafc970d@mail.gmail.com> <4A241837.9090504@aps.org> <2c7e61990906011252p7357d9f8mbef3dc90ee90e866@mail.gmail.com> Message-ID: <6D52AC7F-0AD0-48A6-A274-01715364BC7C@mattwynne.net> On 1 Jun 2009, at 20:52, Pat Maddox wrote: > You can do > > it "should do something" do > some_precondition.should be_met > an_object.do_something > some_postcondition.should be_met > end Also, more verbosely... describe "when there is some precondition" before(:each) do do_stuff_which_attempts_to_set_up_some_precondition some_precondition.should be_met end it "should do something" an_object.do_something some_postcondition.should be_met end end Which, can often make your specs read nicely. I also offers an obvious space to think of a few more examples to throw in there. cheers, Matt From Jarmo.P at gmail.com Mon Jun 1 17:10:55 2009 From: Jarmo.P at gmail.com (Jarmo Pertman) Date: Mon, 1 Jun 2009 14:10:55 -0700 (PDT) Subject: [rspec-users] autospec runs failing specs forever in endless loop In-Reply-To: <57c63afe0905311456m28f97a25tb3f915aa21a57f9e@mail.gmail.com> References: <323c176b-321f-4197-ba30-2f6c02112ed1@t21g2000yqi.googlegroups.com> <57c63afe0905311456m28f97a25tb3f915aa21a57f9e@mail.gmail.com> Message-ID: <4e0f2a76-f515-492d-9992-341b2221f54a@r34g2000vbi.googlegroups.com> No, I didn't have that one, but had one similar problem where one of my specs edited one non-Ruby file, which caused autotest to reload. I solved that problem by explicitly ignoring it in autotest. I was surprised that autotest cares about non-mapped files :) But now I have another problem - it seems that autotest doesn't understand always when something really failed and it seems to be due to the fact that autotest.rb has this line: self.failed_results_re = /^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?) \)/ It doesn't match correctly with most of the failing specs so Snarl (like Growl for Windows) shows that tests are passing when they're actually not. So, I digged around a little more to see if RSpec modifies this regular expression somewhere and I found it at lib/ autotest/rspec.rb and there is this class Autotest::Rspec < Autotest, which overwrites failed_results_re as: self.failed_results_re = /^\d+\) \n(?:\e\[\d*m)?(?:.*?in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n \n/m This autotest thing seems to be quite strange, because if I added some puts statements into discover.rb and rspec.rb then they didn't seem to get executed, BUT if I putsed this failed_results_re in autotest.rb itself, then it was set correctly as written above. My .autotest file is as following: require 'autotest/menu' require 'autotest/snarl' Autotest.add_hook :initialize do |at| at.add_exception(/\.sqlite/) at.add_exception(/^\.git/) end And spec.opts is like this: -r spec/env.rb -c And I'm running autospec and seeing this output: 1) 'correct year' FAILED expected "2008" got "2009" (compared using eql?) ./spec/year_spec.rb:38: Finished in 5.918 seconds 11 examples, 1 failure And when I added to autotest.rb line 410 this: p self.files_to_test Then the resulted hash was empty, e.g. this line sets result to "green": color = completed && self.files_to_test.empty? ? :green : :red When I break some other test with different error message like this, then Snarl shows me failing tests: 1) NoMethodError in 'DatabaseOperations adds options' undefined method `[]' for nil:NilClass ./spec/database_operations_spec.rb:50: The difference is that failing reason is shown on one line, instead of two lines. Also, p elf.files_to_test results in "normal" result: {"spec/database_operations_spec.rb"=>["DatabaseOperations adds options", "DatabaseOperations adds new default_options if some are missing"]} - Is it possible that this regular expression is little outdated and can't handle the situation where failing reason is shown on 2 lines? - Why won't anything puts'ed from autotest/discover.rb or autotest/ rspec.rb like they aren't loaded? - Any other reasons why autotest behaviour might be broken? Jarmo On Jun 1, 12:56?am, David Chelimsky wrote: > On Sun, May 31, 2009 at 3:59 PM, Jarmo Pertman wrote: > > I wanted to start using autospec on my little (non-Rails) project. I'm > > on Windows XP and have used it some time ago successfully (on the same > > PC), although I've updated many gems in the meantime (RSpec for > > example among others). > > > In short, everything is fine when all specs pass, but if some fails, > > then autospec won't stop running failing specs again even if no files > > are changed. I expect it to run specs again only if some file gets > > modified. It's kinda irritating when it doesn't stop and is by no > > means helping any development :/ > > > Also, when I fix the failing spec then it will run it only once and > > then run whole suit once and stops as expected. > > > Any ideas what might cause this distracting behaviour? > > Do you have "--format failing_examples" in spec/spec.opts? If so, > rspec saves a file with a list of the failing examples in it, which > would trigger autotest to run again unless that file is explicitly > ignored. > > HTH, > David > > > > > BR, > > Jarmo > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From timcharper at gmail.com Tue Jun 2 01:58:50 2009 From: timcharper at gmail.com (Tim Harper) Date: Mon, 1 Jun 2009 23:58:50 -0600 Subject: [rspec-users] spec_server errors when reloading fixture replacement pl In-Reply-To: <5e62f6f34e444a8e7267736994822cd8@ruby-forum.com> References: <1106da77-505a-4262-b9df-a67c9af6027b@w35g2000prg.googlegroups.com> <57c63afe0905010704r254bab7bn5ac3d32b8027672f@mail.gmail.com> <4A173837.7090605@railsnewbie.com> <4A18D839.6030709@benmabey.com> <4A1913CE.4070409@railsnewbie.com> <4A1A29D3.9020102@benmabey.com> <3c30da400905261022t1839a207m5824fad50b73a846@mail.gmail.com> <5e62f6f34e444a8e7267736994822cd8@ruby-forum.com> Message-ID: Ben J., Have you given up on this? You're right - that defeats the purpose of Spork. You need to make sure that any code that loads code in your project does not make it in to your Spork.prefork block. If you are specifically loading the models in your environment, that's your problem. Here's some possible options to resolve what you're experiencing: 1) Add spork blocks to your environment.rb to put portions that are loading code you develop on inside of a Spork.each_run block, and the rest of it in a Spork.prefork block. 2) modify your environment.rb file to only load libraries like gems and plug-ins, and set up autoload to load the rest of your classes as you need them. Alternatively, is this is a matter of pre-caching, you could choose not to load those classes preemptively in the test environment. -------------- next part -------------- An HTML attachment was scrubbed... URL: From evgeny.bogdanov at gmail.com Tue Jun 2 03:50:25 2009 From: evgeny.bogdanov at gmail.com (Evgeny Bogdanov) Date: Tue, 2 Jun 2009 00:50:25 -0700 (PDT) Subject: [rspec-users] [rspec] How to pass route parameters to post method? Message-ID: <93124666-d42b-4381-8905-39915eceaae9@j32g2000yqh.googlegroups.com> Hello, I am trying to spec an action in a controller, and rspec doesn't find a route. It seems that problem is in ":viewtype". If I change a line "/:viewtype/asset/add" into "/context/asset/add" in routes it works. I tried also post "/context/asset/add", no luck. Could you please let me know how I can call the action through that route with post method? Thank you in advance, Evgeny ===================== map.with_options(:controller => "assets", :conditions =>{:method => :post}) do |m| m.create_asset '/:viewtype/asset/ add', :action => 'create' end describe AssetsController, "when working with formats" do it "should call a find_asset_format for some actions" do post :create end end From lists at ruby-forum.com Tue Jun 2 11:53:33 2009 From: lists at ruby-forum.com (Wolfram Arnold) Date: Tue, 2 Jun 2009 17:53:33 +0200 Subject: [rspec-users] Cucumber vs Rails Fixtures In-Reply-To: <4A1445E1.3070204@benmabey.com> References: <4A1445E1.3070204@benmabey.com> Message-ID: >> How do I actually use real, pre-existing Rails fixtures, the same as >> the unit tests use? For familiarity? What I was missing is the regular use of fixtures as in rspec or test unit, like so: u = users(:bob) u.email = "aaa" u.should_not be_valid This link > > http://wiki.github.com/aslakhellesoy/cucumber/fixtures > described how to get fixtures loaded for the entire suite, so that you can say: u = User.find(1) or u = User.find_by_name("Bob") this is kind of a drag, if you have a well formed fixture file with symbolic names, etc. So I came up with this (which was developed and tested in Cucumber gem version 0.2.3, and I haven't tried it yet with the latest 0.3.9): Add this to your env file: Fixtures.reset_cache fixtures_folder = File.join(RAILS_ROOT, 'test', 'fixtures') fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') } fixtures << Dir[File.join(fixtures_folder, '*.csv')].map {|f| File.basename(f, '.csv') } # If your fixture files are named differently from the classes they refer to, # you also need to do this: # # class_table_mappings = {:table_name_in_db => class_name} # Fixtures.create_fixtures(fixtures_folder, fixtures, class_table_mappings) # # otherwise: # This will populate the test database tables Fixtures.create_fixtures(fixtures_folder, fixtures) # The following will define methods that can access symbolic fixture names, # as in users(:bob) World do |world| (class << world; self; end).class_eval do @@fixture_cache = {} fixtures.each do |table_name| table_name = table_name.to_s.tr('.', '_') define_method(table_name) do |*fixture_symbols| @@fixture_cache[table_name] ||= {} instances = fixture_symbols.map do |fixture_symbol| if fix = Fixtures.cached_fixtures(ActiveRecord::Base.connection, table_name)[fixture_symbol.to_s] @@fixture_cache[table_name][fixture_symbol] ||= fix.find # find model.find's the instance else raise StandardError, "No fixture with name '#{fixture_symbol}' found for table '#{table_name}'" end end instances.size == 1 ? instances.first : instances end end end world end -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Jun 2 12:03:15 2009 From: lists at ruby-forum.com (Wolfram Arnold) Date: Tue, 2 Jun 2009 18:03:15 +0200 Subject: [rspec-users] Cucumber vs Rails Fixtures In-Reply-To: References: <4A1445E1.3070204@benmabey.com> Message-ID: <001e00da53125003ed65f21a2fedc492@ruby-forum.com> I've updated http://wiki.github.com/aslakhellesoy/cucumber/fixtures accordingly. -- Posted via http://www.ruby-forum.com/. From Jarmo.P at gmail.com Tue Jun 2 12:07:33 2009 From: Jarmo.P at gmail.com (Jarmo Pertman) Date: Tue, 2 Jun 2009 09:07:33 -0700 (PDT) Subject: [rspec-users] autospec runs failing specs forever in endless loop In-Reply-To: <4e0f2a76-f515-492d-9992-341b2221f54a@r34g2000vbi.googlegroups.com> References: <323c176b-321f-4197-ba30-2f6c02112ed1@t21g2000yqi.googlegroups.com> <57c63afe0905311456m28f97a25tb3f915aa21a57f9e@mail.gmail.com> <4e0f2a76-f515-492d-9992-341b2221f54a@r34g2000vbi.googlegroups.com> Message-ID: <1169fe9c-dd76-4dd5-8d93-e9c42c052f3d@j18g2000yql.googlegroups.com> Ok. I've created failing example. Just create project directory and spec directory into it and add there one spec file: describe "autospec" do it "fails" do "hi".should eql("hello") end end It fails, but for autotest it is still green (thus making growl and snarl to report as everything is passing) and now I'm pretty sure that it has to do with the fact that "should eql" outputs "expected" and "got" result on different lines. As soon as you replace the matcher to: "hi".eql?("hello").should be_true - then output is on single line and autotest detects it as failing. Still, problem is with the regular expression provided for autotest? Jarmo From dchelimsky at gmail.com Tue Jun 2 12:50:03 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 2 Jun 2009 11:50:03 -0500 Subject: [rspec-users] autospec runs failing specs forever in endless loop In-Reply-To: <1169fe9c-dd76-4dd5-8d93-e9c42c052f3d@j18g2000yql.googlegroups.com> References: <323c176b-321f-4197-ba30-2f6c02112ed1@t21g2000yqi.googlegroups.com> <57c63afe0905311456m28f97a25tb3f915aa21a57f9e@mail.gmail.com> <4e0f2a76-f515-492d-9992-341b2221f54a@r34g2000vbi.googlegroups.com> <1169fe9c-dd76-4dd5-8d93-e9c42c052f3d@j18g2000yql.googlegroups.com> Message-ID: <57c63afe0906020950q65932ac4k937768b7b78b72d8@mail.gmail.com> On Tue, Jun 2, 2009 at 11:07 AM, Jarmo Pertman wrote: > Ok. I've created failing example. > > Just create project directory and spec directory into it and add there > one spec file: > > describe "autospec" do > > ? ? ? ?it "fails" do > ? ? ? ? ? ? ? ?"hi".should eql("hello") > ? ? ? ?end > > end > > It fails, but for autotest it is still green (thus making growl and > snarl to report as everything is passing) and now I'm pretty sure that > it has to do with the fact that "should eql" outputs "expected" and > "got" result on different lines. As soon as you replace the matcher > to: "hi".eql?("hello").should be_true - then output is on single line > and autotest detects it as failing. > > Still, problem is with the regular expression provided for autotest? Seems likely. Wanna make a proper patch w/ specs? > > Jarmo > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From Jarmo.P at gmail.com Tue Jun 2 13:31:48 2009 From: Jarmo.P at gmail.com (Jarmo Pertman) Date: Tue, 2 Jun 2009 10:31:48 -0700 (PDT) Subject: [rspec-users] autospec runs failing specs forever in endless loop In-Reply-To: <57c63afe0906020950q65932ac4k937768b7b78b72d8@mail.gmail.com> References: <323c176b-321f-4197-ba30-2f6c02112ed1@t21g2000yqi.googlegroups.com> <57c63afe0905311456m28f97a25tb3f915aa21a57f9e@mail.gmail.com> <4e0f2a76-f515-492d-9992-341b2221f54a@r34g2000vbi.googlegroups.com> <1169fe9c-dd76-4dd5-8d93-e9c42c052f3d@j18g2000yql.googlegroups.com> <57c63afe0906020950q65932ac4k937768b7b78b72d8@mail.gmail.com> Message-ID: Done at https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/832-autotest-not-detecting-failing-examples-correctly-when-matcher-outputs-multiple-lines-of-information I started even before you've replied, because that bugged me too much :) Jarmo On Jun 2, 7:50?pm, David Chelimsky wrote: > Seems likely. Wanna make a proper patch w/ specs? From dchelimsky at gmail.com Wed Jun 3 10:38:38 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Jun 2009 09:38:38 -0500 Subject: [rspec-users] infoworld article on BDD Message-ID: <57c63afe0906030738j7cafdbadlff1c816ad78e33b9@mail.gmail.com> infoworld article on BDD http://www.infoworld.com/d/developer-world/behavior-driven-development-catches-605 Good article other than "Behavior" (sans u) and "BDD insists on inside-out." From rick.denatale at gmail.com Wed Jun 3 11:14:00 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 3 Jun 2009 11:14:00 -0400 Subject: [rspec-users] New Zentest, any feedback? Message-ID: So I notice that Ryan released a new zentest gem today. It looks like it has been refactored a bit. Are there any brave guinea pigs/canaries in the RSpec/Cucumber community who have tried it out? Any issues? I do see that someone has been reporting some problems with multiruby which is a part of zentest which a lot of folks don't use as much. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From joe at pinkpucker.net Wed Jun 3 13:01:52 2009 From: joe at pinkpucker.net (Joe Van Dyk) Date: Wed, 3 Jun 2009 10:01:52 -0700 Subject: [rspec-users] having autospec run tests? Message-ID: Hi, On one project, I have cucumber features and test/unit (well, i guess activesupport::testcase) tests. I really like how: AUTOFEATURE=true autospec works on my projects that use rspec and cucumber. Can I get that same behavior, but with my tests in the tests directory? Joe From sfeley at gmail.com Wed Jun 3 13:28:28 2009 From: sfeley at gmail.com (Stephen Eley) Date: Wed, 3 Jun 2009 13:28:28 -0400 Subject: [rspec-users] having autospec run tests? In-Reply-To: References: Message-ID: <1fb4df0906031028s3a582ee4jaf1a618d9a54a12c@mail.gmail.com> On Wed, Jun 3, 2009 at 1:01 PM, Joe Van Dyk wrote: > > I really like how: > AUTOFEATURE=true autospec > works on my projects that use rspec and cucumber. > > Can I get that same behavior, but with my tests in the tests directory? Sure. In fact it should work just fine out of the box: do the same thing, but with 'autotest' instead of 'autospec'. (The check for that environment variable isn't in the autospec script, it's in the discovery file that Cucumber sets up.) -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Wed Jun 3 13:46:13 2009 From: lists at ruby-forum.com (Sebastian W.) Date: Wed, 3 Jun 2009 19:46:13 +0200 Subject: [rspec-users] Mock should receive no messages? Message-ID: <94197c1d081e58d8af50fc2f70fbcdbf@ruby-forum.com> Hello all, Is there a way to explicitly tell a mock to expect no messages and give an error if it does? I believe this is the default behavior, but thought it might be nice for code readers to see. Thank you! -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Jun 3 14:01:39 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Jun 2009 13:01:39 -0500 Subject: [rspec-users] Mock should receive no messages? In-Reply-To: <94197c1d081e58d8af50fc2f70fbcdbf@ruby-forum.com> References: <94197c1d081e58d8af50fc2f70fbcdbf@ruby-forum.com> Message-ID: <57c63afe0906031101tcd56c45xd36a2974026785de@mail.gmail.com> On Wed, Jun 3, 2009 at 12:46 PM, Sebastian W. wrote: > Hello all, > Is there a way to explicitly tell a mock to expect no messages and give > an error if it does? I believe this is the default behavior, but thought > it might be nice for code readers to see. You can tell it to expect not to receive a specific message, but there is no way to say that it should not receive any messages. Cheers, David > > Thank you! From lists at ruby-forum.com Wed Jun 3 14:19:37 2009 From: lists at ruby-forum.com (Sebastian W.) Date: Wed, 3 Jun 2009 20:19:37 +0200 Subject: [rspec-users] Mock should receive no messages? In-Reply-To: <57c63afe0906031101tcd56c45xd36a2974026785de@mail.gmail.com> References: <94197c1d081e58d8af50fc2f70fbcdbf@ruby-forum.com> <57c63afe0906031101tcd56c45xd36a2974026785de@mail.gmail.com> Message-ID: <86f8ef0bee3e4b32d30fcacf42af4b48@ruby-forum.com> David Chelimsky wrote: > On Wed, Jun 3, 2009 at 12:46 PM, Sebastian W. > wrote: >> Hello all, >> Is there a way to explicitly tell a mock to expect no messages and give >> an error if it does? I believe this is the default behavior, but thought >> it might be nice for code readers to see. > > You can tell it to expect not to receive a specific message, but there > is no way to say that it should not receive any messages. > > Cheers, > David Okay, cool - feature request? : ) -- Posted via http://www.ruby-forum.com/. From rick.denatale at gmail.com Wed Jun 3 14:26:18 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 3 Jun 2009 14:26:18 -0400 Subject: [rspec-users] Mock should receive no messages? In-Reply-To: <57c63afe0906031101tcd56c45xd36a2974026785de@mail.gmail.com> References: <94197c1d081e58d8af50fc2f70fbcdbf@ruby-forum.com> <57c63afe0906031101tcd56c45xd36a2974026785de@mail.gmail.com> Message-ID: On Wed, Jun 3, 2009 at 2:01 PM, David Chelimsky wrote: > On Wed, Jun 3, 2009 at 12:46 PM, Sebastian W. wrote: >> Hello all, >> Is there a way to explicitly tell a mock to expect no messages and give >> an error if it does? I believe this is the default behavior, but thought >> it might be nice for code readers to see. > > You can tell it to expect not to receive a specific message, but there > is no way to say that it should not receive any messages. Maybe not explicitly but doesn't isn't making a mock with no expectations effectively the same thing: describe "an object which should not get any messages" do it "should not receive any messages" do o = mock("Object") o.foo end end Mock 'Object' received unexpected message :foo with (no args) -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From dchelimsky at gmail.com Wed Jun 3 14:30:48 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Jun 2009 13:30:48 -0500 Subject: [rspec-users] Mock should receive no messages? In-Reply-To: References: <94197c1d081e58d8af50fc2f70fbcdbf@ruby-forum.com> <57c63afe0906031101tcd56c45xd36a2974026785de@mail.gmail.com> Message-ID: <57c63afe0906031130q75e6ed17h2ec646f7b6c96626@mail.gmail.com> On Wed, Jun 3, 2009 at 1:26 PM, Rick DeNatale wrote: > On Wed, Jun 3, 2009 at 2:01 PM, David Chelimsky wrote: >> On Wed, Jun 3, 2009 at 12:46 PM, Sebastian W. wrote: >>> Hello all, >>> Is there a way to explicitly tell a mock to expect no messages and give >>> an error if it does? I believe this is the default behavior, but thought >>> it might be nice for code readers to see. >> >> You can tell it to expect not to receive a specific message, but there >> is no way to say that it should not receive any messages. > > Maybe not explicitly but doesn't isn't making a mock with no > expectations effectively the same thing: > > describe "an object which should not get any messages" do > ?it "should not receive any messages" do > ? ?o = mock("Object") > ? ?o.foo > ?end > end > > Mock 'Object' received unexpected message :foo with (no args) Right - Sebastian noted that in the original post - but he's looking for something explicit. > -- > Rick DeNatale > > Blog: http://talklikeaduck.denhaven2.com/ > Twitter: http://twitter.com/RickDeNatale > WWR: http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn: http://www.linkedin.com/in/rickdenatale From joe at fixieconsulting.com Wed Jun 3 14:30:56 2009 From: joe at fixieconsulting.com (Joe Van Dyk) Date: Wed, 3 Jun 2009 11:30:56 -0700 Subject: [rspec-users] having autospec run tests? In-Reply-To: <1fb4df0906031028s3a582ee4jaf1a618d9a54a12c@mail.gmail.com> References: <1fb4df0906031028s3a582ee4jaf1a618d9a54a12c@mail.gmail.com> Message-ID: autotest doesn't seem to work for me, for some reason: that file doesn't get loaded when autospec runs. /home/joe/projects/zoolah/vendor/plugins/mocha/lib/mocha/integration/test_unit.rb:17:in `remove_method': method `run' not defined in Test::Unit::TestCase (NameError) from /home/joe/projects/zoolah/vendor/plugins/mocha/lib/mocha/integration/test_unit.rb:17 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `polyglot_original_require' from /home/joe/projects/zoolah/vendor/gems/polyglot-0.2.5/lib/polyglot.rb:54:in `require' from /home/joe/projects/zoolah/vendor/rails/activesupport/lib/active_support/dependencies.rb:158:in `require' from /home/joe/projects/zoolah/vendor/rails/activesupport/lib/active_support/dependencies.rb:265:in `require_or_load' from /home/joe/projects/zoolah/vendor/rails/activesupport/lib/active_support/dependencies.rb:425:in `load_missing_constant' from /home/joe/projects/zoolah/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:in `const_missing' ... 11 levels... from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run' from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run' from /usr/local/lib/ruby/1.8/test/unit.rb:278 from -e:1 On Wed, Jun 3, 2009 at 10:28 AM, Stephen Eley wrote: > On Wed, Jun 3, 2009 at 1:01 PM, Joe Van Dyk wrote: >> >> I really like how: >> AUTOFEATURE=true autospec >> works on my projects that use rspec and cucumber. >> >> Can I get that same behavior, but with my tests in the tests directory? > > Sure. ?In fact it should work just fine out of the box: do the same > thing, but with 'autotest' instead of 'autospec'. ?(The check for that > environment variable isn't in the autospec script, it's in the > discovery file that Cucumber sets up.) > > > -- > Have Fun, > ? Steve Eley (sfeley at gmail.com) > ? ESCAPE POD - The Science Fiction Podcast Magazine > ? http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Wed Jun 3 14:36:40 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 3 Jun 2009 14:36:40 -0400 Subject: [rspec-users] Mock should receive no messages? In-Reply-To: <57c63afe0906031130q75e6ed17h2ec646f7b6c96626@mail.gmail.com> References: <94197c1d081e58d8af50fc2f70fbcdbf@ruby-forum.com> <57c63afe0906031101tcd56c45xd36a2974026785de@mail.gmail.com> <57c63afe0906031130q75e6ed17h2ec646f7b6c96626@mail.gmail.com> Message-ID: On Wed, Jun 3, 2009 at 2:30 PM, David Chelimsky wrote: > On Wed, Jun 3, 2009 at 1:26 PM, Rick DeNatale wrote: >> On Wed, Jun 3, 2009 at 2:01 PM, David Chelimsky wrote: >>> On Wed, Jun 3, 2009 at 12:46 PM, Sebastian W. wrote: >>>> Hello all, >>>> Is there a way to explicitly tell a mock to expect no messages and give >>>> an error if it does? I believe this is the default behavior, but thought >>>> it might be nice for code readers to see. >>> >>> You can tell it to expect not to receive a specific message, but there >>> is no way to say that it should not receive any messages. >> >> Maybe not explicitly but doesn't isn't making a mock with no >> expectations effectively the same thing: >> >> describe "an object which should not get any messages" do >> ?it "should not receive any messages" do >> ? ?o = mock("Object") >> ? ?o.foo >> ?end >> end >> >> Mock 'Object' received unexpected message :foo with (no args) > > Right - Sebastian noted that in the original post - but he's looking > for something explicit. Well how about: describe "an object which should not get any messages" do it "should not receive any messages" do o = mock("Object") o.should_not_receive(:a_damned_thing) o.foo end end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From dchelimsky at gmail.com Wed Jun 3 14:37:10 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Jun 2009 13:37:10 -0500 Subject: [rspec-users] Mock should receive no messages? In-Reply-To: <86f8ef0bee3e4b32d30fcacf42af4b48@ruby-forum.com> References: <94197c1d081e58d8af50fc2f70fbcdbf@ruby-forum.com> <57c63afe0906031101tcd56c45xd36a2974026785de@mail.gmail.com> <86f8ef0bee3e4b32d30fcacf42af4b48@ruby-forum.com> Message-ID: <57c63afe0906031137m1d107fb4y78ea7d709adf57a2@mail.gmail.com> On Wed, Jun 3, 2009 at 1:19 PM, Sebastian W. wrote: > David Chelimsky wrote: >> On Wed, Jun 3, 2009 at 12:46 PM, Sebastian W. >> wrote: >>> Hello all, >>> Is there a way to explicitly tell a mock to expect no messages and give >>> an error if it does? I believe this is the default behavior, but thought >>> it might be nice for code readers to see. >> >> You can tell it to expect not to receive a specific message, but there >> is no way to say that it should not receive any messages. >> >> Cheers, >> David > > Okay, cool - feature request? : ) You never have to ask to make a feature request - just make one: http://rspec.lighthouseapp.com > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From kero at chello.nl Wed Jun 3 17:29:14 2009 From: kero at chello.nl (Kero van Gelder) Date: Wed, 3 Jun 2009 23:29:14 +0200 Subject: [rspec-users] New Zentest, any feedback? In-Reply-To: References: Message-ID: <20090603212914.GA30527@bumblebee.m38c.nl> > So I notice that Ryan released a new zentest gem today. It looks like > it has been refactored a bit. > > Are there any brave guinea pigs/canaries in the RSpec/Cucumber > community who have tried it out? Any issues? I do see that someone > has been reporting some problems with multiruby which is a part of > zentest which a lot of folks don't use as much. A quick test shows that it still reruns cucumber when I change a feature and runs rspec when I change a ruby file. and that it does not rerun anything when I touch a file for which there is an exception (e.g. when I do something with git, add_exception %r{\.git} triggers nothing anymore, whereas the previous gem triggered a run of cucumber, which was remendously annoying). I'm not using rails and also not using any other sort of additional framework. no webrat, etc. Bye, Kero. ___ How can I change the world if I can't even change myself? -- Faithless, Salva Mea From jona.hunt777 at gmail.com Thu Jun 4 01:53:25 2009 From: jona.hunt777 at gmail.com (Hunt Jon) Date: Thu, 4 Jun 2009 14:53:25 +0900 Subject: [rspec-users] Difference between spec:server and autospec Message-ID: <5e1f1f1f0906032253n5b528eb1ga0f69d4c1a31a0ea@mail.gmail.com> What's the difference between spec:server and autospec? I understand spec:server is only for a Rails project while autospec can work with any projects. I read http://wiki.github.com/dchelimsky/rspec/spec_server-autospec-nearly-pure-bdd-joy but couldn't understand it. I leave autotest/autospec running during the development. "autotest-fsevent" is very helpful for me, a Mac user. Do we use both at the same time for Rails projects? Jon From scott at railsnewbie.com Thu Jun 4 02:24:53 2009 From: scott at railsnewbie.com (Scott Taylor) Date: Thu, 04 Jun 2009 02:24:53 -0400 Subject: [rspec-users] Difference between spec:server and autospec In-Reply-To: <5e1f1f1f0906032253n5b528eb1ga0f69d4c1a31a0ea@mail.gmail.com> References: <5e1f1f1f0906032253n5b528eb1ga0f69d4c1a31a0ea@mail.gmail.com> Message-ID: <4A2768B5.6020201@railsnewbie.com> Hunt Jon wrote: > What's the difference between spec:server and autospec? > > I wouldn't recommend using spec server - use spork instead: http://github.com/timcharper/spork/tree/master Both load the rails environment, so that each time you run your tests (with script/spec -X or script/spec --drb) you won't have to wait for it to load up (which can take 4-5 seconds). autospec/autotest, on the other hand, polls the filesystem every 3 seconds or so for changes. When it sees one, it reruns just the test or spec file which has changed. Scott From jona.hunt777 at gmail.com Thu Jun 4 03:44:45 2009 From: jona.hunt777 at gmail.com (Hunt Jon) Date: Thu, 4 Jun 2009 16:44:45 +0900 Subject: [rspec-users] Difference between spec:server and autospec In-Reply-To: <4A2768B5.6020201@railsnewbie.com> References: <5e1f1f1f0906032253n5b528eb1ga0f69d4c1a31a0ea@mail.gmail.com> <4A2768B5.6020201@railsnewbie.com> Message-ID: <5e1f1f1f0906040044ja120fddkf830757666031955@mail.gmail.com> Thanks Scott. I don't get what happens if I add --drb to spec/spec.opts files. Can anybody explain to me, please? On Thu, Jun 4, 2009 at 3:24 PM, Scott Taylor wrote: > Hunt Jon wrote: >> >> What's the difference between spec:server and autospec? >> >> > > I wouldn't recommend using spec server - use spork instead: > > http://github.com/timcharper/spork/tree/master > > Both load the rails environment, so that each time you run your tests (with > script/spec -X or script/spec --drb) you won't have to wait for it to load > up (which can take 4-5 seconds). > > autospec/autotest, on the other hand, polls the filesystem every 3 seconds > or so for changes. ?When it sees one, it reruns just the test or spec file > which has changed. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From scott at railsnewbie.com Thu Jun 4 04:14:57 2009 From: scott at railsnewbie.com (Scott Taylor) Date: Thu, 04 Jun 2009 04:14:57 -0400 Subject: [rspec-users] Difference between spec:server and autospec In-Reply-To: <5e1f1f1f0906040044ja120fddkf830757666031955@mail.gmail.com> References: <5e1f1f1f0906032253n5b528eb1ga0f69d4c1a31a0ea@mail.gmail.com> <4A2768B5.6020201@railsnewbie.com> <5e1f1f1f0906040044ja120fddkf830757666031955@mail.gmail.com> Message-ID: <4A278281.6000207@railsnewbie.com> Hunt Jon wrote: > Thanks Scott. > > I don't get what happens if I add --drb > to spec/spec.opts > files. > If you add --drb to your spec.opts (or you run script/spec --drb spec/my_spec.rb) - you will run your specs through the spec server. Without --drb, rails will load up in a fresh process. The *whole point* of the drb server is to speed up load time when running specs. Just to give you an idea, here's the difference for me (with spork instead of the spec server): http://screencast.com/t/qhRvqiXc Scott > Can anybody explain to me, please? > > On Thu, Jun 4, 2009 at 3:24 PM, Scott Taylor wrote: > >> Hunt Jon wrote: >> >>> What's the difference between spec:server and autospec? >>> >>> >>> >> I wouldn't recommend using spec server - use spork instead: >> >> http://github.com/timcharper/spork/tree/master >> >> Both load the rails environment, so that each time you run your tests (with >> script/spec -X or script/spec --drb) you won't have to wait for it to load >> up (which can take 4-5 seconds). >> >> autospec/autotest, on the other hand, polls the filesystem every 3 seconds >> or so for changes. When it sees one, it reruns just the test or spec file >> which has changed. >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pat.maddox at gmail.com Thu Jun 4 20:53:38 2009 From: pat.maddox at gmail.com (Pat Maddox) Date: Thu, 4 Jun 2009 17:53:38 -0700 Subject: [rspec-users] Mock should receive no messages? In-Reply-To: <94197c1d081e58d8af50fc2f70fbcdbf@ruby-forum.com> References: <94197c1d081e58d8af50fc2f70fbcdbf@ruby-forum.com> Message-ID: <2c7e61990906041753g553e6304gb3021e8922e0ef48@mail.gmail.com> On Wed, Jun 3, 2009 at 10:46 AM, Sebastian W. wrote: > Hello all, > Is there a way to explicitly tell a mock to expect no messages and give > an error if it does? I believe this is the default behavior, but thought > it might be nice for code readers to see. Document it in the mock object's name. my_mock = mock('never receives a message') I don't see any reason why something should be added to RSpec core. Pat From amkirwan at gmail.com Thu Jun 4 21:19:35 2009 From: amkirwan at gmail.com (amkirwan) Date: Thu, 4 Jun 2009 18:19:35 -0700 (PDT) Subject: [rspec-users] rspec-rails img src and timestamps Message-ID: <3be7e2cb-b323-44ca-9cce-e4f76d939f98@b1g2000vbc.googlegroups.com> when I run the following matcher bellow it fails because rails adds the timestamp after the file name. I've looked around but have not found anyone else having this problem. I am new to rails and rspec so maybe I am completely missing something obvious. response.should have_selector("#logo", :src => "/images/logo.jpg") From amkirwan at gmail.com Thu Jun 4 21:54:55 2009 From: amkirwan at gmail.com (amkirwan) Date: Thu, 4 Jun 2009 18:54:55 -0700 (PDT) Subject: [rspec-users] rspec-rails img src and timestamps In-Reply-To: <3be7e2cb-b323-44ca-9cce-e4f76d939f98@b1g2000vbc.googlegroups.com> References: <3be7e2cb-b323-44ca-9cce-e4f76d939f98@b1g2000vbc.googlegroups.com> Message-ID: I found the answer to my own question. Just needed to use image_path ("logo.jpg"). Incase anyone else has this is I hope this helps. response.should have_selector("#logo", :src => image_path("logo.jpg")) On Jun 4, 9:19?pm, amkirwan wrote: > when I run the following matcher bellow it fails because rails adds > the timestamp after the file name. I've looked around but have not > found anyone else having this problem. I am new to rails and rspec so > maybe I am completely missing something obvious. > > ?response.should have_selector("#logo", :src => "/images/logo.jpg") > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From amkirwan at gmail.com Thu Jun 4 18:40:38 2009 From: amkirwan at gmail.com (amkirwan) Date: Thu, 4 Jun 2009 15:40:38 -0700 (PDT) Subject: [rspec-users] rspec-rails img src and timestamps Message-ID: There is probably an easy solution to this but I am new to rails and rspec and after searching I cannot seem to find an answer. When I try the following code: response.should have_selector("#logo", :src => "/images/logo.jpg") it fails because rails appends a ? and timestamp to the end of the image name. If I put the full name it passes. response.should have_selector("#logo", :src => "/images/logo.jpg? 1243997048") From matt at mattwynne.net Fri Jun 5 02:54:10 2009 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 5 Jun 2009 07:54:10 +0100 Subject: [rspec-users] rspec-rails img src and timestamps In-Reply-To: References: <3be7e2cb-b323-44ca-9cce-e4f76d939f98@b1g2000vbc.googlegroups.com> Message-ID: <97295A30-F16B-4536-80A2-DCCCE78D100B@mattwynne.net> On 5 Jun 2009, at 02:54, amkirwan wrote: > I found the answer to my own question. Just needed to use image_path > ("logo.jpg"). Incase anyone else has this is I hope this helps. > > response.should have_selector("#logo", :src => image_path("logo.jpg")) I'd have thought there's a marginal risk (if your page renders slowly in the test, for example) that the timestamp might change between rendering the page and running this assertion. Another other way is to use a looser CSS selector, something like response.should have_selector("#logo[src*=logo.jpg]") I can't quite remember the syntax, but the idea is to search for a tag whose src attributes *begins with* 'logo.jpg', thereby ignoring the timestamp entirely. > On Jun 4, 9:19 pm, amkirwan wrote: >> when I run the following matcher bellow it fails because rails adds >> the timestamp after the file name. I've looked around but have not >> found anyone else having this problem. I am new to rails and rspec so >> maybe I am completely missing something obvious. >> >> response.should have_selector("#logo", :src => "/images/logo.jpg") >> _______________________________________________ >> 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 Matt Wynne http://beta.songkick.com http://blog.mattwynne.net From evgeny.bogdanov at gmail.com Fri Jun 5 08:55:55 2009 From: evgeny.bogdanov at gmail.com (Evgeny Bogdanov) Date: Fri, 5 Jun 2009 05:55:55 -0700 (PDT) Subject: [rspec-users] [rspec] How to pass route parameters to post method? In-Reply-To: <339800360906041314k6b3d0ad2v328fe5288f072604@mail.gmail.com> References: <93124666-d42b-4381-8905-39915eceaae9@j32g2000yqh.googlegroups.com> <339800360906041314k6b3d0ad2v328fe5288f072604@mail.gmail.com> Message-ID: <025fba16-3e3f-4c9d-88f6-b7a8ec20c8ee@h18g2000yqj.googlegroups.com> Hello Mike, Thank you for your hint. Obviously, it worked! Laughing at myself now: how post method was supposed to know what I mean by :viewtype if don't specify it :) Best, Evgeny On Jun 4, 10:14?pm, Mike Sassak wrote: > Hi Evgeny, > > You didn't include the error message in your email, so this is just a guess, > but from your example, it looks like you need to specify :viewtype in your > call to post, like so: > > post :create, :viewtype => 'context' > > The HTTP verb methods require you to specify the route parameters in order > to work. > > Mike > > On Jun 2, 2009 3:53 AM, "Evgeny Bogdanov" wrote: > > Hello, > > I am trying to spec an action in a controller, and rspec doesn't find > a route. > It seems that problem is in ":viewtype". If I change a line > "/:viewtype/asset/add" > into "/context/asset/add" in routes it works. > > I tried also > post "/context/asset/add", no luck. > > Could you please let me know how I can call the action through > that route with post method? > > Thank you in advance, > Evgeny > ===================== > ?map.with_options(:controller => "assets", :conditions =>{:method > => :post}) do |m| > ? ?m.create_asset ? ? ? ? ? ? ? ? ? '/:viewtype/asset/ > add', ? ? ? ? ? ? ? ? ? ? ? ?:action => 'create' > ?end > > describe AssetsController, "when working with formats" do > ?it "should call a find_asset_format for some actions" do > ? ?post :create > ?end > end > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Fri Jun 5 09:11:11 2009 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 5 Jun 2009 14:11:11 +0100 Subject: [rspec-users] response.should be_success -- what does this prove? In-Reply-To: <50873a360906050536m5eda4d88q6e7259f3f4ba5098@mail.gmail.com> References: <50873a360906050536m5eda4d88q6e7259f3f4ba5098@mail.gmail.com> Message-ID: <9E2ED486-1F59-4C9D-A13A-971D9C7D08C5@mattwynne.net> On 5 Jun 2009, at 13:36, doug livesey wrote: > Hi -- if my controller action already ensures that the correct > template is being rendered, what use is speccing that it should also > be successful? > I do it, but just because I saw someone else do it ages ago. > Is there a point? It checks that the response code indicates to the browser that the request was 200 OK (as opposed to, say a 302 redirect, or a 404 not found). It's useful when you're doing TDD as it's the simplest thing to expect a controller to do. If you break something it's also quite a nice first-failure to have. see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html Matt Wynne http://blog.mattwynne.net http://www.songkick.com From agilejoe at gmail.com Fri Jun 5 10:44:38 2009 From: agilejoe at gmail.com (Joe Ocampo) Date: Fri, 5 Jun 2009 09:44:38 -0500 Subject: [rspec-users] Example group parallel execution Message-ID: <93cf9750906050744s686a7c55g29e98fdebd2e109e@mail.gmail.com> So I am working on a project right now where we are combining Selenium and RSpec. It was working really well until we implemented the grid and started to do parallel execution on the specs to help speed things up. We are rolling are own framework as DeepTest did not really provide the facilities we were hoping. Our problem is that we have mutiple context per file. Currently the Thread runner executes the files in paralle per file. As you can imagine this isn't very efficient once the grid executes it, as it simply turns a prallel prococess back into a serial one once it parses the file. My question is where should I hook into RSpec to incercept the call of when the example group "context" is being executed as an atomic unit? Thanks for your help in advance. Joe Ocampo agilejoe.lostechies.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Jun 5 11:07:01 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Jun 2009 10:07:01 -0500 Subject: [rspec-users] Example group parallel execution In-Reply-To: <93cf9750906050744s686a7c55g29e98fdebd2e109e@mail.gmail.com> References: <93cf9750906050744s686a7c55g29e98fdebd2e109e@mail.gmail.com> Message-ID: <57c63afe0906050807g712fdecep65e7d3b7280c5cc7@mail.gmail.com> On Fri, Jun 5, 2009 at 9:44 AM, Joe Ocampo wrote: > So I am working on a project right now where we are combining Selenium and > RSpec.? It was working really well until we implemented the grid and started > to do parallel execution on the specs to help speed things up. We are > rolling are own framework as DeepTest did not really provide the facilities > we were hoping. > > Our problem is that we have mutiple context per file.? Currently the Thread > runner executes the files in paralle per file. As you can imagine this isn't > very efficient once the grid executes it, as it simply turns a prallel > prococess back into a serial one once it parses the file.? My question is > where should I hook into RSpec to incercept the call of when the example > group "context" is being executed as an atomic unit? This is something that rspec doesn't support with a formal API yet, and until we formalize it this is subject to change. That said, I think you're looking for the run() method in Spec::Runner::ExampleGroupRunner. Let me know if that gets you what you're looking for. > > Thanks for your help in advance. > > Joe Ocampo > agilejoe.lostechies.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From agilejoe at gmail.com Fri Jun 5 11:23:29 2009 From: agilejoe at gmail.com (Joe Ocampo) Date: Fri, 5 Jun 2009 10:23:29 -0500 Subject: [rspec-users] Example group parallel execution In-Reply-To: <57c63afe0906050807g712fdecep65e7d3b7280c5cc7@mail.gmail.com> References: <93cf9750906050744s686a7c55g29e98fdebd2e109e@mail.gmail.com> <57c63afe0906050807g712fdecep65e7d3b7280c5cc7@mail.gmail.com> Message-ID: <93cf9750906050823j7722d142s9168b3409c331e4e@mail.gmail.com> Thanks David! I will be sure to let you know our progress. Joe Ocampo agilejoe.lostechies.com On Fri, Jun 5, 2009 at 10:07 AM, David Chelimsky wrote: > On Fri, Jun 5, 2009 at 9:44 AM, Joe Ocampo wrote: > > So I am working on a project right now where we are combining Selenium > and > > RSpec. It was working really well until we implemented the grid and > started > > to do parallel execution on the specs to help speed things up. We are > > rolling are own framework as DeepTest did not really provide the > facilities > > we were hoping. > > > > Our problem is that we have mutiple context per file. Currently the > Thread > > runner executes the files in paralle per file. As you can imagine this > isn't > > very efficient once the grid executes it, as it simply turns a prallel > > prococess back into a serial one once it parses the file. My question is > > where should I hook into RSpec to incercept the call of when the example > > group "context" is being executed as an atomic unit? > > This is something that rspec doesn't support with a formal API yet, > and until we formalize it this is subject to change. That said, I > think you're looking for the run() method in > Spec::Runner::ExampleGroupRunner. > > Let me know if that gets you what you're looking for. > > > > > Thanks for your help in advance. > > > > Joe Ocampo > > agilejoe.lostechies.com > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Lee.Longmore at googlemail.com Fri Jun 5 11:40:07 2009 From: Lee.Longmore at googlemail.com (Lee) Date: Fri, 5 Jun 2009 08:40:07 -0700 (PDT) Subject: [rspec-users] Driving Out A View - Layouts and Sessions? Message-ID: I am driving out a view and I want to test that a link is displayed. The link_to code for the link is included in the layout for the view rather than the view template itself. Here's my example: it "should display a link to create a new zone" do render "contexts/index.html.erb", :layout => "layouts/ contexts.html.erb" response.should contain("sign out") end Firstly, my experiments suggest that the layout is only rendered if the :layout attribute is included in the call to render. Is my understanding correct? Secondly, the link_to code only executes if the session contains a piece of data (member id). How do I set up the session data in my view spec? Thanks. From Lee.Longmore at googlemail.com Fri Jun 5 11:54:00 2009 From: Lee.Longmore at googlemail.com (Lee) Date: Fri, 5 Jun 2009 08:54:00 -0700 (PDT) Subject: [rspec-users] Driving Out A View - Am I specifying too much? Message-ID: <6b81ab17-7935-431e-b846-fe1d2bf3b0f7@j12g2000vbl.googlegroups.com> I am driving out a view that renders a list of items with which a logged in member is associated. Against each item, one or more links may be rendered according to the member's role with respect to the item (item owner, item administrator, regular user etc). Each link represents a type of function that the member can perform on the item (edit, delete, invite etc), and the range of functions may differ across the items according to the member's role for each item. When specifying the view, should I include examples to specify which links should appear against an item for each potential role of a member? Or is this going too far? Here is an example list for a member: item 1 view edit delete (member is the owner of this item) item 2 view edit invite (member a regular user of this item) item 3 view (member has no role association with this item but can view it) Thanks. From sfeley at gmail.com Fri Jun 5 12:25:10 2009 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 5 Jun 2009 12:25:10 -0400 Subject: [rspec-users] Driving Out A View - Am I specifying too much? In-Reply-To: <6b81ab17-7935-431e-b846-fe1d2bf3b0f7@j12g2000vbl.googlegroups.com> References: <6b81ab17-7935-431e-b846-fe1d2bf3b0f7@j12g2000vbl.googlegroups.com> Message-ID: <1fb4df0906050925v714ad6eev9e42de2ee96eff59@mail.gmail.com> On Fri, Jun 5, 2009 at 11:54 AM, Lee wrote: > > When specifying the view, should I include examples to specify which > links should appear against an item for each potential role of a > member? Or is this going too far? It depends. If you're doing full BDD on your view, using RSpec as a design tool to plan the view before (or while) you create it, that sounds totally appropriate. Role-based hyperlinks sound like important business features, not cosmetics or cruft, so they should be declared and tested *somewhere* for sure. If you do it this way, you should make sure you're only testing the view's code, i.e. the existence of the link, and not the logic that decides who can do what. (Which isn't the proper job for a view.) That said, view specs at a unit level tend to be a bit of a drag, and many people skip them in favor of testing views at an integration level. You could put the same tests into Cucumber, or even a Selenium or Watir browser suite, and drive it without having to set up all those mock models in the view spec. It isn't a *bad* idea to spec the views too, though. You don't lose anything but time, and you may gain that back if the operation is a sensitive one. When I make decisions about whether to test controllers or views in RSpec, I usually think about whether the code is doing anything particularly complex or unusual, or if something in it is exceptionally likely to break. (And then, if either of those is true, I think about whether I could simplify those vulnerabilities out by reexamining my assumptions.) >8-> -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From sfeley at gmail.com Fri Jun 5 12:39:56 2009 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 5 Jun 2009 12:39:56 -0400 Subject: [rspec-users] Driving Out A View - Layouts and Sessions? In-Reply-To: References: Message-ID: <1fb4df0906050939i71326272k35bd6b54a7850641@mail.gmail.com> On Fri, Jun 5, 2009 at 11:40 AM, Lee wrote: > > Firstly, my experiments suggest that the layout is only rendered if > the :layout attribute is included in the call to render. Is my > understanding correct? Yes, and it's the way things should be. I suggest writing a separate spec for the layout, and testing its behavior separate from the view. After all, you're *unit* testing here. And the layout is a separate unit. > Secondly, the link_to code only executes if the session contains a > piece of data (member id). How do I set up the session data in my view > spec? With the session[] object, e.g. "session[:foo] = bar". See: http://rspec.info/rails/writing/views.html Whether the view (or layout) should be looking directly into the session and making decisions from what it sees, instead of trusting what it gets from the controller, is another question. "Is there a current user?" is _probably_ closer to your actual business rules than "Does the session contain a member id?" -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From zach.dennis at gmail.com Fri Jun 5 13:04:50 2009 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 5 Jun 2009 13:04:50 -0400 Subject: [rspec-users] Driving Out A View - Am I specifying too much? In-Reply-To: <6b81ab17-7935-431e-b846-fe1d2bf3b0f7@j12g2000vbl.googlegroups.com> References: <6b81ab17-7935-431e-b846-fe1d2bf3b0f7@j12g2000vbl.googlegroups.com> Message-ID: <85d99afe0906051004v749f3fe8w62cfd36c5041f0d6@mail.gmail.com> On Fri, Jun 5, 2009 at 11:54 AM, Lee wrote: > I am driving out a view that renders a list of items with which a > logged in member is associated. > > Against each item, one or more links may be rendered according to the > member's role with respect to the item (item owner, item > administrator, regular user etc). Each link represents a type of > function that the member can perform on the item (edit, delete, invite > etc), and the range of functions may differ across the items according > to the member's role for each item. > > When specifying the view, should I include examples to specify which > links should appear against an item for each potential role of a > member? Or is this going too far? I don't think it's going to far. If certain links should not show up in some cases, but should in others, I would provide an example for those. If it's important enough to hide, it's important enough to make sure it's hidden for the right reasons. > > Here is an example list for a member: > > item 1 ?view edit delete (member is the owner of this item) > item 2 ?view edit invite (member a regular user of this item) > item 3 ?view (member has no role association with this item but can > view it) I would probably drive these with a view spec that looked like this.... describe "your/view" do it "should always have a link to view the item" context "when the member owns the item" do it "should have a link to edit the item" it "should have a link to delete the item" end context "when the member owns the item" do it "should have a link to edit the item" it "should have a link to invite ..." end end > > Thanks. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) From lists at ruby-forum.com Fri Jun 5 16:28:40 2009 From: lists at ruby-forum.com (Fernando Perez) Date: Fri, 5 Jun 2009 22:28:40 +0200 Subject: [rspec-users] response.should be_success -- what does this prove? In-Reply-To: <9E2ED486-1F59-4C9D-A13A-971D9C7D08C5@mattwynne.net> References: <50873a360906050536m5eda4d88q6e7259f3f4ba5098@mail.gmail.com> <9E2ED486-1F59-4C9D-A13A-971D9C7D08C5@mattwynne.net> Message-ID: <358301607ac99a7d13a5e12f58c995a1@ruby-forum.com> > It's useful when you're doing TDD as it's the simplest thing to expect > a controller to do. If you break something it's also quite a nice > first-failure to have. Hmm, I'm not sure about that. If the view fails to render, then Rails returns the error page, i.e: response.should be_success is total crap. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jun 5 16:29:30 2009 From: lists at ruby-forum.com (Fernando Perez) Date: Fri, 5 Jun 2009 22:29:30 +0200 Subject: [rspec-users] Mocking find_by_sql Message-ID: Hi, I cannot manage to mock a call to find_by_sql. Which class is actually getting called? It is not the model, and I tried ActiveRecord which didn't work either. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jun 5 16:33:56 2009 From: lists at ruby-forum.com (Fernando Perez) Date: Fri, 5 Jun 2009 22:33:56 +0200 Subject: [rspec-users] Mocking find_by_sql In-Reply-To: References: Message-ID: <620e1158085ef951d2036e4e60f475a8@ruby-forum.com> Damn I can't mock will_paginate's paginate method either!!! -- Posted via http://www.ruby-forum.com/. From mauricio.linhares at gmail.com Fri Jun 5 16:53:09 2009 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Fri, 5 Jun 2009 17:53:09 -0300 Subject: [rspec-users] Given/When/Then blocks on Cucumber Message-ID: Hello guys, I've been looking at Pyccuracy and found the "Given/Then/When" blocks to be very interesting and easier to understand and write, specially when writting scenarios with more than one of those. An example can be found here: http://www.pyccuracy.org/getting_started_3.html Here's how they do: Scenario 1 - Searching for Hello World Given I go to "http://www.google.com" When I fill "q" textbox with "Hello World" And I click "btnG" button Then I see "Hello World - Google Search" title And here's how we would do with Cucumber Scenario: Searching for Hello World Given I go to "http://www.google.com" When I fill "q" textbox with "Hello World" When I click "btnG" button Then I see "Hello World - Google Search" title With cucumber we need to repeat the When's, Then's and Given's if there's more than one, woudn't it be nice to avoid this? - Maur?cio Linhares http://alinhavado.wordpress.com/ (pt-br) | http://codeshooter.wordpress.com/ (en) From ben at benmabey.com Fri Jun 5 17:00:50 2009 From: ben at benmabey.com (Ben Mabey) Date: Fri, 05 Jun 2009 15:00:50 -0600 Subject: [rspec-users] Given/When/Then blocks on Cucumber In-Reply-To: References: Message-ID: <4A298782.90503@benmabey.com> Maur?cio Linhares wrote: > Hello guys, > > I've been looking at Pyccuracy and found the "Given/Then/When" blocks > to be very interesting and easier to understand and write, specially > when writting scenarios with more than one of those. An example can be > found here: http://www.pyccuracy.org/getting_started_3.html > > Here's how they do: > > Scenario 1 - Searching for Hello World > Given > I go to "http://www.google.com" > When > I fill "q" textbox with "Hello World" > And I click "btnG" button > Then > I see "Hello World - Google Search" title > > And here's how we would do with Cucumber > > Scenario: Searching for Hello World > Given I go to "http://www.google.com" > When I fill "q" textbox with "Hello World" > When I click "btnG" button > Then I see "Hello World - Google Search" title > > With cucumber we need to repeat the When's, Then's and Given's if > there's more than one, woudn't it be nice to avoid this? > Yep, and you can... (since Cucumber started you've been able to do this) You can use "And" and "But": Scenario: Searching for Hello World Given I go to "http://www.google.com" When I fill "q" textbox with "Hello World" And I click "btnG" button Then I see "Hello World - Google Search" title But I should not see "Whatever" -Ben From ben at benmabey.com Fri Jun 5 17:02:03 2009 From: ben at benmabey.com (Ben Mabey) Date: Fri, 05 Jun 2009 15:02:03 -0600 Subject: [rspec-users] Given/When/Then blocks on Cucumber In-Reply-To: References: Message-ID: <4A2987CB.3060007@benmabey.com> Maur?cio Linhares wrote: > Hello guys, > > I've been looking at Pyccuracy and found the "Given/Then/When" blocks > to be very interesting and easier to understand and write, specially > when writting scenarios with more than one of those. An example can be > found here: http://www.pyccuracy.org/getting_started_3.html > > Here's how they do: > > Scenario 1 - Searching for Hello World > Given > I go to "http://www.google.com" > When > I fill "q" textbox with "Hello World" > And I click "btnG" button > Then > I see "Hello World - Google Search" title > > And here's how we would do with Cucumber > > Scenario: Searching for Hello World > Given I go to "http://www.google.com" > When I fill "q" textbox with "Hello World" > When I click "btnG" button > Then I see "Hello World - Google Search" title > > With cucumber we need to repeat the When's, Then's and Given's if > there's more than one, woudn't it be nice to avoid this? > > - > Maur?cio Linhares > http://alinhavado.wordpress.com/ (pt-br) | > http://codeshooter.wordpress.com/ (en) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > BTW, please use the new Cucumber ML for cucumber related posts: http://groups.google.com/group/cukes -Ben From joe at josephwilk.net Fri Jun 5 17:03:33 2009 From: joe at josephwilk.net (Joseph Wilk) Date: Fri, 05 Jun 2009 22:03:33 +0100 Subject: [rspec-users] Given/When/Then blocks on Cucumber In-Reply-To: References: Message-ID: <4A298825.4060406@josephwilk.net> Maur?cio Linhares wrote: > Hello guys, > > I've been looking at Pyccuracy and found the "Given/Then/When" blocks > to be very interesting and easier to understand and write, specially > when writting scenarios with more than one of those. An example can be > found here: http://www.pyccuracy.org/getting_started_3.html > > Here's how they do: > > Scenario 1 - Searching for Hello World > Given > I go to "http://www.google.com" > When > I fill "q" textbox with "Hello World" > And I click "btnG" button > Then > I see "Hello World - Google Search" title > > And here's how we would do with Cucumber > > Scenario: Searching for Hello World > Given I go to "http://www.google.com" > When I fill "q" textbox with "Hello World" > When I click "btnG" button > Then I see "Hello World - Google Search" title > > With cucumber we need to repeat the When's, Then's and Given's if > there's more than one, woudn't it be nice to avoid this? > We don't have to repeat ourselves in Cucumber: Scenario: Searching for Hello World Given I go to "http://www.google.com" When I fill "q" textbox with "Hello World" And I click "btnG" button Then I see "Hello World - Google Search" title While the block idea is interesting the key thing for me is the scenario reads like prose. Also we have moved Cuke to its own mailing list, so please send any Cucumber related questions there. http://groups.google.com/group/cukes?pli=1 Thanks! -- Joseph Wilk http://blog.josephwilk.net > - > Maur?cio Linhares > http://alinhavado.wordpress.com/ (pt-br) | > http://codeshooter.wordpress.com/ (en) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > From dchelimsky at gmail.com Fri Jun 5 17:04:07 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Jun 2009 16:04:07 -0500 Subject: [rspec-users] Mocking find_by_sql In-Reply-To: References: Message-ID: <57c63afe0906051404t2b25e96ar9cee6ec488340274@mail.gmail.com> On Fri, Jun 5, 2009 at 3:29 PM, Fernando Perez wrote: > Hi, I cannot manage to mock a call to find_by_sql. Which class is > actually getting called? It is not the model, and I tried ActiveRecord > which didn't work either. It's the model's class: class Foo < AR::Base; end describe Foo do it "...." do Foo.should_receive(:find_by_sql) .... HTH, David > -- > 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 Fri Jun 5 17:05:30 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Jun 2009 16:05:30 -0500 Subject: [rspec-users] Mocking find_by_sql In-Reply-To: <620e1158085ef951d2036e4e60f475a8@ruby-forum.com> References: <620e1158085ef951d2036e4e60f475a8@ruby-forum.com> Message-ID: <57c63afe0906051405j3a577030wed86d9d37a085a32@mail.gmail.com> On Fri, Jun 5, 2009 at 3:33 PM, Fernando Perez wrote: > Damn I can't mock will_paginate's paginate method either!!! Same deal as your other post about find_by_sql. Set the message expectation on the method on the class: Post.should_receive(:paginate) > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Fri Jun 5 17:36:32 2009 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 5 Jun 2009 17:36:32 -0400 Subject: [rspec-users] Driving Out A View - Am I specifying too much? In-Reply-To: <298c4d2a0906051353y51f694acs6292872413a8c6d6@mail.gmail.com> References: <6b81ab17-7935-431e-b846-fe1d2bf3b0f7@j12g2000vbl.googlegroups.com> <85d99afe0906051004v749f3fe8w62cfd36c5041f0d6@mail.gmail.com> <298c4d2a0906051353y51f694acs6292872413a8c6d6@mail.gmail.com> Message-ID: <1fb4df0906051436r452cc87m9b027caa1b2d07e4@mail.gmail.com> On Fri, Jun 5, 2009 at 4:53 PM, Charlie Bowman wrote: > I never spec my views.? I also never put conditional logic in the views.? If > you have links that should show up sometimes and not others why not just > move that logic into a helper or other associated class and test the method? Good point. But if one is really being completionist, it still makes sense to check that the view is calling that helper. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Fri Jun 5 18:27:13 2009 From: lists at ruby-forum.com (Wolfram Arnold) Date: Sat, 6 Jun 2009 00:27:13 +0200 Subject: [rspec-users] Cucumber vs Rails Fixtures In-Reply-To: References: <4A1445E1.3070204@benmabey.com> Message-ID: <14a9331d4a903b05e58342d0f4da53b9@ruby-forum.com> The method I posted last week only works for Cucumber prior to 0.2.3.2. For 0.2.3.2 and later, you cannot pass a block to the World more than once, and thus the new way would be (in env.rb): module FixtureAccess def self.included(base) (class << base; self; end).class_eval do @@fixture_cache = {} fixtures.each do |table_name| table_name = table_name.to_s.tr('.', '_') define_method(table_name) do |*fixture_symbols| @@fixture_cache[table_name] ||= {} instances = fixture_symbols.map do |fixture_symbol| if fix = Fixtures.cached_fixtures(ActiveRecord::Base.connection, table_name)[fixture_symbol.to_s] @@fixture_cache[table_name][fixture_symbol] ||= fix.find # find model.find's the instance else raise StandardError, "No fixture with name '#{fixture_symbol}' found for table '#{table_name}'" end end instances.size == 1 ? instances.first : instances end end end end end ... then ... World(FixtureAccess) -- Posted via http://www.ruby-forum.com/. From lenny at aps.org Fri Jun 5 18:10:27 2009 From: lenny at aps.org (Lenny Marks) Date: Fri, 5 Jun 2009 18:10:27 -0400 Subject: [rspec-users] Problems upgrading to Rails-2.3.2/Rspec 1.2.6 Message-ID: <99D2A806-00DF-429A-A0BF-B4A6EF18F583@aps.org> jruby-1.3.0 rspec/rspec-rails 1.2.6 I just ran into the 'Missing template' thing from the ticket below as well. Is it really that uncommon for a controller action to redirect or explicitly render a different template? Is it still considered 'invalid'? Seems silly to have to create a bunch of blank templates. https://rspec.lighthouseapp.com/projects/5645/tickets/765-controller-spec-with-xhr-gives-template-missing-error I was also running into a conflict between the version of the rack gem bundled with Rails 2.3.2 and the rack gem dependency from rspec-rails. When running my app I was getting the error below from POST requests that were expecting JSON back. undefined method `split' for # /Users/Shared/eds_test/share/RubyGems/1.8/gems/actionpack-2.3.2/ lib/action_controller/mime_type.rb:206:in `method_missing' /Users/Shared/eds_test/share/RubyGems/1.8/gems/rack-1.0.0/lib/ rack/request.rb:51:in `media_type' I'm not sure why it was picking up the rack-1.0.0 gem. I thought I checked out all the upgrade notes and I did re-run the rspec generator. My solution was to remove the rack-1.0.0 gem and comment out the runtime dependency in the rspec-rails gemspec. if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, ["= 1.2.6"]) #s.add_runtime_dependency(%q, [">= 0.4.0"]) Anyone have any better suggestions? Maybe I have something peculiar that others aren't hitting these issues? Thanks, -lenny From lists at ruby-forum.com Fri Jun 5 21:21:02 2009 From: lists at ruby-forum.com (Wolfram Arnold) Date: Sat, 6 Jun 2009 03:21:02 +0200 Subject: [rspec-users] Cucumber vs Rails Fixtures In-Reply-To: <14a9331d4a903b05e58342d0f4da53b9@ruby-forum.com> References: <4A1445E1.3070204@benmabey.com> <14a9331d4a903b05e58342d0f4da53b9@ruby-forum.com> Message-ID: This still wasn't fully working; I posted too soon. See here for the final and working version: http://wiki.github.com/aslakhellesoy/cucumber/fixtures -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Jun 5 23:30:52 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Jun 2009 22:30:52 -0500 Subject: [rspec-users] Problems upgrading to Rails-2.3.2/Rspec 1.2.6 In-Reply-To: <99D2A806-00DF-429A-A0BF-B4A6EF18F583@aps.org> References: <99D2A806-00DF-429A-A0BF-B4A6EF18F583@aps.org> Message-ID: <57c63afe0906052030m755b0d3fv6725296f61293a09@mail.gmail.com> On Fri, Jun 5, 2009 at 5:10 PM, Lenny Marks wrote: > jruby-1.3.0 > rspec/rspec-rails 1.2.6 > > I just ran into the 'Missing template' thing from the ticket below as well. > Is it really that uncommon for a controller action to redirect or explicitly > render a different template? Is it still considered 'invalid'? Seems silly > to have to create a bunch of blank templates. > > https://rspec.lighthouseapp.com/projects/5645/tickets/765-controller-spec-with-xhr-gives-template-missing-error I reopened the ticket. > > I was also running into a conflict between the version of the rack gem > bundled with Rails 2.3.2 and the rack gem dependency from rspec-rails. When > running my app I was getting the error below from POST requests that were > expecting JSON back. > > undefined method `split' for # > > ?/Users/Shared/eds_test/share/RubyGems/1.8/gems/actionpack-2.3.2/lib/action_controller/mime_type.rb:206:in > `method_missing' > > ?/Users/Shared/eds_test/share/RubyGems/1.8/gems/rack-1.0.0/lib/rack/request.rb:51:in > `media_type' > > I'm not sure why it was picking up the rack-1.0.0 gem. I thought I checked > out all the upgrade notes and I did re-run the rspec generator. > > My solution was to remove the rack-1.0.0 gem and comment out the runtime > dependency in the rspec-rails gemspec. > > if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then > ? ? ?s.add_runtime_dependency(%q, ["= 1.2.6"]) > ? ? ?#s.add_runtime_dependency(%q, [">= 0.4.0"]) > > Anyone have any better suggestions? Maybe I have something peculiar that > others aren't hitting these issues? > > Thanks, > -lenny > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 5 23:38:56 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Jun 2009 22:38:56 -0500 Subject: [rspec-users] Testing my rails authentication controller In-Reply-To: <004f01c9e619$a7466870$f5d33950$@com> References: <004f01c9e619$a7466870$f5d33950$@com> Message-ID: <57c63afe0906052038t588fb3b6h362a86bfd11e628c@mail.gmail.com> On Fri, Jun 5, 2009 at 3:10 PM, Wayne Andersen wrote: > I have a simple controller: > > class AccessController < ApplicationController > ? def login > ??? if request.post? > ????? employee = Employee.authenticate(params[:name], params[:password]) > ????? if employee > ??????? session[:employee_id] = employee.id > ??????? redirect_to(:controller => "timesheets", :action => "index") > ????? else > ??????? flash.now[:notice] = "Invalid username/password combination" > ????? end > ??? end > ? end > end > > I have tried a number of ways to create a spec to test the login function, > but am not having any luck. > > My current code looks something like this, but I don?t really understand > what is going on here. > > ?? controller.should_receive(:login).with(no_args()) This line overrides the login action with a message expectation, so the login action in the controller is never executed. What you want is to stub the decision points and then set expectations about what happens. For example: it "assigns the employee id to the session if the employee is found" do Employee.stub(:authenticate).and_return(mock_model(Employee, :id => 37)) post :login, params session[:employee_id].should == 37 end Let me know if that is not self-explanatory and I'll explain. Cheers, David > ?? post :login, params > ?? session[:employee_id].should_not be_nil > > I am setting a simple expectation in the first line and then doing a post > with params. I then check to see if the variable is in the session. > > What is the best way to make something like this work.. > > Wayne L. Andersen Hi Wayne, In the firs tlin From dchelimsky at gmail.com Fri Jun 5 23:40:59 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Jun 2009 22:40:59 -0500 Subject: [rspec-users] Missing template in helper specs with a render In-Reply-To: <298c4d2a0906041841t47189443u26a5b12a6b3833b8@mail.gmail.com> References: <298c4d2a0906041841t47189443u26a5b12a6b3833b8@mail.gmail.com> Message-ID: <57c63afe0906052040j62de7b68va9db5fc28df35665@mail.gmail.com> On Thu, Jun 4, 2009 at 8:41 PM, Charlie Bowman wrote: > I have a helper method that does a "render :partial".? The method works fine > within the app (Rails 2.3.2).? In rspec (1.2.6) I get an error ("Missing > template /comments/_comment.erb in view path" > It seems that rspec when running helper tests doesn't set the view_path so > rails doens't know where to look for the templates.? Is there a way to run > helper specs with the same setup as controller specs? There is no support for rendering in helper specs as of yet. Please file a feature request if you think there should be. I have, personally, never rendered from a helper. Anybody else? > > Charlie > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From Lee.Longmore at googlemail.com Sat Jun 6 01:01:44 2009 From: Lee.Longmore at googlemail.com (Lee) Date: Fri, 5 Jun 2009 22:01:44 -0700 (PDT) Subject: [rspec-users] Driving Out A View - Layouts and Sessions? In-Reply-To: <1fb4df0906050939i71326272k35bd6b54a7850641@mail.gmail.com> References: <1fb4df0906050939i71326272k35bd6b54a7850641@mail.gmail.com> Message-ID: <8faab528-324e-4b1a-9c83-0fe93a3fb772@l32g2000vba.googlegroups.com> Thanks Steve. As suggested I started to wrtite a separate spec for the layout: require File.expand_path(File.dirname(__FILE__) + '/../../ spec_helper') describe "layouts/contexts.html.erb" do it "should display a link to create a new zone" do render "layouts/contexts.html.erb" end end When I execute this, it complains of a missing method "sub_menu". This method, along with others such as "main_menu", are called within the layout. Unlike "main_menu" which is defined in my "application_helper.rb" file, "sub_menu" is defined in the helper file for the controller "contexts". How do I get the spec to "see" this file and its contents when executed? I think It's seeing "main_menu". Thanks. On 5 June, 17:39, Stephen Eley wrote: > On Fri, Jun 5, 2009 at 11:40 AM, Lee wrote: > > > Firstly, my experiments suggest that the layout is only rendered if > > the :layout attribute is included in the call to render. Is my > > understanding correct? > > Yes, and it's the way things should be. ?I suggest writing a separate > spec for the layout, and testing its behavior separate from the view. > After all, you're *unit* testing here. ?And the layout is a separate > unit. > > > Secondly, the link_to code only executes if the session contains a > > piece of data (member id). How do I set up the session data in my view > > spec? > > With the session[] object, e.g. "session[:foo] = bar". ?See:http://rspec.info/rails/writing/views.html > > Whether the view (or layout) should be looking directly into the > session and making decisions from what it sees, instead of trusting > what it gets from the controller, is another question. ?"Is there a > current user?" is _probably_ closer to your actual business rules than > "Does the session contain a member id?" > > -- > Have Fun, > ? ?Steve Eley (sfe... at gmail.com) > ? ?ESCAPE POD - The Science Fiction Podcast Magazine > ? ?http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From Lee.Longmore at googlemail.com Sat Jun 6 01:23:02 2009 From: Lee.Longmore at googlemail.com (Lee) Date: Fri, 5 Jun 2009 22:23:02 -0700 (PDT) Subject: [rspec-users] Driving Out A View - Am I specifying too much? In-Reply-To: <1fb4df0906051436r452cc87m9b027caa1b2d07e4@mail.gmail.com> References: <6b81ab17-7935-431e-b846-fe1d2bf3b0f7@j12g2000vbl.googlegroups.com> <85d99afe0906051004v749f3fe8w62cfd36c5041f0d6@mail.gmail.com> <298c4d2a0906051353y51f694acs6292872413a8c6d6@mail.gmail.com> <1fb4df0906051436r452cc87m9b027caa1b2d07e4@mail.gmail.com> Message-ID: <8041babd-c009-4563-86e5-c40b2d791041@s21g2000vbb.googlegroups.com> Thank you everyone for your helpful insights. I had already gone down the route suggested by Zach but it was nevertheless very re-assuring to have my approach validated as I am a newbie to RSpec. I did however consolidate my expectations e.g.: context "when the member is a privileged member of a zone" do it "should display links for functions (Create sub-zone, Invite member, Invite non-member)" do .... "a" tag expectations for each expected link as well as the use of :count to check the number of links e.g. function_links.should have_selector("li", :count => 4) To Charlie's point, I do call a helper from my view to avoid cluttering the view e.g. def function_links_for(functions, member, context) contents = content_tag(:li, link_to("Enter zone", member_context_path(member, context))) functions.each do | function | case function.name when "ManageZone" contents << content_tag(:li, link_to("Manage zone", edit_member_context_path(member, context))) when "RemoveZone" .... 'functions' is an array of Function objects valid for member and his/ her role for a given context (item). But I opted not to test this explicitly but, I confess, on the basis that Chapter 22 "Rails Helpers" in The RSpec Book is not yet written! Thanks. On 5 June, 22:36, Stephen Eley wrote: > On Fri, Jun 5, 2009 at 4:53 PM, Charlie Bowman wrote: > > I never spec my views.? I also never put conditional logic in the views.? If > > you have links that should show up sometimes and not others why not just > > move that logic into a helper or other associated class and test the method? > > Good point. ?But if one is really being completionist, it still makes > sense to check that the view is calling that helper. > > -- > Have Fun, > ? ?Steve Eley (sfe... at gmail.com) > ? ?ESCAPE POD - The Science Fiction Podcast Magazine > ? ?http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Sat Jun 6 05:16:49 2009 From: lists at ruby-forum.com (Fernando Perez) Date: Sat, 6 Jun 2009 11:16:49 +0200 Subject: [rspec-users] Mocking find_by_sql In-Reply-To: <57c63afe0906051405j3a577030wed86d9d37a085a32@mail.gmail.com> References: <620e1158085ef951d2036e4e60f475a8@ruby-forum.com> <57c63afe0906051405j3a577030wed86d9d37a085a32@mail.gmail.com> Message-ID: <5b5e57e72e2ad1f991722e2d86558814@ruby-forum.com> > Same deal as your other post about find_by_sql. Set the message > expectation on the method on the class: > > Post.should_receive(:paginate) Unfortunately it doesn't work :-( I'll have to dive into the will_paginate source code to find out how it plugs itself in AR. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Jun 6 07:06:01 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 6 Jun 2009 06:06:01 -0500 Subject: [rspec-users] Driving Out A View - Layouts and Sessions? In-Reply-To: <8faab528-324e-4b1a-9c83-0fe93a3fb772@l32g2000vba.googlegroups.com> References: <1fb4df0906050939i71326272k35bd6b54a7850641@mail.gmail.com> <8faab528-324e-4b1a-9c83-0fe93a3fb772@l32g2000vba.googlegroups.com> Message-ID: <57c63afe0906060406nfc765d6p215f0a5fd1fb927@mail.gmail.com> On Sat, Jun 6, 2009 at 12:01 AM, Lee wrote: > Thanks Steve. > > As suggested I started to wrtite a separate spec for the layout: > > require File.expand_path(File.dirname(__FILE__) + '/../../ > spec_helper') > > describe "layouts/contexts.html.erb" do > > ?it "should display a link to create a new zone" do > ? ?render "layouts/contexts.html.erb" > ?end > > end > > When I execute this, it complains of a missing method "sub_menu". This > method, along with others such as "main_menu", are called within the > layout. Unlike "main_menu" which is defined in my > "application_helper.rb" file, "sub_menu" is defined in the helper file > for the controller "contexts". How do I get the spec to "see" this > file and its contents when executed? I think It's seeing "main_menu". http://rspec.rubyforge.org/rspec-rails/1.2.6/classes/Spec/Rails/Example/ViewExampleGroup.html#M000049 > > Thanks. > > On 5 June, 17:39, Stephen Eley wrote: >> On Fri, Jun 5, 2009 at 11:40 AM, Lee wrote: >> >> > Firstly, my experiments suggest that the layout is only rendered if >> > the :layout attribute is included in the call to render. Is my >> > understanding correct? >> >> Yes, and it's the way things should be. ?I suggest writing a separate >> spec for the layout, and testing its behavior separate from the view. >> After all, you're *unit* testing here. ?And the layout is a separate >> unit. >> >> > Secondly, the link_to code only executes if the session contains a >> > piece of data (member id). How do I set up the session data in my view >> > spec? >> >> With the session[] object, e.g. "session[:foo] = bar". ?See:http://rspec.info/rails/writing/views.html >> >> Whether the view (or layout) should be looking directly into the >> session and making decisions from what it sees, instead of trusting >> what it gets from the controller, is another question. ?"Is there a >> current user?" is _probably_ closer to your actual business rules than >> "Does the session contain a member id?" >> >> -- >> Have Fun, >> ? ?Steve Eley (sfe... at gmail.com) >> ? ?ESCAPE POD - The Science Fiction Podcast Magazine >> ? ?http://www.escapepod.org >> _______________________________________________ >> 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 matt at mattwynne.net Sat Jun 6 07:16:59 2009 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 6 Jun 2009 12:16:59 +0100 Subject: [rspec-users] Missing template in helper specs with a render In-Reply-To: <57c63afe0906052040j62de7b68va9db5fc28df35665@mail.gmail.com> References: <298c4d2a0906041841t47189443u26a5b12a6b3833b8@mail.gmail.com> <57c63afe0906052040j62de7b68va9db5fc28df35665@mail.gmail.com> Message-ID: <3D53E049-CB10-467B-8667-1E4E894C2403@mattwynne.net> On 6 Jun 2009, at 04:40, David Chelimsky wrote: > On Thu, Jun 4, 2009 at 8:41 PM, Charlie Bowman > wrote: >> I have a helper method that does a "render :partial". The method >> works fine >> within the app (Rails 2.3.2). In rspec (1.2.6) I get an error >> ("Missing >> template /comments/_comment.erb in view path" >> It seems that rspec when running helper tests doesn't set the >> view_path so >> rails doens't know where to look for the templates. Is there a way >> to run >> helper specs with the same setup as controller specs? > > There is no support for rendering in helper specs as of yet. Please > file a feature request if you think there should be. I have, > personally, never rendered from a helper. Anybody else? Yep, I quite often have helper methods that wrap a call to render_partial, but they'd just get tested as part of the main view render, or by the cukes. Matt Wynne http://blog.mattwynne.net http://www.songkick.com From dchelimsky at gmail.com Sat Jun 6 07:40:21 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 6 Jun 2009 06:40:21 -0500 Subject: [rspec-users] Example group parallel execution In-Reply-To: <93cf9750906050823j7722d142s9168b3409c331e4e@mail.gmail.com> References: <93cf9750906050744s686a7c55g29e98fdebd2e109e@mail.gmail.com> <57c63afe0906050807g712fdecep65e7d3b7280c5cc7@mail.gmail.com> <93cf9750906050823j7722d142s9168b3409c331e4e@mail.gmail.com> Message-ID: <57c63afe0906060440t7aa7e8fcn21308e0ea1b48870@mail.gmail.com> Hey Joe - you can actually write your own runner and plug it in from the command line with --runner. I forgot about this (it's been a long time since anybody has brought it up). On Fri, Jun 5, 2009 at 10:23 AM, Joe Ocampo wrote: > Thanks David! > > I will be sure to let you know our progress. > > Joe Ocampo > agilejoe.lostechies.com > > > On Fri, Jun 5, 2009 at 10:07 AM, David Chelimsky > wrote: >> >> On Fri, Jun 5, 2009 at 9:44 AM, Joe Ocampo wrote: >> > So I am working on a project right now where we are combining Selenium >> > and >> > RSpec.? It was working really well until we implemented the grid and >> > started >> > to do parallel execution on the specs to help speed things up. We are >> > rolling are own framework as DeepTest did not really provide the >> > facilities >> > we were hoping. >> > >> > Our problem is that we have mutiple context per file.? Currently the >> > Thread >> > runner executes the files in paralle per file. As you can imagine this >> > isn't >> > very efficient once the grid executes it, as it simply turns a prallel >> > prococess back into a serial one once it parses the file.? My question >> > is >> > where should I hook into RSpec to incercept the call of when the example >> > group "context" is being executed as an atomic unit? >> >> This is something that rspec doesn't support with a formal API yet, >> and until we formalize it this is subject to change. That said, I >> think you're looking for the run() method in >> Spec::Runner::ExampleGroupRunner. >> >> Let me know if that gets you what you're looking for. >> >> > >> > Thanks for your help in advance. >> > >> > Joe Ocampo >> > agilejoe.lostechies.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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jona.hunt777 at gmail.com Sat Jun 6 11:31:08 2009 From: jona.hunt777 at gmail.com (Hunt Jon) Date: Sun, 7 Jun 2009 00:31:08 +0900 Subject: [rspec-users] Mocking find_by_sql In-Reply-To: <5b5e57e72e2ad1f991722e2d86558814@ruby-forum.com> References: <620e1158085ef951d2036e4e60f475a8@ruby-forum.com> <57c63afe0906051405j3a577030wed86d9d37a085a32@mail.gmail.com> <5b5e57e72e2ad1f991722e2d86558814@ruby-forum.com> Message-ID: <5e1f1f1f0906060831w47b13117oa4b4a14f67611d3d@mail.gmail.com> You might not be understanding the usage of mock very well. From charlesmbowman at gmail.com Sat Jun 6 18:34:17 2009 From: charlesmbowman at gmail.com (Charlie Bowman) Date: Sat, 6 Jun 2009 15:34:17 -0700 Subject: [rspec-users] Missing template in helper specs with a render In-Reply-To: <1244271633.18900.5.camel@ip6-localhost> References: <298c4d2a0906041841t47189443u26a5b12a6b3833b8@mail.gmail.com> <57c63afe0906052040j62de7b68va9db5fc28df35665@mail.gmail.com> <1244271633.18900.5.camel@ip6-localhost> Message-ID: I consider an if statement in the view layer a bug. I often need to conditionally render a partial and a helper is a great way to construct that condition. Im currently stubing the call to render but I only like stub when absolutely necessary. Sent from my iPhone On Jun 6, 2009, at 12:00 AM, Hans de Graaff wrote: > On Fri, 2009-06-05 at 22:40 -0500, David Chelimsky wrote: > >> There is no support for rendering in helper specs as of yet. Please >> file a feature request if you think there should be. I have, >> personally, never rendered from a helper. Anybody else? > > We do this for example to render a set of unrelated items into a > single > timeline-based view. The helper sorts out the ordering and renders > each > object in it using a specific partial. > > Hans > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From sfeley at gmail.com Sat Jun 6 19:08:57 2009 From: sfeley at gmail.com (Stephen Eley) Date: Sat, 6 Jun 2009 19:08:57 -0400 Subject: [rspec-users] Driving Out A View - Layouts and Sessions? In-Reply-To: <8faab528-324e-4b1a-9c83-0fe93a3fb772@l32g2000vba.googlegroups.com> References: <1fb4df0906050939i71326272k35bd6b54a7850641@mail.gmail.com> <8faab528-324e-4b1a-9c83-0fe93a3fb772@l32g2000vba.googlegroups.com> Message-ID: <1fb4df0906061608i74721dd3h4414ed9216ee1f86@mail.gmail.com> On Sat, Jun 6, 2009 at 1:01 AM, Lee wrote: > > When I execute this, it complains of a missing method "sub_menu". This > method, along with others such as "main_menu", are called within the > layout. Unlike "main_menu" which is defined in my > "application_helper.rb" file, "sub_menu" is defined in the helper file > for the controller "contexts". How do I get the spec to "see" this > file and its contents when executed? I think It's seeing "main_menu". Just require it and then include it. A "describe" block is really just a prettified form of class definition, so you can include any modules you like in it. Although (warning: continued smartassery here) I'm also wondering why it's a good idea to call a method defined in a specific controller's helper from a global layout. Is this layout only used by that controller? If not, why isn't the method in application helpers? -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From zach.dennis at gmail.com Sun Jun 7 01:02:07 2009 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 7 Jun 2009 01:02:07 -0400 Subject: [rspec-users] Missing template in helper specs with a render In-Reply-To: References: <298c4d2a0906041841t47189443u26a5b12a6b3833b8@mail.gmail.com> <57c63afe0906052040j62de7b68va9db5fc28df35665@mail.gmail.com> <1244271633.18900.5.camel@ip6-localhost> Message-ID: <85d99afe0906062202w1c1b5863q132150b955b9d059@mail.gmail.com> On Sat, Jun 6, 2009 at 6:34 PM, Charlie Bowman wrote: > I consider an if statement in the view layer a bug. Perhaps we can consider it a possible code smell? It's not really a bug unless it's producing incorrect or unexpected result in the application's behaviour. > I often need to > conditionally render a partial and a helper is a great way to construct that > condition. Im currently stubing the call to render but I only like stub > when absolutely necessary. Helpers can be a great way to organize some of the view's implementation, although my goal isn't to move every conditional out of the view, it's to avoid having unnecessary logic in the view. When I work outside-in I'm able to push logic that doesn't belong in the view into a presenter or further down to a model with a good method name. The logic that is left in the view is very minimal and ultra-simple. I find it easy to spec and it doesn't impede the life or maintainability of the view. For example, if I need to display a piece of information for an admin, but not a normal user then I have no problem doing the "if current_user.admin?" check in a view: <% if current_user.admin? %> Foo bar baz <% end %> The check itself is already ultra-simple and it reads very well. What value would we get from moving this to a helper method? It's currently easy to open the view and know that "Foo bar baz" will only be rendered for an admin. Does moving this to "display_foo_bar_baz_for_admin" really give us anything? There's a cost to creating a helper method for every one-off condition. There's also a cost for turning every snippet of markup that shows up in a simple view condition into a partial. The cost is in the disconnect and separation that comes from doing separating these pieces that go together as well as the organization nightmare of a plethora of helper methods and partials. I like extracting helpers when it provides more value than burden. When it doesn't I will leave the small, ultra-simple logic in the view, Zach > > Sent from my iPhone > > On Jun 6, 2009, at 12:00 AM, Hans de Graaff wrote: > >> On Fri, 2009-06-05 at 22:40 -0500, David Chelimsky wrote: >> >>> There is no support for rendering in helper specs as of yet. Please >>> file a feature request if you think there should be. I have, >>> personally, never rendered from a helper. Anybody else? >> >> We do this for example to render a set of unrelated items into a single >> timeline-based view. The helper sorts out the ordering and renders each >> object in it using a specific partial. >> >> Hans >> _______________________________________________ >> 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 > -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) From charlesmbowman at gmail.com Sun Jun 7 04:24:44 2009 From: charlesmbowman at gmail.com (Charlie Bowman) Date: Sun, 7 Jun 2009 01:24:44 -0700 Subject: [rspec-users] Missing template in helper specs with a render In-Reply-To: <85d99afe0906062202w1c1b5863q132150b955b9d059@mail.gmail.com> References: <298c4d2a0906041841t47189443u26a5b12a6b3833b8@mail.gmail.com> <57c63afe0906052040j62de7b68va9db5fc28df35665@mail.gmail.com> <1244271633.18900.5.camel@ip6-localhost> <85d99afe0906062202w1c1b5863q132150b955b9d059@mail.gmail.com> Message-ID: Sent from my iPhone On Jun 6, 2009, at 10:02 PM, Zach Dennis wrote: > On Sat, Jun 6, 2009 at 6:34 PM, Charlie Bowman > wrote: >> I consider an if statement in the view layer a bug. > > Perhaps we can consider it a possible code smell? It's not really a > bug unless it's producing incorrect or unexpected result in the > application's behaviour. Absolutely true. Not really a bug but I find it helpful to treat it as such. > > >> I often need to >> conditionally render a partial and a helper is a great way to >> construct that >> condition. Im currently stubing the call to render but I only like >> stub >> when absolutely necessary. > > Helpers can be a great way to organize some of the view's > implementation, although my goal isn't to move every conditional out > of the view, it's to avoid having unnecessary logic in the view. When > I work outside-in I'm able to push logic that doesn't belong in the > view into a presenter or further down to a model with a good method > name. The logic that is left in the view is very minimal and > ultra-simple. I find it easy to spec and it doesn't impede the life or > maintainability of the view. > > For example, if I need to display a piece of information for an admin, > but not a normal user then I have no problem doing the "if > current_user.admin?" check in a view: > > <% if current_user.admin? %> > Foo bar baz > <% end def foo_message "foo bar baz" if current_user.admin? end That's how I handle that. If for no other reason but easier testing. > > > The check itself is already ultra-simple and it reads very well. What > value would we get from moving this to a helper method? It's currently > easy to open the view and know that "Foo bar baz" will only be > rendered for an admin. Does moving this to > "display_foo_bar_baz_for_admin" really give us anything? > > There's a cost to creating a helper method for every one-off > condition. There's also a cost for turning every snippet of markup > that shows up in a simple view condition into a partial. The cost is > in the disconnect and separation that comes from doing separating > these pieces that go together as well as the organization nightmare of > a plethora of helper methods and partials. > > I like extracting helpers when it provides more value than burden. > When it doesn't I will leave the small, ultra-simple logic in the > view, > > Zach > >> >> Sent from my iPhone >> >> On Jun 6, 2009, at 12:00 AM, Hans de Graaff >> wrote: >> >>> On Fri, 2009-06-05 at 22:40 -0500, David Chelimsky wrote: >>> >>>> There is no support for rendering in helper specs as of yet. Please >>>> file a feature request if you think there should be. I have, >>>> personally, never rendered from a helper. Anybody else? >>> >>> We do this for example to render a set of unrelated items into a >>> single >>> timeline-based view. The helper sorts out the ordering and renders >>> each >>> object in it using a specific partial. >>> >>> Hans >>> _______________________________________________ >>> 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 >> > > > > -- > Zach Dennis > http://www.continuousthinking.com (personal) > http://www.mutuallyhuman.com (hire me) > http://ideafoundry.info/behavior-driven-development (first rate BDD > training) > @zachdennis (twitter) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Sun Jun 7 11:54:13 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sun, 7 Jun 2009 11:54:13 -0400 Subject: [rspec-users] Missing template in helper specs with a render In-Reply-To: References: <298c4d2a0906041841t47189443u26a5b12a6b3833b8@mail.gmail.com> <57c63afe0906052040j62de7b68va9db5fc28df35665@mail.gmail.com> <1244271633.18900.5.camel@ip6-localhost> <85d99afe0906062202w1c1b5863q132150b955b9d059@mail.gmail.com> Message-ID: On Sun, Jun 7, 2009 at 4:24 AM, Charlie Bowman wrote: > On Jun 6, 2009, at 10:02 PM, Zach Dennis wrote: >> For example, if I need to display a piece of information for an admin, >> but not a normal user then I have no problem doing the "if >> current_user.admin?" check in a view: >> >> ?<% if current_user.admin? %> >> ? ? Foo bar baz >> ?<% end > > def foo_message > ?"foo bar baz" if current_user.admin? > end > > That's how I handle that. If for no other reason but easier testing. But that refactoring is less intention revealing since it hides the fact than only admins will see that message. If I couldn't come up with a better name for foo_message which revealed that, I'd probably prefer leaving the if test in the view. Resolving the tensions between things like "dumb views" and "intention revealing names" is why they pay us the big bucks! -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From lists at ruby-forum.com Sun Jun 7 13:47:42 2009 From: lists at ruby-forum.com (Wolfram Arnold) Date: Sun, 7 Jun 2009 19:47:42 +0200 Subject: [rspec-users] Cucumber vs Rails Fixtures In-Reply-To: References: Message-ID: <8b6b60ae0ec63aba5c4a2508b9f5a368@ruby-forum.com> Yi Wen wrote: > I do this: > > Fixtures.reset_cache > fixtures_folder = File.join(RAILS_ROOT, 'test', 'fixtures') > fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| > File.basename(f, '.yml') } > fixture_class_names = {} # or whatever needed > Fixtures.create_fixtures(fixtures_folder, fixtures, fixture_class_names) Sure, that'll load fixtures and let you access them, e.g. with: User.find(1) What I wanted is to be able to access fixtures with: users(:john) Hence all the heavy lifting. It works now as described on the github wiki page. -- Posted via http://www.ruby-forum.com/. From charlesmbowman at gmail.com Sun Jun 7 13:52:37 2009 From: charlesmbowman at gmail.com (Charlie Bowman) Date: Sun, 7 Jun 2009 10:52:37 -0700 Subject: [rspec-users] Missing template in helper specs with a render In-Reply-To: References: <298c4d2a0906041841t47189443u26a5b12a6b3833b8@mail.gmail.com> <57c63afe0906052040j62de7b68va9db5fc28df35665@mail.gmail.com> <1244271633.18900.5.camel@ip6-localhost> <85d99afe0906062202w1c1b5863q132150b955b9d059@mail.gmail.com> Message-ID: <5AAF14EC-B5A6-4E92-B151-53FE38E7AF24@gmail.com> Sent from my iPhone On Jun 7, 2009, at 8:54 AM, Rick DeNatale wrote: > On Sun, Jun 7, 2009 at 4:24 AM, Charlie Bowman > wrote: >> On Jun 6, 2009, at 10:02 PM, Zach Dennis >> wrote: > >>> For example, if I need to display a piece of information for an >>> admin, >>> but not a normal user then I have no problem doing the "if >>> current_user.admin?" check in a view: >>> >>> <% if current_user.admin? %> >>> Foo bar baz >>> <% end >> >> def foo_message >> "foo bar baz" if current_user.admin? >> end >> >> That's how I handle that. If for no other reason but easier testing. > > But that refactoring is less intention revealing since it hides the > fact than only admins will see that message. > > If I couldn't come up with a better name for foo_message which > revealed that, I'd probably prefer leaving the if test in the view. > > Resolving the tensions between things like "dumb views" and "intention > revealing names" is why they pay us the big bucks! > Agreed. Should be def foo_message_if_admin And yes I know im being extreme with my view on conditional logic in views. I've found it very helpful to think this way about my views. Just by refactoring old code this way I've found and fixed bugs that hadn't even surfaced yet. > -- > Rick DeNatale > > Blog: http://talklikeaduck.denhaven2.com/ > Twitter: http://twitter.com/RickDeNatale > WWR: http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn: http://www.linkedin.com/in/rickdenatale > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lawrence.pit at gmail.com Sun Jun 7 22:40:05 2009 From: lawrence.pit at gmail.com (lawrence.pit) Date: Sun, 7 Jun 2009 19:40:05 -0700 (PDT) Subject: [rspec-users] before(:all) In-Reply-To: <57c63afe0905210446i31f9a12fl1dfdde4684538ed2@mail.gmail.com> References: <6fd630b3-7faf-40bc-9d30-284da2e89787@d38g2000prn.googlegroups.com> <57c63afe0905210446i31f9a12fl1dfdde4684538ed2@mail.gmail.com> Message-ID: Hi, I took a stab at this and created what I call Machinery. So far it works great for me. For those that are looking for a way to create objects in the database in a before(:all) instead of a before(:each) to speed up tests, have a look at: http://github.com/lawrencepit/machinery Cheers, Lawrence > > When I execute database actions within a before(:each) they are rolled > > back after each example test has run. > > Nothing built in, and it's probably not something we'd support in > rspec-rails, which simply wraps the transaction handling provided by > rails, which rolls back after every test method (equivalent of an > rspec example). > > You're not the first to have asked for this, so having a solution for > it that would work with rails out of the box and with rspec would be > helpful to the community. But I think that would have to be in a > separate gem. From lists at ruby-forum.com Mon Jun 8 01:21:29 2009 From: lists at ruby-forum.com (Salil Gaikwad) Date: Mon, 8 Jun 2009 07:21:29 +0200 Subject: [rspec-users] undefined local variable or method `params' for # References: <5a7105e9d4df55a9fc36081e16d7bd7a@ruby-forum.com> <119ac056026d4734808fe19e77ec250a@ruby-forum.com> Message-ID: <2e979239105253b072431701a2102be1@ruby-forum.com> Hi All, Any Update on this topic. I still not found any solution for a following method. it "should be active if controller is same" do tab_class('tab').should include('active') end Regards, Salil -- Posted via http://www.ruby-forum.com/. From 36srinu at gmail.com Mon Jun 8 02:35:01 2009 From: 36srinu at gmail.com (srinu) Date: Sun, 7 Jun 2009 23:35:01 -0700 (PDT) Subject: [rspec-users] Rails 2.3.2, rspec routing errors Message-ID: <76f2493d-0f5c-401d-8876-35fda4daae4b@n21g2000vba.googlegroups.com> Hi, I have turned my rails application to new version 2.3.2, with this I used to get fixtire_path error which was resolved by upgrading the plugins spec/spec-rails. Now I struck up with Routing error to run the spec, the thing which might because of routing specs. As I know my spec version=1.2.6 Any help will be appreciated. Thanks Srinivas From dchelimsky at gmail.com Mon Jun 8 08:32:51 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Jun 2009 07:32:51 -0500 Subject: [rspec-users] Rails 2.3.2, rspec routing errors In-Reply-To: <23918822.post@talk.nabble.com> References: <23918822.post@talk.nabble.com> Message-ID: <57c63afe0906080532q151043b6sbd91a41e4133246e@mail.gmail.com> On Mon, Jun 8, 2009 at 1:45 AM, 36srinu<36srinu at gmail.com> wrote: > Hi, I have turned my rails application to new version 2.3.2, with this I > used to get fixtire_path error which was resolved by upgrading the plugins > spec/spec-rails. Now I struck up with Routing error to run the spec, the > thing which might because of routing specs. As I know my spec version=1.2.6 > Any help will be appreciated. Thanks Srinivas See if http://rspec.rubyforge.org/rspec-rails/1.2.6/files/Upgrade_rdoc.html helps. If not, please post the specific failure messages you're getting. Thanks, David From dchelimsky at gmail.com Mon Jun 8 08:50:30 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Jun 2009 07:50:30 -0500 Subject: [rspec-users] undefined local variable or method `params' for # References: <5a7105e9d4df55a9fc36081e16d7bd7a@ruby-forum.com> <119ac056026d4734808fe19e77ec250a@ruby-forum.com> <2e979239105253b072431701a2102be1@ruby-forum.com> Message-ID: <57c63afe0906080550n60ea45dbx9d9a1832e49a79fb@mail.gmail.com> On Mon, Jun 8, 2009 at 12:21 AM, Salil Gaikwad wrote: > Hi All, > > Any Update on this topic. > > I still not found any solution for a following method. > > ?it "should be active if controller is same" do > ? ?tab_class('tab').should include('active') > ?end Please read http://wiki.github.com/dchelimsky/rspec/get-in-touch and try again. There is a lot of missing context information here. Thanks, David > > > Regards, > > Salil > -- > 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 Mon Jun 8 09:31:45 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 8 Jun 2009 15:31:45 +0200 Subject: [rspec-users] Troble running controller spec In-Reply-To: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> Message-ID: <4d688e753514dc23e3838da815505f79@ruby-forum.com> David Chelimsky wrote: > On Fri, May 22, 2009 at 1:41 AM, Amit Kulkarni > wrote: >> >> ? end >> >> ? it "should create channel" do >> ? ?Channel.should_receive(:new).with(:brand_name => "test" >> ).and_return(@channel) > > I *think* Rails converts the keys in this hash to strings. Try: > > Channel.should_receive(:new).with('brand_name' => 'test'). > and_return(@channel) > Hi, I tried with the above command but it still gives the same error.Dont know what is wrong.I am following the same which is given in the book Details are as follows require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ChannelsController do describe "Channel Creation" do before(:each) do @channel = mock_model(Channel, :save => nil) Channel.stub!(:new).and_return(@channel) end it "should create channel" do Channel.should_receive(:new).with('brand_name' => 'manager' ).and_return(@channel) post :create, :channel => {'brand_name' => 'manager' } end it "should save channel" do @channel.should_receive(:save) post :create end end Following are the errors {Please ignore the missing a's :-)} ChnnelsController Chnnel Cretion should crete chnnel (FILED - 1) should sve chnnel (FILED - 2) 1) Spec::Mocks::MockExpecttionError in 'ChnnelsController Chnnel Cretion should cre te chnnel' expected :new with ({"brnd_nme"=>"mnger"}) once, but received it 0 times ./spec/controllers/chnnels_controller_spec.rb:183: script/spec:4: 2) Spec::Mocks::MockExpecttionError in 'ChnnelsController Chnnel Cretion should sve chnnel' Mock 'Chnnel_1002' expected :sve with (ny rgs) once, but received it 0 times ./spec/controllers/chnnels_controller_spec.rb:188: script/spec:4: Finished in 0.305 seconds 2 exmples, 2 filures -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Jun 8 10:03:21 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Jun 2009 09:03:21 -0500 Subject: [rspec-users] Troble running controller spec In-Reply-To: <4d688e753514dc23e3838da815505f79@ruby-forum.com> References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> <4d688e753514dc23e3838da815505f79@ruby-forum.com> Message-ID: <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> On Mon, Jun 8, 2009 at 8:31 AM, Amit Kulkarni wrote: > David Chelimsky wrote: >> On Fri, May 22, 2009 at 1:41 AM, Amit Kulkarni >> wrote: >>> >>> ? end >>> >>> ? it "should create channel" do >>> ? ?Channel.should_receive(:new).with(:brand_name => "test" >>> ).and_return(@channel) >> >> I *think* Rails converts the keys in this hash to strings. Try: >> >> Channel.should_receive(:new).with('brand_name' => 'test'). >> ? and_return(@channel) >> > > Hi, > > I tried with the above command but it still gives the same error.Dont > know what is wrong.I am following the same which is given in the book > Details are as follows > > require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') > > describe ChannelsController do > ?describe "Channel Creation" do > ? ?before(:each) do > ? ? ?@channel = mock_model(Channel, :save => nil) > ? ? ?Channel.stub!(:new).and_return(@channel) > ? ?end > > ? ?it "should create channel" do > ? ? ?Channel.should_receive(:new).with('brand_name' => 'manager' > ).and_return(@channel) > ? ? ?post :create, :channel => {'brand_name' => 'manager' } > ? ?end > > ? ?it "should save channel" do > ? ? ?@channel.should_receive(:save) > ? ? ?post :create > ? ?end > ?end I went as far as to create a rails 2.1.2 project with rspec and rspec-rails 1.2.4, copy your code into it and ran the specs. They both pass. I don't have a Vista environment in which to test this, so that's all I can do to help at the moment. Anybody else running into similar problems on Vista? > > > Following are the errors > {Please ignore the missing a's :-)} > > ChnnelsController > ?Chnnel Cretion > ? ?should crete chnnel (FILED - 1) > ? ?should sve chnnel (FILED - 2) > > 1) > Spec::Mocks::MockExpecttionError in 'ChnnelsController Chnnel Cretion > should cre > te chnnel' > logo_file_size: st > ring, logo_content_type: string, points: integer, rnk: integer, > overruled_rnk: b > oolen, title: string, description: text, tgs: string, url: string, > kit_file_nme: > ?string, kit_file_size: string, kit_content_type: string, ctive: boolen, > bg_colo > r: string, font_color: string, title_color: string, title_style: string, > emotion > l_file_nme: string, emotionl_file_size: string, emotionl_content_type: > string, n > cestor_id: integer, chnnel_ctegory_id: integer, creted_t: dtetime, > updted_t: dte > time) (clss)> expected :new with ({"brnd_nme"=>"mnger"}) once, but > received it 0 > ?times > ./spec/controllers/chnnels_controller_spec.rb:183: > script/spec:4: > > 2) > Spec::Mocks::MockExpecttionError in 'ChnnelsController Chnnel Cretion > should sve > ?chnnel' > Mock 'Chnnel_1002' expected :sve with (ny rgs) once, but received it 0 > times > ./spec/controllers/chnnels_controller_spec.rb:188: > script/spec:4: > > Finished in 0.305 seconds > > 2 exmples, 2 filures > > > -- > 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 Mon Jun 8 10:48:37 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 8 Jun 2009 16:48:37 +0200 Subject: [rspec-users] Troble running controller spec In-Reply-To: <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> <4d688e753514dc23e3838da815505f79@ruby-forum.com> <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> Message-ID: David Chelimsky wrote: > On Mon, Jun 8, 2009 at 8:31 AM, Amit Kulkarni > wrote: >>> I *think* Rails converts the keys in this hash to strings. Try: >> >> Channel.should_receive(:new).with('brand_name' => 'manager' >> ).and_return(@channel) >> post :create, :channel => {'brand_name' => 'manager' } >> end >> >> it "should save channel" do >> @channel.should_receive(:save) >> post :create >> end >> end > > I went as far as to create a rails 2.1.2 project with rspec and > rspec-rails 1.2.4, copy your code into it and ran the specs. They both > pass. I don't have a Vista environment in which to test this, so > that's all I can do to help at the moment. > > Anybody else running into similar problems on Vista? > Thanks a lot for looking into the matter.I am not sure if i am getting this problem due to vista environment.If it is then i dont know what to do :-( Also i didnt understand b the statement "create a rails 2.1.2 project with rspec and rspec-rails 1.2.4, copy your code into it and ran the specs." Also i checked my spec version it is 1.2.6,so does this causing the problem. This version got updated from 1.2.4. Please suggest. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Jun 8 11:01:27 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Jun 2009 10:01:27 -0500 Subject: [rspec-users] Troble running controller spec In-Reply-To: References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> <4d688e753514dc23e3838da815505f79@ruby-forum.com> <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> Message-ID: <57c63afe0906080801p38f67629s7c2babd25c79eb07@mail.gmail.com> On Mon, Jun 8, 2009 at 9:48 AM, Amit Kulkarni wrote: > David Chelimsky wrote: >> On Mon, Jun 8, 2009 at 8:31 AM, Amit Kulkarni >> wrote: >>>> I *think* Rails converts the keys in this hash to strings. Try: >>> >>> ? ? ?Channel.should_receive(:new).with('brand_name' => 'manager' >>> ).and_return(@channel) >>> ? ? ?post :create, :channel => {'brand_name' => 'manager' } >>> ? ?end >>> >>> ? ?it "should save channel" do >>> ? ? ?@channel.should_receive(:save) >>> ? ? ?post :create >>> ? ?end >>> ?end >> >> I went as far as to create a rails 2.1.2 project with rspec and >> rspec-rails 1.2.4, copy your code into it and ran the specs. They both >> pass. I don't have a Vista environment in which to test this, so >> that's all I can do to help at the moment. >> >> Anybody else running into similar problems on Vista? >> > > Thanks a lot for looking into the matter.I am not sure if i am getting > this problem due to vista environment.If it is then i dont know what to > do :-( > > Also i didnt understand b the statement > "create a rails 2.1.2 project with rspec and rspec-rails 1.2.4, copy > your code into it and ran the specs." The versions you cited earlier were rails 2.1.2 and rspec 1.2.4, so I did the following: * created a rails 2.1.2 project * configured it to use rspec 1.2.4 * created a ChannelsController and a spec for it * created a Channel model with a migration and ran the migration * copied the code you posted in this thread to app/controllers/channels_controller.rb and spec/controllers/channels_controller_spec.rb * ran the specs * watched them pass > > Also i checked my spec version it is 1.2.6,so does this causing the > problem. > This version got updated from 1.2.4. > Please suggest. You stated above that you were using 1.2.4, but now you are saying you are using 1.2.6. Please be sure to provide accurate information. Do you have both rspec and rspec-rails? And are they both 1.2.6 now? FYI - I get the same result from 1.2.6. All specs pass. > -- > 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 Mon Jun 8 11:10:28 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 8 Jun 2009 17:10:28 +0200 Subject: [rspec-users] Troble running controller spec In-Reply-To: <57c63afe0906080801p38f67629s7c2babd25c79eb07@mail.gmail.com> References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> <4d688e753514dc23e3838da815505f79@ruby-forum.com> <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> <57c63afe0906080801p38f67629s7c2babd25c79eb07@mail.gmail.com> Message-ID: > You stated above that you were using 1.2.4, but now you are saying you > are using 1.2.6. Please be sure to provide accurate information. I am sorry for the above information.Yes earlier the version was 1.2.4 but i installed rspec again and it installed the latest version i.e 1.2.6 > Do you have both rspec and rspec-rails? And are they both 1.2.6 now? > Yes i have both rspec and rspec-rails as 1.2.6 and 1.2.4 installed. > FYI - I get the same result from 1.2.6. All specs pass. -- Posted via http://www.ruby-forum.com/. From ru_ghetto at rubyghetto.com Mon Jun 8 23:33:17 2009 From: ru_ghetto at rubyghetto.com (ru_ghetto) Date: Mon, 8 Jun 2009 20:33:17 -0700 (PDT) Subject: [rspec-users] Adding specs to engines Message-ID: <97f5463f-c7fc-4f7d-af64-54dfc2b118f5@c9g2000yqm.googlegroups.com> I am breaking an app into a bunch of rails 2.x style engine plugins. The app is already tested with rspec and I am trying to figure out how to get autotest or even rake spec to run the examples in the plugins. Thanks for any information From dchelimsky at gmail.com Tue Jun 9 00:37:29 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Jun 2009 23:37:29 -0500 Subject: [rspec-users] Adding specs to engines In-Reply-To: <97f5463f-c7fc-4f7d-af64-54dfc2b118f5@c9g2000yqm.googlegroups.com> References: <97f5463f-c7fc-4f7d-af64-54dfc2b118f5@c9g2000yqm.googlegroups.com> Message-ID: <57c63afe0906082137y471d24a1y9511801822240fb3@mail.gmail.com> On Mon, Jun 8, 2009 at 10:33 PM, ru_ghetto wrote: > I am breaking an app into a bunch of rails 2.x style engine plugins. > The app is already tested with rspec and I am trying to figure out how > to get autotest or even rake spec to run the examples in the plugins. > > Thanks for any information For plugins there is a rake spec:plugins task, but you can also roll your own rake task pretty easily. Just take a look at all the different spec tasks in lib/tasks/rspec.rake (generated when you ran script/generate rspec). Also doco is here: http://rspec.rubyforge.org/rspec/1.2.6/classes/Spec/Rake/SpecTask.html HTH, David From lists at ruby-forum.com Tue Jun 9 02:19:44 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Tue, 9 Jun 2009 08:19:44 +0200 Subject: [rspec-users] Troble running controller spec In-Reply-To: References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> <4d688e753514dc23e3838da815505f79@ruby-forum.com> <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> <57c63afe0906080801p38f67629s7c2babd25c79eb07@mail.gmail.com> Message-ID: Amit Kulkarni wrote: >> You stated above that you were using 1.2.4, but now you are saying you >> are using 1.2.6. Please be sure to provide accurate information. > > I am sorry for the above information.Yes earlier the version was 1.2.4 > but i installed rspec again and it installed the latest version i.e > 1.2.6 > >> Do you have both rspec and rspec-rails? And are they both 1.2.6 now? >> Yes i have both rspec and rspec-rails as 1.2.6 and 1.2.4 installed. > >> FYI - I get the same result from 1.2.6. All specs pass. Any Updates.... :-) -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Jun 9 07:58:10 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 9 Jun 2009 06:58:10 -0500 Subject: [rspec-users] Troble running controller spec In-Reply-To: References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> <4d688e753514dc23e3838da815505f79@ruby-forum.com> <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> <57c63afe0906080801p38f67629s7c2babd25c79eb07@mail.gmail.com> Message-ID: <57c63afe0906090458w1276878jd84d3cc52554b671@mail.gmail.com> On Tue, Jun 9, 2009 at 1:19 AM, Amit Kulkarni wrote: > Amit Kulkarni wrote: >>> You stated above that you were using 1.2.4, but now you are saying you >>> are using 1.2.6. Please be sure to provide accurate information. >> >> I am sorry for the above information.Yes earlier the version was 1.2.4 >> but i installed rspec again and it installed the latest version i.e >> 1.2.6 >> >>> Do you have both rspec and rspec-rails? And are they both 1.2.6 now? >>> Yes i have both rspec and rspec-rails as 1.2.6 and 1.2.4 installed. >> >>> FYI - I get the same result from 1.2.6. All specs pass. > > Any Updates.... > :-) Any Vista users in earshot? I've done all I can do on this. From philodespotos at gmail.com Tue Jun 9 10:05:03 2009 From: philodespotos at gmail.com (Kyle Hargraves) Date: Tue, 9 Jun 2009 09:05:03 -0500 Subject: [rspec-users] before(:all) In-Reply-To: References: <6fd630b3-7faf-40bc-9d30-284da2e89787@d38g2000prn.googlegroups.com> <57c63afe0905210446i31f9a12fl1dfdde4684538ed2@mail.gmail.com> Message-ID: <60f3810c0906090705n29fd0964g8c28711cc69975fa@mail.gmail.com> On Sun, Jun 7, 2009 at 9:40 PM, lawrence.pit wrote: > Hi, > > I took a stab at this and created what I call Machinery. So far it > works great for me. > > For those that are looking for a way to create objects in the database > in a before(:all) instead of a before(:each) to speed up tests, have a > look at: > > http://github.com/lawrencepit/machinery This plugin is *awesome*. Thank you. =) k From lists at ruby-forum.com Tue Jun 9 10:27:15 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Tue, 9 Jun 2009 16:27:15 +0200 Subject: [rspec-users] Troble running controller spec In-Reply-To: <57c63afe0906090458w1276878jd84d3cc52554b671@mail.gmail.com> References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> <4d688e753514dc23e3838da815505f79@ruby-forum.com> <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> <57c63afe0906080801p38f67629s7c2babd25c79eb07@mail.gmail.com> <57c63afe0906090458w1276878jd84d3cc52554b671@mail.gmail.com> Message-ID: <427c51acf5a09884ce63bc4f11742b10@ruby-forum.com> David Chelimsky wrote: > On Tue, Jun 9, 2009 at 1:19 AM, Amit Kulkarni > wrote: >>> >>>> FYI - I get the same result from 1.2.6. All specs pass. >> >> Any Updates.... >> :-) > > Any Vista users in earshot? I've done all I can do on this. Oh ok. -- Posted via http://www.ruby-forum.com/. From tech at onghu.com Tue Jun 9 11:30:29 2009 From: tech at onghu.com (Mohit Sindhwani) Date: Tue, 09 Jun 2009 23:30:29 +0800 Subject: [rspec-users] Troble running controller spec In-Reply-To: <57c63afe0906090458w1276878jd84d3cc52554b671@mail.gmail.com> References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> <4d688e753514dc23e3838da815505f79@ruby-forum.com> <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> <57c63afe0906080801p38f67629s7c2babd25c79eb07@mail.gmail.com> <57c63afe0906090458w1276878jd84d3cc52554b671@mail.gmail.com> Message-ID: <4A2E8015.2060005@onghu.com> David Chelimsky wrote: > On Tue, Jun 9, 2009 at 1:19 AM, Amit Kulkarni wrote: > >> Amit Kulkarni wrote: >> >>>> You stated above that you were using 1.2.4, but now you are saying you >>>> are using 1.2.6. Please be sure to provide accurate information. >>>> >>> I am sorry for the above information.Yes earlier the version was 1.2.4 >>> but i installed rspec again and it installed the latest version i.e >>> 1.2.6 >>> >>> >>>> Do you have both rspec and rspec-rails? And are they both 1.2.6 now? >>>> Yes i have both rspec and rspec-rails as 1.2.6 and 1.2.4 installed. >>>> >>>> FYI - I get the same result from 1.2.6. All specs pass. >>>> >> Any Updates.... >> :-) >> > > Any Vista users in earshot? I've done all I can do on this. Hi David I'm on Vista, but I just joined the mailing list - could I have a bit of a background to what we're trying to do? I'll try to see what I can do. Cheers, Mohit. 6/9/2009 | 11:30 PM. From dchelimsky at gmail.com Tue Jun 9 13:31:40 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 9 Jun 2009 12:31:40 -0500 Subject: [rspec-users] Troble running controller spec In-Reply-To: <4A2E8015.2060005@onghu.com> References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> <4d688e753514dc23e3838da815505f79@ruby-forum.com> <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> <57c63afe0906080801p38f67629s7c2babd25c79eb07@mail.gmail.com> <57c63afe0906090458w1276878jd84d3cc52554b671@mail.gmail.com> <4A2E8015.2060005@onghu.com> Message-ID: <57c63afe0906091031w30285803ocb6e527b802ec7c0@mail.gmail.com> On Tue, Jun 9, 2009 at 10:30 AM, Mohit Sindhwani wrote: > David Chelimsky wrote: >> >> On Tue, Jun 9, 2009 at 1:19 AM, Amit Kulkarni wrote: >> >>> >>> Amit Kulkarni wrote: >>> >>>>> >>>>> You stated above that you were using 1.2.4, but now you are saying you >>>>> are using 1.2.6. Please be sure to provide accurate information. >>>>> >>>> >>>> I am sorry for the above information.Yes earlier the version was 1.2.4 >>>> but i installed rspec again and it installed the latest version i.e >>>> 1.2.6 >>>> >>>> >>>>> >>>>> Do you have both rspec and rspec-rails? And are they both 1.2.6 now? >>>>> Yes i have both rspec and rspec-rails as 1.2.6 and 1.2.4 installed. >>>>> ? ? ? ?FYI - I get the same result from 1.2.6. All specs pass. >>>>> >>> >>> Any Updates.... >>> :-) >>> >> >> Any Vista users in earshot? I've done all I can do on this. > > Hi David > > I'm on Vista, but I just joined the mailing list - could I have a bit of a > background to what we're trying to do? ?I'll try to see what I can do. Thanks for volunteering to help Amit. You can see the full thread at http://groups.google.com/group/rspec/browse_thread/thread/dc0f97750a92f7bd. Cheers, David > > Cheers, > Mohit. > 6/9/2009 | 11:30 PM. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hvolkmer at gmail.com Tue Jun 9 16:25:30 2009 From: hvolkmer at gmail.com (Hendrik Volkmer) Date: Tue, 9 Jun 2009 22:25:30 +0200 Subject: [rspec-users] Adding specs to engines In-Reply-To: <97f5463f-c7fc-4f7d-af64-54dfc2b118f5@c9g2000yqm.googlegroups.com> References: <97f5463f-c7fc-4f7d-af64-54dfc2b118f5@c9g2000yqm.googlegroups.com> Message-ID: Hi! On Tue, Jun 9, 2009 at 5:33 AM, ru_ghetto wrote: > I am breaking an app into a bunch of rails 2.x style engine plugins. > The app is already tested with rspec and I am trying to figure out how > to get autotest or even rake spec to run the examples in the plugins. We use our dry_plugin_test_helper [1] to test our engines. The TODOs at the bottom of the README are solved. So it should work with RSpec. You should use PluginTestEnvironment.initialize_engines_environment instead of PluginTestEnvironment.initialize_environment for engines tests/specs. Cheers, Hendrik http://github.com/imedo/dry_plugin_test_helper/tree/master From lists at ruby-forum.com Tue Jun 9 23:27:18 2009 From: lists at ruby-forum.com (Alexandre Da silva) Date: Wed, 10 Jun 2009 05:27:18 +0200 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> Message-ID: <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> David Chelimsky wrote: > On Mon, Apr 6, 2009 at 4:50 PM, Arco wrote: >> github.com/grosser/autotest/tree/master). >> >> Is there a way to make autospec run just once if it sees a red >> example? >> >> I am using rspec 1.2.2, platform: cygwin - testing a standalone ruby >> class. > > What's in your spec/spec.opts file? I get the same behavior.... my spec/spec.opts contains: --colour --format progress --loadby mtime --reverse I can reproduce in a new project... rails blog cd blog/ script/generate rspec script/generate rspec_scaffold posts title:string body:text rm -rf test/ rake db:create:all rake db:migrate rake db:test:prepare autospec # posts generated in plural to get error at beginning the loop runs forever -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Jun 9 23:28:40 2009 From: lists at ruby-forum.com (Alexandre Da silva) Date: Wed, 10 Jun 2009 05:28:40 +0200 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> Message-ID: <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> sorry my self reply... but I forgot to mention that I am running Ubuntu 8.10 ruby 1.8.7.xx -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Jun 10 06:55:48 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Wed, 10 Jun 2009 12:55:48 +0200 Subject: [rspec-users] Mock and Stub objects Message-ID: Hello, I had seen many controller spec using mock and stub objects. I had written controller spec earlier without these objects. In the book it is mention about mock and stub objects.but i am still not getting the reason behind it. Can somebody tell me what are these and why are we using it especially in controllers? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Jun 10 13:56:35 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 10 Jun 2009 12:56:35 -0500 Subject: [rspec-users] Mock and Stub objects In-Reply-To: References: Message-ID: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> On Wed, Jun 10, 2009 at 5:55 AM, Amit Kulkarni wrote: > Hello, > > ? ? ?I had seen many controller spec using mock and stub objects. > > ? ? ?I had written controller spec earlier without these objects. > > ? ? ?In the book it is mention about mock and stub objects.but i am > still not getting the reason behind it. Did you read the chapter on Mock Objects? > > ? ? ?Can somebody tell me what are these and why are we using it > especially in controllers? From solaris at sundevil.de Wed Jun 10 06:44:08 2009 From: solaris at sundevil.de (Hendrik Volkmer) Date: Wed, 10 Jun 2009 12:44:08 +0200 Subject: [rspec-users] Adding specs to engines In-Reply-To: <97f5463f-c7fc-4f7d-af64-54dfc2b118f5@c9g2000yqm.googlegroups.com> References: <97f5463f-c7fc-4f7d-af64-54dfc2b118f5@c9g2000yqm.googlegroups.com> Message-ID: On Tue, Jun 9, 2009 at 5:33 AM, ru_ghetto wrote: > I am breaking an app into a bunch of rails 2.x style engine plugins. > The app is already tested with rspec and I am trying to figure out how > to get autotest or even rake spec to run the examples in the plugins. We use our dry_plugin_test_helper [1] to test our engines. The TODOs at the bottom of the README are solved. So it should work with RSpec. You should use PluginTestEnvironment.initialize_engines_environment instead of PluginTestEnvironment.initialize_environment for engines tests/specs. Cheers, Hendrik http://github.com/imedo/dry_plugin_test_helper/tree/master From lists at ruby-forum.com Wed Jun 10 02:48:53 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Wed, 10 Jun 2009 08:48:53 +0200 Subject: [rspec-users] Troble running controller spec In-Reply-To: <4A2E8015.2060005@onghu.com> References: <57c63afe0905220335s3c7a9657xf6562acd8a4b7998@mail.gmail.com> <4d688e753514dc23e3838da815505f79@ruby-forum.com> <57c63afe0906080703r65abe625p1634fee81ca2f7dc@mail.gmail.com> <57c63afe0906080801p38f67629s7c2babd25c79eb07@mail.gmail.com> <57c63afe0906090458w1276878jd84d3cc52554b671@mail.gmail.com> <4A2E8015.2060005@onghu.com> Message-ID: <54a5ec34cddbd3084bf54a777db60a63@ruby-forum.com> Mohit Sindhwani wrote: > David Chelimsky wrote: >>>> >> Any Vista users in earshot? I've done all I can do on this. > Hi David > > I'm on Vista, but I just joined the mailing list - could I have a bit of > a background to what we're trying to do? I'll try to see what I can do. > > Cheers, > Mohit. > 6/9/2009 | 11:30 PM. Thanks Mohit. -- Posted via http://www.ruby-forum.com/. From sfeley at gmail.com Wed Jun 10 14:39:46 2009 From: sfeley at gmail.com (Stephen Eley) Date: Wed, 10 Jun 2009 14:39:46 -0400 Subject: [rspec-users] Mock and Stub objects In-Reply-To: References: Message-ID: <1fb4df0906101139h7e6e6a9t3265372cdb49ed2f@mail.gmail.com> On Wed, Jun 10, 2009 at 6:55 AM, Amit Kulkarni wrote: > > ? ? ?In the book it is mention about mock and stub objects.but i am > still not getting the reason behind it. The Very Short Answer: You don't want your controller specs failing because your model is broken. Your _model_ specs should fail instead. You also don't want your controller specs running slow because it's hitting a database. (That, again, is the model's problem.) The answer to this is not to talk to the model in your controller specs. Your specs talk only to the controller. For everything else, you create one or more fake model-like thingies that give all the right answers when asked the right questions. Then, when your controller specs fail, you know where to focus your energy. In the controller. (That, or they fail because the specs or the mocks and stubs are slightly wrong. In my experience that's more common, and that's one reason why I hardly ever do controller specs any more. But still: there you go. That's the reason for the way it's done canonically.) -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Wed Jun 10 22:50:09 2009 From: lists at ruby-forum.com (Zach Powell) Date: Thu, 11 Jun 2009 04:50:09 +0200 Subject: [rspec-users] spec_server errors when reloading fixture replacement pl In-Reply-To: References: <1106da77-505a-4262-b9df-a67c9af6027b@w35g2000prg.googlegroups.com> <49CF1F6E.7080905@railsnewbie.com> <7a9e7cb7-5bc3-499e-9986-36cb6e4a8e69@j9g2000prh.googlegroups.com> <49CF3411.9040409@railsnewbie.com> <4eab1d15-ce00-4992-a81a-9fdcc9d02eb0@z16g2000prd.googlegroups.com> <57c63afe0905010704r254bab7bn5ac3d32b8027672f@mail.gmail.com> Message-ID: <47e6f1f1659e51b5ab0e3c1600e58d21@ruby-forum.com> Ben Johnson wrote: > Did anyone ever figure out the factory_girl / machinist issues? I am > having the same problems and can figure out how to fix it for the life > of me. The first run works fine, then afterwards I get a bunch of these > errors: > > No blueprint for class Venue > > Any ideas? Thanks! I found that using load File.expand_path(File.dirname(__FILE__) + "/blueprints.rb") in the spec_helper.rb did the trick. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Jun 11 03:17:38 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Thu, 11 Jun 2009 09:17:38 +0200 Subject: [rspec-users] Mock and Stub objects In-Reply-To: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> References: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> Message-ID: <29526f4662fa39f1da04186918701984@ruby-forum.com> David Chelimsky wrote: > On Wed, Jun 10, 2009 at 5:55 AM, Amit Kulkarni > wrote: >> Hello, >> >> ? ? ?I had seen many controller spec using mock and stub objects. >> >> ? ? ?I had written controller spec earlier without these objects. >> >> ? ? ?In the book it is mention about mock and stub objects.but i am >> still not getting the reason behind it. > > Did you read the chapter on Mock Objects? Yes i have read Mock Objects. I understood a bit that Mock object create objects virtually so that we can run our specs.It helps us in that we dont have to actually create those objects. But i am still not getting my hand on it. we may have a situation that just for instance that all the development is done and we are now writing the spec for it.In this case all the coding in controller,model are done. So when we write specs for controller do we have to create mock objects? What if we write specs in controller without using mock objects?Will it be fine? Also since i am using the beta version Mocking Objects part is not there.And it is does not give clearcut idea from the topic Mock Objects. Also it will be very helpful if you can provide me a link or anything which can give me details of Mocks and Stubs.How to use it?When to use it..e.t.c Thanks & Regards, Amit -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Thu Jun 11 04:43:48 2009 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 11 Jun 2009 09:43:48 +0100 Subject: [rspec-users] Mock and Stub objects In-Reply-To: <29526f4662fa39f1da04186918701984@ruby-forum.com> References: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> <29526f4662fa39f1da04186918701984@ruby-forum.com> Message-ID: <46E063A1-C6AA-4D01-AEF8-C83F5460C800@mattwynne.net> On 11 Jun 2009, at 08:17, Amit Kulkarni wrote: > David Chelimsky wrote: >> On Wed, Jun 10, 2009 at 5:55 AM, Amit Kulkarni >> wrote: >>> Hello, >>> >>> ? ? ?I had seen many controller spec using mock and stub >>> objects. >>> >>> ? ? ?I had written controller spec earlier without these >>> objects. >>> >>> ? ? ?In the book it is mention about mock and stub >>> objects.but i am >>> still not getting the reason behind it. >> >> Did you read the chapter on Mock Objects? > > Yes i have read Mock Objects. > I understood a bit that Mock object create objects virtually so that > we > can run our specs.It helps us in that we dont have to actually create > those objects. > > But i am still not getting my hand on it. > > we may have a situation that just for instance that all the > development > is done and we are now writing the spec for it.In this case all the > coding in controller,model are done. > So when we write specs for controller do we have to create mock > objects? > What if we write specs in controller without using mock objects?Will > it > be fine? If you're writing the specs after you've written the code, you're losing a lot of the value of mock objects. Mock objects were originally devised as a design tool for use when doing TDD. TDD stands for Test *Driven* Development, meaning that you write the test before you have written any of the code. When you're doing this, you want to be able to build the system piece by piece, class by class, so you write tests for a single object at a time, and use mock objects to assemble quick, lightweight sketches of the surrounding objects that you imagine it will interact with when the system is finished. > Also since i am using the beta version Mocking Objects part is not > there.And it is does not give clearcut idea from the topic Mock > Objects. > Also it will be very helpful if you can provide me a link or anything > which can give me details of Mocks and Stubs.How to use it?When to use > it..e.t.c This is a big topic which is not going to be easy to explain over email. Here is some more stuff for you to read. http://www.patmaddox.com/blog/you-probably-dont-get-mocks http://www.mockobjects.com/book/ http://www.jmock.org/oopsla2004.pdf http://www.martinfowler.com/articles/mocksArentStubs.html Matt Wynne http://beta.songkick.com http://blog.mattwynne.net From lists at ruby-forum.com Thu Jun 11 05:39:28 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Thu, 11 Jun 2009 11:39:28 +0200 Subject: [rspec-users] Mock and Stub objects In-Reply-To: <46E063A1-C6AA-4D01-AEF8-C83F5460C800@mattwynne.net> References: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> <29526f4662fa39f1da04186918701984@ruby-forum.com> <46E063A1-C6AA-4D01-AEF8-C83F5460C800@mattwynne.net> Message-ID: <4f319adc94f989870fe60f6a7e59bf05@ruby-forum.com> Matt Wynne wrote: > On 11 Jun 2009, at 08:17, Amit Kulkarni wrote: > >>>> >> those objects. >> it >> be fine? > > If you're writing the specs after you've written the code, you're > losing a lot of the value of mock objects. Actually i am writing specs before the code is written.I saw many examples especially in controllers they are using mocks.So i was bit confused regarding the same. Also Imagine the same situation where code is written and we are writing specs for that then is it necessary to use mocks?If Yes why since code is already written? > Mock objects were originally devised as a design tool for use when > doing TDD. TDD stands for Test *Driven* Development, meaning that you > write the test before you have written any of the code. When you're > doing this, you want to be able to build the system piece by piece, > class by class, so you write tests for a single object at a time, and > use mock objects to assemble quick, lightweight sketches of the > surrounding objects that you imagine it will interact with when the > system is finished. > >> Also since i am using the beta version Mocking Objects part is not >> there.And it is does not give clearcut idea from the topic Mock >> Objects. >> Also it will be very helpful if you can provide me a link or anything >> which can give me details of Mocks and Stubs.How to use it?When to use >> it..e.t.c > > This is a big topic which is not going to be easy to explain over > email. Here is some more stuff for you to read. > > http://www.patmaddox.com/blog/you-probably-dont-get-mocks > http://www.mockobjects.com/book/ > http://www.jmock.org/oopsla2004.pdf > http://www.martinfowler.com/articles/mocksArentStubs.html Thanks a lot Matt for the above links. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Jun 11 09:36:28 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Jun 2009 08:36:28 -0500 Subject: [rspec-users] Mock and Stub objects In-Reply-To: <4f319adc94f989870fe60f6a7e59bf05@ruby-forum.com> References: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> <29526f4662fa39f1da04186918701984@ruby-forum.com> <46E063A1-C6AA-4D01-AEF8-C83F5460C800@mattwynne.net> <4f319adc94f989870fe60f6a7e59bf05@ruby-forum.com> Message-ID: <57c63afe0906110636vd0e75a6oc43642dbb31e9040@mail.gmail.com> On Thu, Jun 11, 2009 at 4:39 AM, Amit Kulkarni wrote: > Matt Wynne wrote: >> On 11 Jun 2009, at 08:17, Amit Kulkarni wrote: >> >>>>> >>> those objects. >>> it >>> be fine? >> >> If you're writing the specs after you've written the code, you're >> losing a lot of the value of mock objects. > > Actually i am writing specs before the code is written.I saw many > examples especially in controllers they are using mocks.So i was bit > confused regarding the same. > > Also Imagine the same situation where code is written and we are writing > specs for that then is it necessary to use mocks?If Yes why since code > is already written? It's not a matter of necessity, but rather a matter of costs and benefits. This is a very complex and subtle topic, which is one reason a lot of people who avoid mocking do so. At some level, it is simpler to not use any mocks or stubs anywhere. But if you choose that path, there are a lot of benefits you're missing out on. Steve wrote in his reply earlier in this thread that we don't want out controller specs failing because the model is broken. But it's not just when the model breaks. It's when the model *changes*. Say, for example, that we've got a Widget model that has a required name attribute, and an optional date attribute. We've got this in our controller spec: describe WidgetsController do describe "POST create" do context "with valid attributes" do it "redirects to the widget list" do post :create, :widget => {:name => 'Foo'} response.should redirect_to(widgets_path) end end context "with invalid attributes" do it "re-renders the 'new' template" do post :create, :widget => {} #missing the required name response.should render_template('new') end end end end Now imagine that we're working on the model spec and we get a new requirement that the date is required. So we write a spec: describe Widget do it "requires a date attribute" do Widget.new(:name => 'Foo', :date => nil).should_not be_valid end end That fails, so we add "validates_presence_of :date" to the model and then the spec passes. Success! Except now the valid attributes case in the controller spec fails because we've changed the meaning of valid for this model. So you have to go back and change this and every other example that creates a Widget without a date. Now stubs/mocks are certainly not the only way to fix this problem. You can use fixtures, centralized helper methods, object mothers, and test data builders. These are all tools that help you centralize the creation of objects, so when you do run into this sort of problem, you only need to fix it in one place. But you still need to fix it once, which takes your focus away from the task at hand. And you don't get the speed savings you get w/ stubs/mocks. And you still get controller specs failing when models are broken. For the record, I generally use stubs/mocks in controller specs, but I tend towards test data builders in model specs. But I'm also very comfortable with all of these tools and am perfectly willing to use test data builders in controller specs or mocks/stubs in model specs when that is the better choice for a given situation. Really, I think that's what we should all be striving for. Not so much "should I use mocks or not," but "when should I choose to use them?" HTH, David >> Mock objects were originally devised as a design tool for use when >> doing TDD. TDD stands for Test *Driven* Development, meaning that you >> write the test before you have written any of the code. When you're >> doing this, you want to be able to build the system piece by piece, >> class by class, so you write tests for a single object at a time, and >> use mock objects to assemble quick, lightweight sketches of the >> surrounding objects that you imagine it will interact with when the >> system is finished. >> >>> Also since i am using the beta version Mocking Objects part is not >>> there.And it is does not give clearcut idea from the topic Mock >>> Objects. >>> Also it will be very helpful if you can provide me a link or anything >>> which can give me details of Mocks and Stubs.How to use it?When to use >>> it..e.t.c >> >> This is a big topic which is not going to be easy to explain over >> email. Here is some more stuff for you to read. >> >> http://www.patmaddox.com/blog/you-probably-dont-get-mocks >> http://www.mockobjects.com/book/ >> http://www.jmock.org/oopsla2004.pdf >> http://www.martinfowler.com/articles/mocksArentStubs.html > > Thanks a lot Matt for the above links. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jpm.van.dijk at gmail.com Thu Jun 11 05:49:36 2009 From: jpm.van.dijk at gmail.com (John van Dijk) Date: Thu, 11 Jun 2009 02:49:36 -0700 (PDT) Subject: [rspec-users] Textmate Bundle focussed test Message-ID: When running a focussed (single) example in textmate and have no description like this: it { should do_something } I get not the desired effect :) Is there a way to get this to work? (When running all examples this is no problem and works fine) regards, j. From dchelimsky at gmail.com Thu Jun 11 10:02:07 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Jun 2009 09:02:07 -0500 Subject: [rspec-users] Textmate Bundle focussed test In-Reply-To: References: Message-ID: <57c63afe0906110702h7edc1f50vc337c8cb9bf65268@mail.gmail.com> On Thu, Jun 11, 2009 at 4:49 AM, John van Dijk wrote: > When running a focussed (single) example in textmate and have no > description like this: > > it { should do_something } > > I get not the desired effect :) > > Is there a way to get this to work? The mechanism for running focused examples relies on the name of the example. When you use this format, the name is not known until after the example is run. So, at least for the moment, no. David > (When running all examples this is no problem and works fine) > > regards, j. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Thu Jun 11 12:36:49 2009 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 11 Jun 2009 12:36:49 -0400 Subject: [rspec-users] Mock and Stub objects In-Reply-To: <57c63afe0906110636vd0e75a6oc43642dbb31e9040@mail.gmail.com> References: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> <29526f4662fa39f1da04186918701984@ruby-forum.com> <46E063A1-C6AA-4D01-AEF8-C83F5460C800@mattwynne.net> <4f319adc94f989870fe60f6a7e59bf05@ruby-forum.com> <57c63afe0906110636vd0e75a6oc43642dbb31e9040@mail.gmail.com> Message-ID: <1fb4df0906110936k311b882evd6a083bddb4b3822@mail.gmail.com> (NOTE: This reply is no longer really for Amit's benefit any more. What David said made perfect sense as an answer to the original question. Now I'm just spinning off into theory.) ((But David -- if the repetition of this whole argument On Thu, Jun 11, 2009 at 9:36 AM, David Chelimsky wrote: > > Steve wrote in his reply earlier in this thread that we don't want out > controller specs failing because the model is broken. But it's not > just when the model breaks. It's when the model *changes*. True. Though if I wanted to play Devil's Advocate, I could make a case that from the point of view of the controller, it's the same thing. "What? The Widget wants WHAT now? Hey, I know all about widgets, and this widget's not doing what I expect any more. Must be something wrong with it." (Of course, that exact attitude points to a lot of what's wrong in human relationships, not just OO ones. >8-> So I wouldn't defend that case rigorously. Still -- it's a problem that can be exacerbated by the sort of static expectation mocks play into.) > That fails, so we add "validates_presence_of :date" to the model and > then the spec passes. Success! Except now the valid attributes case in > the controller spec fails because we've changed the meaning of valid > for this model. So you have to go back and change this and every other > example that creates a Widget without a date. Yep. But isn't the difference just a matter of timing? If you just added a new requirement to Widgets, the controller *needs* to change before you hit production or it's going to break in real-world use. You'll eventually have to go back and change every mock, and _then_ change every example anyway. If you don't, then the mocks no longer represent the true expectation of a Widget and your controller's behavior is no longer correct from the widget's POV. You end up with specs that pass when the application wouldn't. As a matter of practicality, I think I would *prefer* the controller spec to fail right away so that I don't forget to update my mocks later on. Yes, I *should* have integration tests that would catch this, so I ought to be safe if I'm doing other things right; but if the controller spec will have to change sooner or later, I'd rather it bugged me to change it sooner. As I see it, the cost of violating DRY and repeating the expectations of a Widget in a number of mocks, which then have to be maintained separately, is *usually* higher than the cost of referring to the actual model, with slower test runs and less specific failure pinpointing. I don't see earlier spec repair as a cost at all, given that those specs will have to change anyway. There may be cases where this would pay off to me, but the typical highly coupled Rails model/controller relationship isn't it. In practice I only use mocks these days to take the place of outside interfaces or bigger, more conceptually distinct subapplications. > [ . . . ] Really, I think > that's what we should all be striving for. Not so much "should I use > mocks or not," but "when should I choose to use them?" And here... Here you made me really pause and think. Enough to make it a separate message. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Thu Jun 11 12:50:53 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Thu, 11 Jun 2009 18:50:53 +0200 Subject: [rspec-users] Fixtures are not loaded while running controller spec Message-ID: <2441782714143923ffbad86f88b18ddd@ruby-forum.com> Hi, I am running controller spec and it gives me result as 0 examples, 0 failures. I checked into the database and i saw that fixtures are not loaded. Following are the details of my controller file. require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') def valid_bb_post_attributes { :body => "test description", :title => "test" } end describe BbPostsController do context "test" do fixtures :bb_posts, :users @user = User.find_by_login("amit") if @user it "should create post" do post = create_post post.should be_valid end end end My bb_posts.ml file contains bb_post1: id: 1 body: body_description title: test bb_post2: id: 2 body: aasasaskajs title: wwwww Similarly my users.yml contains amit: id: 6 login: amit email: amit at test.com kiran: id : 7 login: kiran email: kiran at test.com I dont know what is wrong. Please suggest :-) -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Jun 11 12:56:48 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Jun 2009 11:56:48 -0500 Subject: [rspec-users] Mock and Stub objects In-Reply-To: <1fb4df0906110936k311b882evd6a083bddb4b3822@mail.gmail.com> References: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> <29526f4662fa39f1da04186918701984@ruby-forum.com> <46E063A1-C6AA-4D01-AEF8-C83F5460C800@mattwynne.net> <4f319adc94f989870fe60f6a7e59bf05@ruby-forum.com> <57c63afe0906110636vd0e75a6oc43642dbb31e9040@mail.gmail.com> <1fb4df0906110936k311b882evd6a083bddb4b3822@mail.gmail.com> Message-ID: <57c63afe0906110956m779b55b1m5827cffa53ce7a97@mail.gmail.com> On Thu, Jun 11, 2009 at 11:36 AM, Stephen Eley wrote: > (NOTE: This reply is no longer really for Amit's benefit any more. > What David said made perfect sense as an answer to the original > question. ?Now I'm just spinning off into theory.) > > ((But David -- if the repetition of this whole argument > > On Thu, Jun 11, 2009 at 9:36 AM, David Chelimsky wrote: >> >> Steve wrote in his reply earlier in this thread that we don't want out >> controller specs failing because the model is broken. But it's not >> just when the model breaks. It's when the model *changes*. > > True. ?Though if I wanted to play Devil's Advocate, I could make a > case that from the point of view of the controller, it's the same > thing. ?"What? ?The Widget wants WHAT now? ?Hey, I know all about > widgets, and this widget's not doing what I expect any more. ?Must be > something wrong with it." > > (Of course, that exact attitude points to a lot of what's wrong in > human relationships, not just OO ones. ?>8-> ?So I wouldn't defend > that case rigorously. ?Still -- it's a problem that can be exacerbated > by the sort of static expectation mocks play into.) > > >> That fails, so we add "validates_presence_of :date" to the model and >> then the spec passes. Success! Except now the valid attributes case in >> the controller spec fails because we've changed the meaning of valid >> for this model. So you have to go back and change this and every other >> example that creates a Widget without a date. > > Yep. ?But isn't the difference just a matter of timing? ?If you just > added a new requirement to Widgets, the controller *needs* to change > before you hit production or it's going to break in real-world use. This may be true in some cases, but generally with validations the controller passes the params straight through to the model without caring about them in any way. In those cases, where the controller is only interacting with methods that are part of AR::Base, you're not really risking a validation change effecting the controller's behaviour. > You'll eventually have to go back and change every mock, and _then_ > change every example anyway. ?If you don't, then the mocks no longer > represent the true expectation of a Widget and your controller's > behavior is no longer correct from the widget's POV. ?You end up with > specs that pass when the application wouldn't. I think you're generalizing here, which is what I was driving at with my point about knowing when to use stubs/mocks and when not to. As I mentioned above, these changes need not always propagate up to the controller or its specs. I would agree with you that there is additional risk in cases where the changes to the model actually do require changes to the controller. Though I mitigate that risk by working with Cucumber first, which catches those sorts of mis-alignments a bit later than if I wasn't using stubs/mocks, but certainly before those changes make it to production. At the moment, one of my projects does not use Cucumber. We're using RSpec for both higher level and lower level specs. In this case, the level of use of stubs/mocks is far lower than in other projects I've worked on. > As a matter of practicality, I think I would *prefer* the controller > spec to fail right away so that I don't forget to update my mocks > later on. ?Yes, I *should* have integration tests that would catch > this, so I ought to be safe if I'm doing other things right; but if > the controller spec will have to change sooner or later, I'd rather it > bugged me to change it sooner. I can appreciate that, though it's not how I operate. > As I see it, the cost of violating DRY and repeating the expectations > of a Widget in a number of mocks, which then have to be maintained > separately, is *usually* higher than the cost of referring to the > actual model, with slower test runs and less specific failure > pinpointing. I run the specs after every change (using autospec). For this to work effectively, the specs need to run fast. This is one of the benefits, in my view, of having two separate tools for dealing at different views of the code (i.e. RSpec and Cucumber). > ?I don't see earlier spec repair as a cost at all, given > that those specs will have to change anyway. ?There may be cases where > this would pay off to me, but the typical highly coupled Rails > model/controller relationship isn't it. ?In practice I only use mocks > these days to take the place of outside interfaces or bigger, more > conceptually distinct subapplications. > > >> [ . . . ] ? Really, I think >> that's what we should all be striving for. Not so much "should I use >> mocks or not," but "when should I choose to use them?" > > And here... ?Here you made me really pause and think. > > Enough to make it a separate message. Looking forward to it. Cheers, David > > > > -- > Have Fun, > ? Steve Eley (sfeley at gmail.com) > ? ESCAPE POD - The Science Fiction Podcast Magazine > ? http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jun 11 12:58:51 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Jun 2009 11:58:51 -0500 Subject: [rspec-users] Fixtures are not loaded while running controller spec In-Reply-To: <2441782714143923ffbad86f88b18ddd@ruby-forum.com> References: <2441782714143923ffbad86f88b18ddd@ruby-forum.com> Message-ID: <57c63afe0906110958h353c878v64cc1a7629af6f51@mail.gmail.com> On Thu, Jun 11, 2009 at 11:50 AM, Amit Kulkarni wrote: > Hi, > > ? I am running controller spec and it gives me result as 0 examples, 0 > failures. > > ? I checked into the database and i saw that fixtures are not loaded. > > ? Following are the details of my controller file. > > > ? require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') > def valid_bb_post_attributes > ?{ > ? ?:body => "test description", > ? ?:title => "test" > ?} > end > describe BbPostsController do > ?context "test" do > ? ?fixtures :bb_posts, :users > ? ?@user = User.find_by_login("amit") > ? ?if @user > ? ? ?it "should create post" do > ? ? ? ?post = create_post > ? ? ? ?post.should be_valid > ? ? ?end > ? ?end > ?end > > My bb_posts.ml file contains > > bb_post1: > ?id: 1 > ?body: body_description > ?title: test > > bb_post2: > ?id: 2 > ?body: aasasaskajs > ?title: wwwww > > Similarly my users.yml contains > > amit: > ?id: 6 > ?login: amit > ?email: amit at test.com > > kiran: > ?id : 7 > ?login: kiran > ?email: kiran at test.com > > > I dont know what is wrong. > Please suggest :-) Make sure that the fixtures are in the same place that is declared in spec/spec_helper.rb. From sfeley at gmail.com Thu Jun 11 14:48:30 2009 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 11 Jun 2009 14:48:30 -0400 Subject: [rspec-users] The problem with learning RSpec Message-ID: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> So... In the recent five-hundred-and-forty-seventh iteration of the "What's the point of mocks?" discussion on this list, David Chelimsky ended a message with: > [ . . . ] Really, I think > that's what we should all be striving for. Not so much "should I use > mocks or not," but "when should I choose to use them?" And here... Here you made me really pause and think. David: Now that you're a Pragmatic author -- have you read Andy's _Pragmatic Thinking and Learning?_ Damn good book. The most valuable part of it to me was in the first couple of chapters, which laid out the Dreyfus model of skill acquisition. Having learned about it a few months ago, I'm starting to see it everywhere now. I don't intend to rehash the whole theory, but it basically says that the development of a skill (_any_ skill) follows a predictable pattern: 1. Novice (needs clear checklists or recipes; not ready for theory or problem-solving) 2. Advanced Beginner (can solve typical problems and alter the recipe within parameters) 3. Competent (understands the theory behind the recipes and can act creatively) 4. Proficient (acts on principles rather than recipes; using the skill is nearly automatic) 5. Expert (defines and innovates the field; works on intuition rather than rules) >From reading a fair amount on TDD/BDD -- including the Rspec Book -- I think there's widespread consensus that learning TDD/BDD is a totally separate skill from programming itself. One can be an expert programmer with decades of experience, but still be at zero when it comes to writing and using tests. (Or even an "anti-learner," hostile to the concept itself.) My thesis in this message is that there is a hurdle built into learning the skill of TDD/BDD with RSpec: that there's a steep curve somewhere in the early part of stage 2 -- "Advanced Beginner" -- that makes it more difficult than it ought to be to ascend to competence. The hurdle is that some easy things are easy, but other easy things are very complicated. Not just hard to do, but hard to *learn.* Hard to understand why stuff works. The tasks where the curve begins can be identified by following the high-level trends of conversations on this list. Usually it's on Rails. Models are easy enough; heck, models are fun. But then we try to do controllers, and... *Boom.* Brick wall. You can run the generator, but... What is it doing? How do you change it? Let's say I'm a novice to Rails, too: what the hell *is* that routing spec? That last sentence is the sharpest way I can think to phrase the problem. "What the hell *is* that spec?" Rails is easy to start rolling with for the default use cases, but moderately hard to _understand_ when you're ready to do more complex things. Its nuances are scattered in a lot of places, and some of the connections are invisible. RSpec on Rails, even in the default cases, exposes more of those nuances and *requires* you to understand them. ActiveRecord stands on its own, so models are fine (and views are mostly just tedious) but you can't even begin to understand that generated controller spec until you understand Rails and all of its nuances better. And if you're trying to learn both at once? And you don't want to go deeper into your Rails code until your specs pass? ...Learning deadlock. The failure to understand one keeps you from making progress with the other. In the ideal case the specs would help to teach you Rails, but in practice it doesn't work that way. They specs are too opaque without Rails knowledge. When I set out to consciously learn this stuff, I was determined to really learn it. I didn't want to type any code I couldn't understand. So I ran the RSpec scaffold in a 'dummy' app and used it only as a reference to build my own by hand. The first controller spec I tried was for a nested resource with parent and child objects. (Bad choice perhaps.) It took me almost two days to write that first full spec with all the mocks and stubs, and get it to pass on every action. I was on contract and even to me that felt hard to justify. And then I had to deal with authentication and filters, and then I felt the pain *again.* I'm a stubborn ass, so I plodded through. Eventually I even figured out what I was doing. (I think.) But I believe I have seen people run into this curve and view it as a brick wall. Many give up, sometimes concluding that RSpec is beyond them -- after all, everyone says it's "easy," so if they can't write a controller spec quickly or see the immediate value of this stuff, they must be too dumb for it. It isn't just Rails either. That's the most common entry point, and controllers seem to be the most common wall. But I hit a wall again when I needed to write an adapter for a complex SOAP interface, building some abstractions on top of soap4r. "Where do I start?" was quite hard for me. I fished around for blog posts and examples to give me some precedent. Eventually I figured out a reasonably efficient way to mock out the SOAP responses without building a whole fake server, and I think I'm better for the exercise. But as soon as I got beyond "this is all my code, so I understand it," I hit that curve again. ...This is a real problem. It's not entirely the fault of RSpec (in which I include RSpec-Rails) as a framework. Some of it's built into the ideology: some types of systems really are hard to specify or interact with, and we don't acknowledge that enough. Or we say "If it's painful to specify you're doing it wrong." Not always true, and a dangerous statement for a novice who's only feeling the sorts of pain everyone feels when they first begin exercising. Some of it's built into Rails and "Rails-like" MVC frameworks This is off the topic here, but I can't shake the feeling that if DHH had had RSpec from the very start and applied some of its philosophies faithfully, Rails would be different in some fundamental ways. Instead, some things are coupled in ways that require RSpec-Rails to jump through some weird hoops. It all works, but it isn't all _simple._ And beginners can't grok beyond simple. Some of it's the fault of the community. The problems I see here are subtle and certainly not malignant. This list, for instance, is excellent for its purpose -- it has probably the highest signal-to-noise ratio of any active technical list I follow, and everyone's eager to help at every level. I've never seen anyone sniped at for asking beginner questions. That's great. But the questions and the answers are both coming from such a broad range of skill levels, and sometimes that makes for a disconnect that's tough for learning. That's what I saw in the quote above that triggered this weird polemic from me. In the Dreyfus model, there's no question that many people here would be classed as Expert -- almost by definition in David's or Aslak's case. Me, I see myself on the level of "mid-to-high Competent, struggling toward Proficient." Whether that's accurate or not, I'd be the wrong person to say. Studies show that most incompetent people are very bad at gauging their incompetence, and I might be one of them. Studies also show that Experts are generally not good at teaching Novices, because they no longer _think_ in terms of rules and recipes. Making an Expert follow a recipe is terribly frustrating and a waste of everyone's time. OTOH telling Novice "use your own judgment" is even more frustrating -- and may result in the loss of that Novice. The Novice doesn't _have_ his or her own judgment yet. When we say things like, "I think that's what we should be striving for -- not 'should I use mocks or not,' but 'when should I choose to use them?'" ...That problem is, if we buy into that Dreyfus hierarchy, that is a harmful statement to deliver to an audience that's broadly distributed along the skill curve. The question of "When should I use X?" is an appropriate question for someone at Competent or Proficient levels. But it would be very challenging for most Advanced Beginners to suggest an answer, and a Novice wouldn't be able to answer it at all. (As for Experts: they probably don't even need to think about it. They just know.) We need more awareness of this. It's not a bad thing, and I think there are probably more benefits in having a skill-level-distributed list like this than to set up some sort of "beginner's" or "learner's" list or anything. (For one thing, most programmers who'd benefit would have too much ego to join it.) We just need to recognize -- and I include myself, as *I* spun off the theory tangent in that last thread -- that a Novice question needs a Novice or Advanced Beginner answer, and that saying "It's really more complicated than that" isn't helpful to certain classes of question. Community-wise: I also think we need better learning resources. The RSpec Book is great. Followed faithfully, I have a hunch it can bring an Advanced Beginner up to Competent with remarkable efficiency. I think it could work as well for *some* Novices. But not all. It depends on their thinking patterns, and whether they need or want to be grounded in theory before they get going with the recipes. The Mastermind puzzle is a good starting exercise, but there's too much explanation going on before the rest of the practical reference begins. (Again, for some people. This was _my_ impression. For others it might be just right.) The RSpec.info site is...problematic. It's quirky in its information structure, and I've gotten lost sometimes clicking around to find something I *knew* was there. I don't feel comfortable pointing people to it as a start-from-zero starting point. The explanations are clear and up-to-date, but it's hard to find a handhold. The Peepcode videos worked better for me, though they were a bit too long for my ADD-driven brain. At one point I was going to write a "Getting Started With RSpec" sort of primer. It was going to be informed by my own growth curve, and truly start with "Step by step, okay, just do this." No generators, write the code by hand, but get actual specs working quickly in actual projects. Of course, my "do this" would be somewhat different from David's -- I've been vocal enough about doing a lot of my tests a different way -- so I felt a bit awkward about breaking from orthodoxy when I don't feel like an expert myself. But I felt bold. I started it, got a little distracted and overplanned the demo app (a wiki to host the primer itself, but I wanted some new sorts of features) and it's languishing. This thread makes me wonder if I should put a little more foreground time into it. Not the stupid wiki, but the document. I'm rambling now, and I've spent *way* too much of my workday on this message, so I'll just summarize: * Some easy things are complicated in RSpec; * Incomplete understanding of RSpec and a framework being spec'ed can create learning deadlock; * Novices need different answers than competent practitioners; * The community as a whole should be aware and respectful of the growth curve difficulty. If anyone had the patience to read this far, any thoughts? Am I identifying real issues, or am I just full of hot air? -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From sfeley at gmail.com Thu Jun 11 15:00:05 2009 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 11 Jun 2009 15:00:05 -0400 Subject: [rspec-users] Mock and Stub objects In-Reply-To: <57c63afe0906110956m779b55b1m5827cffa53ce7a97@mail.gmail.com> References: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> <29526f4662fa39f1da04186918701984@ruby-forum.com> <46E063A1-C6AA-4D01-AEF8-C83F5460C800@mattwynne.net> <4f319adc94f989870fe60f6a7e59bf05@ruby-forum.com> <57c63afe0906110636vd0e75a6oc43642dbb31e9040@mail.gmail.com> <1fb4df0906110936k311b882evd6a083bddb4b3822@mail.gmail.com> <57c63afe0906110956m779b55b1m5827cffa53ce7a97@mail.gmail.com> Message-ID: <1fb4df0906111200u544d1b77s2ee30dad2349792a@mail.gmail.com> On Thu, Jun 11, 2009 at 12:56 PM, David Chelimsky wrote: > > This may be true in some cases, but generally with validations the > controller passes the params straight through to the model without > caring about them in any way. In those cases, where the controller is > only interacting with methods that are part of AR::Base, you're not > really risking a validation change effecting the controller's > behaviour. This is a good point. I think I got a little too zoomed in on the example. (In which that wasn't entirely clear, as it did focus on specific attributes being passed.) I stand corrected, thank you. > I run the specs after every change (using autospec). For this to work > effectively, the specs need to run fast. This is one of the benefits, > in my view, of having two separate tools for dealing at different > views of the code (i.e. RSpec and Cucumber). And it's why the active side project I really *am* spending time on right now is a smarter, more human-efficient replacement for Autospec. >8-> But enough of that until I can actually show something for it. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From rick.denatale at gmail.com Thu Jun 11 17:53:26 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 11 Jun 2009 17:53:26 -0400 Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> References: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> Message-ID: On Thu, Jun 11, 2009 at 2:48 PM, Stephen Eley wrote: > So... ?In the recent five-hundred-and-forty-seventh iteration of the > "What's the point of mocks?" discussion on this list, David Chelimsky > ended a message with: > >> [ . . . ] ? Really, I think >> that's what we should all be striving for. Not so much "should I use >> mocks or not," but "when should I choose to use them?" > > And here... ?Here you made me really pause and think. > > David: Now that you're a Pragmatic author -- have you read Andy's > _Pragmatic Thinking and Learning?_ ?Damn good book. ?The most valuable > part of it to me was in the first couple of chapters, which laid out > the Dreyfus model of skill acquisition. ?Having learned about it a few > months ago, I'm starting to see it everywhere now. ?I don't intend to > rehash the whole theory, but it basically says that the development of > a skill (_any_ skill) follows a predictable pattern: > > 1. Novice (needs clear checklists or recipes; not ready for theory or > problem-solving) > 2. Advanced Beginner (can solve typical problems and alter the recipe > within parameters) > 3. Competent (understands the theory behind the recipes and can act creatively) > 4. Proficient (acts on principles rather than recipes; using the skill > is nearly automatic) > 5. Expert (defines and innovates the field; works on intuition rather > than rules) And look at the chart in the section "Is a Ruby Code-base Hard to Understand?" in the article which Martin Fowler just published today http://martinfowler.com/articles/rubyAtThoughtWorks.html It shows a curve of the usage of metaprogramming in Ruby as the experience of the programmer progresses, along with annotations about what the thoughts about the technique during the leaning progression. The progression goes: Attitude Usage Scary and bad low Scary and good at the high end of the sensible range Obvious and good high in the "over usage" range Obvious and bad at the high end of the sensible range The real key to mastery is gaining experience by making mistakes and learning not only techniques, but the trade-offs in when and when not to use them. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From pat.maddox at gmail.com Thu Jun 11 20:09:57 2009 From: pat.maddox at gmail.com (Pat Maddox) Date: Thu, 11 Jun 2009 17:09:57 -0700 Subject: [rspec-users] Fixtures are not loaded while running controller spec In-Reply-To: <2441782714143923ffbad86f88b18ddd@ruby-forum.com> References: <2441782714143923ffbad86f88b18ddd@ruby-forum.com> Message-ID: <2c7e61990906111709v1fb63f59h87547a7934811ca2@mail.gmail.com> On Thu, Jun 11, 2009 at 9:50 AM, Amit Kulkarni wrote: > describe BbPostsController do > ?context "test" do > ? ?fixtures :bb_posts, :users > ? ?@user = User.find_by_login("amit") > ? ?if @user > ? ? ?it "should create post" do > ? ? ? ?post = create_post > ? ? ? ?post.should be_valid > ? ? ?end > ? ?end > ?end Why do you have that if there? That's gotta be screwing you up. So the way Rails tests work, the fixtures don't get loaded until an example is run. In your code, you're trying to find a user that probably doesn't exist due to there being no fixtures loaded yet. So why are you doing that find and subsequent if? Try changing it to: describe BbPostsController do context "test" do fixtures :bb_posts, :users it "should create post" do User.find_by_login("amit").should_not be_nil post = create_post post.should be_valid end end end (that's an odd spec but let's try to get your fixtures loading first :) Pat From powertoaster at hotmail.com Thu Jun 11 23:36:28 2009 From: powertoaster at hotmail.com (powertoaster) Date: Thu, 11 Jun 2009 20:36:28 -0700 (PDT) Subject: [rspec-users] I am having a problem testing a date in a rails view Message-ID: <23992350.post@talk.nabble.com> I see June 13, 2009 on my index page when running in development. I get this 2. is not true. require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe "/timesheets/index.html.erb" do include TimesheetsHelper before(:each) do assigns[:timesheets] = [ stub_model(Timesheets, :tsdate => Date.parse('2009-6-13'), :off => false, :vacation => 9.99, :holiday => 9.99, :closed => false, :comment => "value for comment", :admin_comment => "value for admin_comment", :approved => false ), stub_model(Timesheets, :tsdate => Date.parse('2009-6-13'), :off => false, :vacation => 9.99, :holiday => 9.99, :closed => false, :comment => "value for comment", :admin_comment => "value for admin_comment", :approved => false ) ] end it "renders a list of timesheets" do render response.should have_tag("tr>td", "2009-06-13".to_s, 2) <++++++++ This where it fails +++++> response.should have_tag("tr>td", false.to_s, 2) response.should have_tag("tr>td", 9.99.to_s, 2) response.should have_tag("tr>td", 9.99.to_s, 2) response.should have_tag("tr>td", false.to_s, 2) response.should have_tag("tr>td", "value for comment".to_s, 2) response.should have_tag("tr>td", "value for admin_comment".to_s, 2) response.should have_tag("tr>td", false.to_s, 2) end end -- View this message in context: http://www.nabble.com/I-am-having-a-problem-testing-a-date-in-a-rails-view-tp23992350p23992350.html Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Fri Jun 12 01:39:15 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 12 Jun 2009 00:39:15 -0500 Subject: [rspec-users] I am having a problem testing a date in a rails view In-Reply-To: <23992350.post@talk.nabble.com> References: <23992350.post@talk.nabble.com> Message-ID: <57c63afe0906112239h52d66873t71e1fc7a679f0d95@mail.gmail.com> On Thu, Jun 11, 2009 at 10:36 PM, powertoaster wrote: > > I see June 13, 2009 on my index page when running in development. > > I get this > 2. > is not true. This is not an rspec failure message. What other gems do you have at play? Also, what versions of rspec, rspec-rails, ruby, rails, OS, etc? http://wiki.github.com/dchelimsky/rspec/get-in-touch > > require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') > > describe "/timesheets/index.html.erb" do > ?include TimesheetsHelper > > ?before(:each) do > ? ?assigns[:timesheets] = [ > ? ? ? ? ? ?stub_model(Timesheets, > ? ? ? ? ? ? ? ? ? ? ? :tsdate => Date.parse('2009-6-13'), > ? ? ? ? ? ? ? ? ? ? ? :off => false, > ? ? ? ? ? ? ? ? ? ? ? :vacation => 9.99, > ? ? ? ? ? ? ? ? ? ? ? :holiday => 9.99, > ? ? ? ? ? ? ? ? ? ? ? :closed => false, > ? ? ? ? ? ? ? ? ? ? ? :comment => "value for comment", > ? ? ? ? ? ? ? ? ? ? ? :admin_comment => "value for admin_comment", > ? ? ? ? ? ? ? ? ? ? ? :approved => false > ? ? ? ? ? ?), > ? ? ? ? ? ?stub_model(Timesheets, > ? ? ? ? ? ? ? ? ? ? ? :tsdate => Date.parse('2009-6-13'), > ? ? ? ? ? ? ? ? ? ? ? :off => false, > ? ? ? ? ? ? ? ? ? ? ? :vacation => 9.99, > ? ? ? ? ? ? ? ? ? ? ? :holiday => 9.99, > ? ? ? ? ? ? ? ? ? ? ? :closed => false, > ? ? ? ? ? ? ? ? ? ? ? :comment => "value for comment", > ? ? ? ? ? ? ? ? ? ? ? :admin_comment => "value for admin_comment", > ? ? ? ? ? ? ? ? ? ? ? :approved => false > ? ? ? ? ? ?) > ? ?] > ?end > > ?it "renders a list of timesheets" do > ? ?render > ? ?response.should have_tag("tr>td", "2009-06-13".to_s, 2) <++++++++ This > where it fails +++++> > ? ?response.should have_tag("tr>td", false.to_s, 2) > ? ?response.should have_tag("tr>td", 9.99.to_s, 2) > ? ?response.should have_tag("tr>td", 9.99.to_s, 2) > ? ?response.should have_tag("tr>td", false.to_s, 2) > ? ?response.should have_tag("tr>td", "value for comment".to_s, 2) > ? ?response.should have_tag("tr>td", "value for admin_comment".to_s, 2) > ? ?response.should have_tag("tr>td", false.to_s, 2) > ?end > end > > -- > View this message in context: http://www.nabble.com/I-am-having-a-problem-testing-a-date-in-a-rails-view-tp23992350p23992350.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Fri Jun 12 02:10:19 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Fri, 12 Jun 2009 08:10:19 +0200 Subject: [rspec-users] Fixtures are not loaded while running controller spec In-Reply-To: <57c63afe0906110958h353c878v64cc1a7629af6f51@mail.gmail.com> References: <2441782714143923ffbad86f88b18ddd@ruby-forum.com> <57c63afe0906110958h353c878v64cc1a7629af6f51@mail.gmail.com> Message-ID: David Chelimsky wrote: > On Thu, Jun 11, 2009 at 11:50 AM, Amit Kulkarni > wrote: >> ? require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') >> ? ?if @user >> ?id: 1 >> amit: >> I dont know what is wrong. >> Please suggest :-) > > Make sure that the fixtures are in the same place that is declared in > spec/spec_helper.rb. My fixtures are under spec/fixtures directory. Earlier it were working fine.But suddenly i dont know what went wrong. Also i checked that if i comment fixtures line then the specs are running fine. Again when i uncomment the fixtures line then it is not working and fixtures are not getting loaded. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jun 12 02:33:58 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Fri, 12 Jun 2009 08:33:58 +0200 Subject: [rspec-users] Fixtures are not loaded while running controller spec In-Reply-To: <2c7e61990906111709v1fb63f59h87547a7934811ca2@mail.gmail.com> References: <2441782714143923ffbad86f88b18ddd@ruby-forum.com> <2c7e61990906111709v1fb63f59h87547a7934811ca2@mail.gmail.com> Message-ID: > describe BbPostsController do > context "test" do > fixtures :bb_posts, :users > it "should create post" do > User.find_by_login("amit").should_not be_nil > post = create_post > post.should be_valid > end > end > end > > (that's an odd spec but let's try to get your fixtures loading first :) > > Pat Thanks a lot Pat.It worked. And fixtures were also loaded successfully. -- Posted via http://www.ruby-forum.com/. From Jarmo.P at gmail.com Fri Jun 12 02:59:30 2009 From: Jarmo.P at gmail.com (Jarmo Pertman) Date: Thu, 11 Jun 2009 23:59:30 -0700 (PDT) Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> Message-ID: <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> Do you have any files, which might be changed during your failing tests? Some temporary files or whatsoever? If that's the case, then autotest thinks that you have made some changes already and tries to run again. Solution would be to put that file into ignore list for autotest. On Jun 10, 6:28?am, Alexandre Da silva wrote: > sorry my self reply... but I forgot to mention that I am running Ubuntu > 8.10 ruby 1.8.7.xx > -- > Posted viahttp://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From Lee.Longmore at googlemail.com Fri Jun 12 03:34:41 2009 From: Lee.Longmore at googlemail.com (Lee) Date: Fri, 12 Jun 2009 00:34:41 -0700 (PDT) Subject: [rspec-users] Can I set params in before[:each] block? Message-ID: <9f033689-6ec7-4529-b6b2-92f4e161dd87@j9g2000prh.googlegroups.com> In my controller's create method, I have: @sub_context = @context.create_sub_context(params[:context][:name]) If I do not specify params in the "post :create" call in my controller spec then I get the following error for each example: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] So I see that it is trying to access :name when :context is nil which can be avoided if I ensure each post :create includes a params for [:context][:name] e.g. post :create, :context => {"name" => "Seniors"} I am wondering if there is a way to avoid having to specify params in each and every example by adding some code to a before[:each] block? For example, the params are redundant in some examples e.g. it "should save the context" do @context.should_receive(:save) post :create, :context => {"name" => "Seniors"} end Thanks. From matt at mattwynne.net Fri Jun 12 04:43:00 2009 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 12 Jun 2009 09:43:00 +0100 Subject: [rspec-users] Can I set params in before[:each] block? In-Reply-To: <9f033689-6ec7-4529-b6b2-92f4e161dd87@j9g2000prh.googlegroups.com> References: <9f033689-6ec7-4529-b6b2-92f4e161dd87@j9g2000prh.googlegroups.com> Message-ID: <7B6873B8-EDDA-4C8E-8744-78E36A760059@mattwynne.net> On 12 Jun 2009, at 08:34, Lee wrote: > In my controller's create method, I have: > > @sub_context = @context.create_sub_context(params[:context][:name]) > > If I do not specify params in the "post :create" call in my controller > spec then I get the following error for each example: > > You have a nil object when you didn't expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[] > > So I see that it is trying to access :name when :context is nil which > can be avoided if I ensure each post :create includes a params for > [:context][:name] e.g. > > post :create, :context => {"name" => "Seniors"} > > I am wondering if there is a way to avoid having to specify params in > each and every example by adding some code to a before[:each] block? > For example, the params are redundant in some examples e.g. > > it "should save the context" do > @context.should_receive(:save) > post :create, :context => {"name" => "Seniors"} > end > > Thanks. There are several ways of doing this. The pattern I tend to us is to create a method that does the post, and contains default parameters which you can override if you want to. describe "when the context has a name" def do_post(params = {}) post :create, (:context => {"name" => "Seniors"}).merge(params) end it "should save the context" do @context.should_receive(:save) do_post end end Make sense? Matt Wynne http://beta.songkick.com http://blog.mattwynne.net From lists at ruby-forum.com Fri Jun 12 05:46:41 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Fri, 12 Jun 2009 11:46:41 +0200 Subject: [rspec-users] Mock and Stub objects In-Reply-To: <1fb4df0906111200u544d1b77s2ee30dad2349792a@mail.gmail.com> References: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> <29526f4662fa39f1da04186918701984@ruby-forum.com> <46E063A1-C6AA-4D01-AEF8-C83F5460C800@mattwynne.net> <4f319adc94f989870fe60f6a7e59bf05@ruby-forum.com> <57c63afe0906110636vd0e75a6oc43642dbb31e9040@mail.gmail.com> <1fb4df0906110936k311b882evd6a083bddb4b3822@mail.gmail.com> <57c63afe0906110956m779b55b1m5827cffa53ce7a97@mail.gmail.com> <1fb4df0906111200u544d1b77s2ee30dad2349792a@mail.gmail.com> Message-ID: <573c067e105d12c6974eb5fc9fcfe203@ruby-forum.com> Even if we are using mocks and if our models are changed then also we need to change our spec. Same for if we don't use mocks. So same question i am asking Are mocks really useful? Also When to use if at all we want to use? I searched on net regarding the same but till now no success :-) Also i had started writing controller specs without using mocks just to see how it works?Will it be ok? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jun 12 06:35:01 2009 From: lists at ruby-forum.com (Ninad Pol) Date: Fri, 12 Jun 2009 12:35:01 +0200 Subject: [rspec-users] Problem while generating rspec model in Rails Project Message-ID: <6b6d18e516aac6bebcaa83dbf3222173@ruby-forum.com> Hi, I am new to testing and Rspec. I have one rails project created on my machine. In this project under \app\models i have a file called "client.rb" which has been already created. Now i want to generate spec file for this model for which i am using command: ruby script/generate rspec_model Client Now with this command along with spec file, a file called "client.rb" will also be generated under \app\models. But in my case since the file "client.rb" is already present,with above command i am getting following message: --------------------------------------------------- >ruby script/generate rspec_model Client The name 'Client' is either already used in your application or reserved by Ru by on Rails. Please choose an alternative and run this generator again. Suggestions: customer node guest ---------------------------------------------------- Platform and Version details: Windows xp-professional Ruby 1.8.6 Rails 2.3.2 Gem 1.3.1 ---------------------------------------------------- I have also attached console snapshot for same. I haven't found any help related to this.Ideally in such cases it should ask for the message regarding "whether you want to overwrite file client.rb ? " So can anybody please help me out regarding this issue. whether this is related to version problem or what else earliest? Attachments: http://www.ruby-forum.com/attachment/3812/rspec_model_generation.JPG -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jun 12 07:42:16 2009 From: lists at ruby-forum.com (Alexandre Da Silva) Date: Fri, 12 Jun 2009 13:42:16 +0200 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> Message-ID: <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> Jarmo Pertman wrote: > Do you have any files, which might be changed during your failing > tests? Some temporary files or whatsoever? If that's the case, then > autotest thinks that you have made some changes already and tries to > run again. Solution would be to put that file into ignore list for > autotest. No... all was working some days ago. in fact the same issue occurs with a new fresh project. Here is my test rails blogapp cd blogapp script/generate rspec script/generate rspec_scaffold posts title:string body:text rake db:migrate autospec This will cause error because posts is pluralized... so my autospec loops forever. all my applications are issuing the same behavior. I am with latest rspec and rspec-rails gems (1.2.6 I mean) when I back to my computer, I will provide a list of all my installed gems. -- Posted via http://www.ruby-forum.com/. From zuperinfinite at gmail.com Fri Jun 12 09:59:03 2009 From: zuperinfinite at gmail.com (Bart Zonneveld) Date: Fri, 12 Jun 2009 15:59:03 +0200 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> Message-ID: <8D54256F-282C-440B-9767-E1BD11AAC0B6@gmail.com> On 12 jun 2009, at 13:42, Alexandre Da Silva wrote: > Jarmo Pertman wrote: >> Do you have any files, which might be changed during your failing >> tests? Some temporary files or whatsoever? If that's the case, then >> autotest thinks that you have made some changes already and tries to >> run again. Solution would be to put that file into ignore list for >> autotest. > > No... all was working some days ago. I have the same issue. Whether a red rspec or cucumber file, autotest goes beserk. Using the latest and greatest gems, on a fresh rails app. gr, bartz From mauricio.linhares at gmail.com Fri Jun 12 10:02:44 2009 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Fri, 12 Jun 2009 11:02:44 -0300 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <8D54256F-282C-440B-9767-E1BD11AAC0B6@gmail.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> <8D54256F-282C-440B-9767-E1BD11AAC0B6@gmail.com> Message-ID: Same for me. - Maur?cio Linhares http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr On Fri, Jun 12, 2009 at 10:59 AM, Bart Zonneveld wrote: > > On 12 jun 2009, at 13:42, Alexandre Da Silva wrote: > >> Jarmo Pertman wrote: >>> >>> Do you have any files, which might be changed during your failing >>> tests? Some temporary files or whatsoever? If that's the case, then >>> autotest thinks that you have made some changes already and tries to >>> run again. Solution would be to put that file into ignore list for >>> autotest. >> >> No... all was working some days ago. > > I have the same issue. Whether a red rspec or cucumber file, autotest goes > beserk. > Using the latest and greatest gems, on a fresh rails app. > > gr, > bartz > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 12 10:13:06 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 12 Jun 2009 09:13:06 -0500 Subject: [rspec-users] Problem while generating rspec model in Rails Project In-Reply-To: <6b6d18e516aac6bebcaa83dbf3222173@ruby-forum.com> References: <6b6d18e516aac6bebcaa83dbf3222173@ruby-forum.com> Message-ID: <57c63afe0906120713s668371a5ta0fde3035282b4aa@mail.gmail.com> On Fri, Jun 12, 2009 at 5:35 AM, Ninad Pol wrote: > > Hi, > > I am new to testing and Rspec. I have one rails project created on my > machine. > In this project under \app\models i have a file called "client.rb" which > has been already created. Now i want to generate spec file for this > model for which i am using command: > > ruby script/generate rspec_model Client > > Now with this command along with spec file, a file called "client.rb" > will also be generated under \app\models. But in my case since the file > "client.rb" is already present,with above command i am getting following > message: > > --------------------------------------------------- >>ruby script/generate rspec_model Client > > The name 'Client' is either already used in your application or reserved > by Ru > by on Rails. > Please choose an alternative and run this generator again. > > Suggestions: > > customer > node > guest > > ---------------------------------------------------- > Platform and Version details: > > Windows xp-professional > Ruby 1.8.6 > Rails 2.3.2 > Gem 1.3.1 > ---------------------------------------------------- > I have also attached console snapshot for same. > > I haven't found any help related to this.Ideally in such cases it should > ask for the message regarding "whether you want to overwrite file > client.rb ? " > > So can anybody please help me out regarding this issue. whether this is > related to version problem or what else earliest? I'm not sure where this message is coming from but it's not coming from rspec. Have you tried generating with the rails generator? ruby script/generate model Client Does that give you the same error? > > Attachments: > http://www.ruby-forum.com/attachment/3812/rspec_model_generation.JPG From lists at ruby-forum.com Fri Jun 12 10:15:53 2009 From: lists at ruby-forum.com (Alexandre Da Silva) Date: Fri, 12 Jun 2009 16:15:53 +0200 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <8D54256F-282C-440B-9767-E1BD11AAC0B6@gmail.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> <8D54256F-282C-440B-9767-E1BD11AAC0B6@gmail.com> Message-ID: <2b1688de1bb19525ddc93c521b4832de@ruby-forum.com> Bart Zonneveld wrote: > On 12 jun 2009, at 13:42, Alexandre Da Silva wrote: > >> Jarmo Pertman wrote: >>> Do you have any files, which might be changed during your failing >>> tests? Some temporary files or whatsoever? If that's the case, then >>> autotest thinks that you have made some changes already and tries to >>> run again. Solution would be to put that file into ignore list for >>> autotest. >> >> No... all was working some days ago. > > I have the same issue. Whether a red rspec or cucumber file, autotest > goes beserk. > Using the latest and greatest gems, on a fresh rails app. > > gr, > bartz it seems that many people are getting the same, at least for me and all developers from my two teams. yesterday I realise that when I have green results, then I modify my controller files, than rspec does not auto restart the tests. does anyone else having the same behavior? att, Alexandre -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Jun 12 10:20:19 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 12 Jun 2009 09:20:19 -0500 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> Message-ID: <57c63afe0906120720p5a32c281md7fee50650be5d9e@mail.gmail.com> On Fri, Jun 12, 2009 at 6:42 AM, Alexandre Da Silva wrote: > Jarmo Pertman wrote: >> Do you have any files, which might be changed during your failing >> tests? Some temporary files or whatsoever? If that's the case, then >> autotest thinks that you have made some changes already and tries to >> run again. Solution would be to put that file into ignore list for >> autotest. > > No... all was working some days ago. > in fact the same issue occurs with a new fresh project. Here is my test > > rails blogapp > cd blogapp > script/generate rspec > script/generate rspec_scaffold posts title:string body:text > rake db:migrate > autospec I just copied this all into a shell and the specs ran only once and stopped, as expected. rspec-1.2.6 rspec-rails-1.2.6 ZenTest-4.1.1 Mac OS 10.5.7 ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] Anything different in your environment? Also, I tried this with and without some autotest exceptions set up in my ~/.autotest file, and it worked correctly in either case. > > > This will cause error because posts is pluralized... so my autospec > loops forever. > all my applications are issuing the same behavior. > > I am with latest rspec and rspec-rails gems (1.2.6 I mean) > when I back to my computer, I will provide a list of all my installed > gems. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Fri Jun 12 10:36:32 2009 From: ben at benmabey.com (Ben Mabey) Date: Fri, 12 Jun 2009 08:36:32 -0600 Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> References: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> Message-ID: <4A3267F0.5080809@benmabey.com> > I'm rambling now, and I've spent *way* too much of my workday on this > message, so I'll just summarize: > > * Some easy things are complicated in RSpec; > * Incomplete understanding of RSpec and a framework being spec'ed can > create learning deadlock; > * Novices need different answers than competent practitioners; > * The community as a whole should be aware and respectful of the > growth curve difficulty. > > If anyone had the patience to read this far, any thoughts? Am I > identifying real issues, or am I just full of hot air? > > > Hi Stephen, I did in fact read your entire message, but I'm running out of time so I'm afraid I can't reply with the thoughtful response that it deserves. Here is my brief gut reaction.. I totally agree about your observation WRT the Dreyfus model. I've thought about how how it relates to TDD/BDD in the past and have made similar conclusions. I think you are spot on about an expert not being able to really answer a novice's question very well.. because they are suffering from the "curse of knowledge" and it is hard to remember what it was like without all that knowledge. In general though I don't know if I really see all of this as a problem specific to RSpec. The problem is that many people coming to RSpec are not just RSpec novices but are in fact TDD novices (and Rails, and Ruby novices too boot at times as well!). TDD, like you said, is a skill apart from programming and is really separate from learning the mechanics of RSpec. A well practiced TDDer without much Ruby experience is in a much better position to use RSpec effectively than an experienced Ruby dev with no TDD experience. So if the real problem is that people don't know TDD/BDD I think outside of the RSpec community there are a lot of resources to draw on. There are great TDD books in addition to lists dedicated to TDD, presentations on TDD, etc... Perhaps one step would be to link to these resources? I also agree with Rick in that it just takes experience to learn this stuff since the answers to questions are so context specific. Anyways, I gotta run, but I those were some of the thoughts I had. Thanks, Ben From dchelimsky at gmail.com Fri Jun 12 10:38:14 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 12 Jun 2009 09:38:14 -0500 Subject: [rspec-users] Mock and Stub objects In-Reply-To: <573c067e105d12c6974eb5fc9fcfe203@ruby-forum.com> References: <57c63afe0906101056p1ad87614rab1392b03280113e@mail.gmail.com> <29526f4662fa39f1da04186918701984@ruby-forum.com> <46E063A1-C6AA-4D01-AEF8-C83F5460C800@mattwynne.net> <4f319adc94f989870fe60f6a7e59bf05@ruby-forum.com> <57c63afe0906110636vd0e75a6oc43642dbb31e9040@mail.gmail.com> <1fb4df0906110936k311b882evd6a083bddb4b3822@mail.gmail.com> <57c63afe0906110956m779b55b1m5827cffa53ce7a97@mail.gmail.com> <1fb4df0906111200u544d1b77s2ee30dad2349792a@mail.gmail.com> <573c067e105d12c6974eb5fc9fcfe203@ruby-forum.com> Message-ID: <57c63afe0906120738h4b8b53adr1abae5d59cf7a64b@mail.gmail.com> On Fri, Jun 12, 2009 at 4:46 AM, Amit Kulkarni wrote: > Even if we are using mocks and if our models are changed then also we > need to change our spec. > Same for if we don't use mocks. This is true in some cases, but not in many of the common cases. Here's an example: describe WidgetsController do describe "POST create" do context "with valid attributes" do WidgetsController.stub(create!).and_return(true) post :create response.should redirect_to(widgets_path) end context "with invalid attributes" do WidgetsController.stub(create!).and_raise(ActiveRecord::RecordInvalid(mock_model(Widget))) post :create response.should render_template('new') end end end These two examples will never have to change due to a change in model validation rules. The only reason they'd ever have to change would be if you wanted to make a change the controller itself and how it handles the create() action. In this case we're using stubs, not mocks, but they are serving the purpose of isolating change. > So same question i am asking Are mocks really useful? > Also When to use if at all we want to use? > I searched on net regarding the same but till now no success :-) Amit - you don't have to search the net. Steve, Matt and I have all taken valuable time to try to explain this to you, and Matt even posted some very useful links for you. From this thread, the RSpec book, and those links, you've got enough information in front of you to start answering these questions for yourself. Please take some time to read some of this stuff. If you have any specific questions about any of that reading material, please feel free to ask them. Cheers, David > > Also i had started writing controller specs without using mocks just to > see how it works?Will it be ok? You'll be fine if you don't use mocks. I'd be fine if I didn't use mocks. I happen to know how and when to use them so I like to use them. Cheers, David > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From powertoaster at hotmail.com Fri Jun 12 12:19:16 2009 From: powertoaster at hotmail.com (powertoaster) Date: Fri, 12 Jun 2009 09:19:16 -0700 (PDT) Subject: [rspec-users] I am having a problem testing a date in a rails view In-Reply-To: <57c63afe0906112239h52d66873t71e1fc7a679f0d95@mail.gmail.com> References: <23992350.post@talk.nabble.com> <57c63afe0906112239h52d66873t71e1fc7a679f0d95@mail.gmail.com> Message-ID: <24002045.post@talk.nabble.com> This is not an rspec failure message. What other gems do you have at play? Also, what versions of rspec, rspec-rails, ruby, rails, OS, etc? http://wiki.github.com/dchelimsky/rspec/get-in-touch Rails 2.3.2 Ruby 1.8 Rspec 1.2.6 calendar_date_select 1.15 (I am not using this on the index page) validates_date_time plugin in the model (agilewebdevelopment.com/plugins/validates_date_time) Running on windows using RubyMine 1.1. I am using the default index.html.erb_spec.rb file generated from the rspec-scaffold generator but added the fields for the tsdate since the generator ignored that field for all of the view specs. It is in the model stuff but none of the view specs. I assumed that it did not like the date datatype in views. In my index page I do use a custom date formatter timesheets.tsdate.to_s(:timesheet) which I have defined in an initializers time_formats.rb file. -- View this message in context: http://www.nabble.com/I-am-having-a-problem-testing-a-date-in-a-rails-view-tp23992350p24002045.html Sent from the rspec-users mailing list archive at Nabble.com. From sfeley at gmail.com Fri Jun 12 12:41:41 2009 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 12 Jun 2009 12:41:41 -0400 Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <4A3267F0.5080809@benmabey.com> References: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> <4A3267F0.5080809@benmabey.com> Message-ID: <1fb4df0906120941p6943b879nff94e8a6c07322b9@mail.gmail.com> Ben and Rick, Thanks very much to both of you for the encouraging responses. Your reply, Ben, came just in time as I was starting to wonder if I had made a complete and irrevocable ass of myself. On Fri, Jun 12, 2009 at 10:36 AM, Ben Mabey wrote: > In general though I don't know if I > really see all of this as a problem specific to RSpec. ?The problem is that > many people coming to RSpec are not just RSpec novices but are in fact TDD > novices (and Rails, and Ruby novices too boot at times as well!). FWIW, I agree totally. In fact I re-read my message last night, and I want to retract one of my statements for sure: the statement that RSpec makes "some easy things easy, but other easy things very complicated." On deeper thought, I don't believe this is true. RSpec doesn't make anything harder than it already is. There's nothing _wrong_ with RSpec in this sense. I think a more incisive statement would be that with RSpec, some complicated things _feel like they should be easier._ If only because other things feel so easy. And newbies tend to confront those problem areas at a point in the growth curve where the complexity can be misinterpreted as them Just Not Getting It. Some are driven off as a result. You're right about practice. You're right that bringing together too many learning curves at once creates interference patterns that shouldn't be blamed on RSpec. And Rick's reference to Martin Fowler's spiked learning curve -- "this is scary, this is nifty, WHOOPS I overdid it, this is okay in its place" -- is an excellent point. But I don't think it's totally out-of-bounds to frame it as an "RSpec problem," even if it isn't RSpec's fault. The thing is... Well... There are *opportunities* here. If RSpec -- along with its tools and resources and culture -- was a little better at some of this stuff, how much easier would it be to learn *everything else?* How many of us learned BDD at the same time we learned programming? ...Show of hands? Anyone? The only developers who could make that claim would have to be pretty fresh out of the pond. If that does apply to anyone reading this, please speak up -- I'd like to hear your thoughts on how you're doing. How many of us used TDD or BDD out of the gate when we learned Rails or Ruby? This is plausible, but I get the sense it's uncommon. Most of us don't even think to work on good testing practices until we believe we're getting the rest of the stuff down. I know I didn't. Formal education in programming doesn't help. Not by any evidence to my eyes. I've recently started seeing someone who's majoring in CS at a well-known university, and he said the first class he took on software design was in C. Frickin' *C*. _Then_ they did C++, and then Java, but there was nothing significant about testing. I told him about Cucumber and it made his heart go pitter-patter. The teaching resources for Rails and Ruby don't help. Just about every book makes a *nod* toward testing -- there's always a chapter, they always say "do this constantly" -- but the chapter's inevitably somewhere near the back, after everything else has been introduced. Rails culture is passionate about testing, but most of us don't start to tap into that culture until we're at 'Competent' or above. What if the world were different? What if teaching were different? What if the predominant lessons people used to get started with Rails *did not* start with "Type 'rails', make a scaffold, watch it fly!" but instead started with, "What's the most important single piece of information in your app? Okay, great. Write a spec like this. Now open up this file in /app/models.. [...] Your spec passed, you're cooking! Now let's spec a view so we can see that information... Now let's spec a controller to bring them together..." (Even better would be to start with Cucumber, which would take up very little extra overhead in that type of tutorial.) You get the gist. What if learning Rails was *all about* learning BDD? Would it make the Rails stuff easier to understand and develop competence faster? I hypothesize that it would. Some things need to be easier in BDD before we can get there. To me that means things need to be easier in RSpec. I believe my tutorial above would be easy enough to do today on the model side, but it's just too cumbersome to write a view or controller spec. You lose that "holy crap look how *fast* this is coming!" vibe which is so invigorating when you're doing something new. We could make that tutorial happen when writing a controller spec takes about as long as writing the controller *code.* There are some mitigators for this -- the Shoulda macros may be great for this now that they work with RSpec -- but even so I think it's probably a little bit of wading into the swamp. I would like to see that world. I'd like to help *make* it. That college guy I'm dating has asked me about learning Rails -- but I'm planning to talk his ass off about Cucumber and RSpec before I agree to help him with code. I'm hoping he'll be my experiment to test my hypothesis, and I'll get a better sense of just how easy or hard it is to learn agile Web development if BDD happens at the ground floor. Given time, I think the patterns facilitated by RSpec could *completely* revolutionize the way software happens everywhere, *if* the next generation of developers come to learn it first and not as an "add-on." And that's why I'm picking on RSpec. I can't think of any other technology in a better position to make this happen, with only some moderate shifts of emphasis in both the tools and the culture. Does anyone else think that'd be pretty cool? -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From Lee.Longmore at googlemail.com Sat Jun 13 02:43:05 2009 From: Lee.Longmore at googlemail.com (Lee) Date: Fri, 12 Jun 2009 23:43:05 -0700 (PDT) Subject: [rspec-users] Can I set params in before[:each] block? In-Reply-To: <7B6873B8-EDDA-4C8E-8744-78E36A760059@mattwynne.net> References: <9f033689-6ec7-4529-b6b2-92f4e161dd87@j9g2000prh.googlegroups.com> <7B6873B8-EDDA-4C8E-8744-78E36A760059@mattwynne.net> Message-ID: Makes perfect sense. Thanks for the tip Matt! On 12 June, 09:43, Matt Wynne wrote: > On 12 Jun 2009, at 08:34, Lee wrote: > > > > > In my controller's create method, I have: > > > @sub_context = @context.create_sub_context(params[:context][:name]) > > > If I do not specify params in the "post :create" call in my controller > > spec then I get the following error for each example: > > > You have a nil object when you didn't expect it! > > You might have expected an instance of ActiveRecord::Base. > > The error occurred while evaluating nil.[] > > > So I see that it is trying to access :name when :context is nil which > > can be avoided if I ensure each post :create includes a params for > > [:context][:name] e.g. > > > post :create, :context => {"name" => "Seniors"} > > > I am wondering if there is a way to avoid having to specify params in > > each and every example by adding some code to a before[:each] block? > > For example, the params are redundant in some examples e.g. > > > ? ?it "should save the context" do > > ? ? ?@context.should_receive(:save) > > ? ? ?post :create, :context => {"name" => "Seniors"} > > ? ?end > > > Thanks. > > There are several ways of doing this. The pattern I tend to us is to ? > create a method that does the post, and contains default parameters ? > which you can override if you want to. > > describe "when the context has a name" > ? ?def do_post(params = {}) > ? ? ?post :create, (:context => {"name" => "Seniors"}).merge(params) > ? ?end > > ? ?it "should save the context" do > ? ? ?@context.should_receive(:save) > ? ? ?do_post > ? ?end > end > > Make sense? > > Matt Wynnehttp://beta.songkick.comhttp://blog.mattwynne.net > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From rjharmon0316 at yahoo.com Sat Jun 13 11:42:13 2009 From: rjharmon0316 at yahoo.com (Randy Harmon) Date: Sat, 13 Jun 2009 08:42:13 -0700 Subject: [rspec-users] Can I set params in before[:each] block? In-Reply-To: <7B6873B8-EDDA-4C8E-8744-78E36A760059@mattwynne.net> References: <9f033689-6ec7-4529-b6b2-92f4e161dd87@j9g2000prh.googlegroups.com> <7B6873B8-EDDA-4C8E-8744-78E36A760059@mattwynne.net> Message-ID: <4A33C8D5.7030905@yahoo.com> On 6/12/09 1:43 AM, Matt Wynne wrote back to Lee who said: >> I am wondering if there is a way to avoid having to specify params in >> each and every example by adding some code to a before[:each] block? > There are several ways of doing this. The pattern I tend to us is to > create a method that does the post, and contains default parameters > which you can override if you want to. For contrast, I'll describe the method I prefer. The purpose of this approach is to simplify and homogenize the interface of the "do it" routine. By localizing the params in @instance variables, the raw do_action() is a) easily called by you or the shared example group, b) consistently named - the shared example doesn't have to care what action is being done, and c) overridden with parameters at any level of nested describe()s as you need. describe "something" do before :each do @params = { :default => 'values' } end sub do_action post :create, @params end it_should_behave_like "some shared example group" # shared example calls back to our do_action, by convention describe "something else" do before do @params[:special_for_something_else] = 'setting' # other setup end it "whatever" do @params[:special_for_whatever] = 'value' do_action end end end Randy From ben at benmabey.com Sat Jun 13 11:57:10 2009 From: ben at benmabey.com (Ben Mabey) Date: Sat, 13 Jun 2009 09:57:10 -0600 Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <1fb4df0906120941p6943b879nff94e8a6c07322b9@mail.gmail.com> References: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> <4A3267F0.5080809@benmabey.com> <1fb4df0906120941p6943b879nff94e8a6c07322b9@mail.gmail.com> Message-ID: <4A33CC56.9090406@benmabey.com> Stephen Eley wrote: > Ben and Rick, > > Thanks very much to both of you for the encouraging responses. Your > reply, Ben, came just in time as I was starting to wonder if I had > made a complete and irrevocable ass of myself. > > > On Fri, Jun 12, 2009 at 10:36 AM, Ben Mabey wrote: > >> In general though I don't know if I >> really see all of this as a problem specific to RSpec. The problem is that >> many people coming to RSpec are not just RSpec novices but are in fact TDD >> novices (and Rails, and Ruby novices too boot at times as well!). >> > > FWIW, I agree totally. In fact I re-read my message last night, and I > want to retract one of my statements for sure: the statement that > RSpec makes "some easy things easy, but other easy things very > complicated." > > On deeper thought, I don't believe this is true. RSpec doesn't make > anything harder than it already is. There's nothing _wrong_ with > RSpec in this sense. I think a more incisive statement would be that > with RSpec, some complicated things _feel like they should be easier._ > If only because other things feel so easy. And newbies tend to > confront those problem areas at a point in the growth curve where the > complexity can be misinterpreted as them Just Not Getting It. Some > are driven off as a result. > > You're right about practice. You're right that bringing together too > many learning curves at once creates interference patterns that > shouldn't be blamed on RSpec. And Rick's reference to Martin Fowler's > spiked learning curve -- "this is scary, this is nifty, WHOOPS I > overdid it, this is okay in its place" -- is an excellent point. > > But I don't think it's totally out-of-bounds to frame it as an "RSpec > problem," even if it isn't RSpec's fault. The thing is... Well... > There are *opportunities* here. If RSpec -- along with its tools and > resources and culture -- was a little better at some of this stuff, > how much easier would it be to learn *everything else?* > > How many of us learned BDD at the same time we learned programming? > ...Show of hands? Anyone? The only developers who could make that > claim would have to be pretty fresh out of the pond. If that does > apply to anyone reading this, please speak up -- I'd like to hear your > thoughts on how you're doing. > > How many of us used TDD or BDD out of the gate when we learned Rails > or Ruby? This is plausible, but I get the sense it's uncommon. Most > of us don't even think to work on good testing practices until we > believe we're getting the rest of the stuff down. I know I didn't. > When learning a new technology I generally don't bother with testing let alone TDD (unless I think TDD could help the learning process). It is like spiking and most of the stuff you are creating is throw-away code that won't need to be maintained. There are times, like this, where testing isn't needed IMO. But that isn't really your question is it.. You're wondering what effect teaching good testing practices up front would bring... I've wondered this my self at times (in fact I'm helping prepare an intro rails course now and wresting with this very issue) and it seems like teaching good testing to people who don't even know OO can be like jumping in to the deep end of the pool. > Formal education in programming doesn't help. Not by any evidence to > my eyes. I've recently started seeing someone who's majoring in CS at > a well-known university, and he said the first class he took on > software design was in C. Frickin' *C*. _Then_ they did C++, and > then Java, but there was nothing significant about testing. I told > him about Cucumber and it made his heart go pitter-patter. > I hear this complaint quite often and FWIW it is an untrue stereotype IME. While I was at the university I was taught testing, design patterns, refactoring, Agile methodologies, pair programming, use cases, CI, etc... In fact the first time I heard about TDD was in my first Java class where the professor would TDD all of his work in the lectures (live coding!). We did team projects where we had a CI server setup and we were required to have tests and do pair programming at least part of the time. We also had class projects where different teams would create different components and we had to work out our communication protocols, touch points, and integrate it all. Anyways, I justed wanted to throw that out and say that formal education isn't totally failing like some people claim it is. Only my "Software Engineering" courses taught and encouraged these practices, but I was still taught them. > The teaching resources for Rails and Ruby don't help. Just about > every book makes a *nod* toward testing -- there's always a chapter, > they always say "do this constantly" -- but the chapter's inevitably > somewhere near the back, after everything else has been introduced. > Rails culture is passionate about testing, but most of us don't start > to tap into that culture until we're at 'Competent' or above. > > What if the world were different? What if teaching were different? > What if the predominant lessons people used to get started with Rails > *did not* start with "Type 'rails', make a scaffold, watch it fly!" > but instead started with, "What's the most important single piece of > information in your app? Okay, great. Write a spec like this. Now > open up this file in /app/models.. [...] Your spec passed, you're > cooking! Now let's spec a view so we can see that information... Now > let's spec a controller to bring them together..." > > (Even better would be to start with Cucumber, which would take up very > little extra overhead in that type of tutorial.) > So... From what I have seen people with little experience testing are able to pick up the notion of integration/acceptance testing a lot faster than object level testing. So, I do think having a tutorial drive all the features out with Cucumber or just webrat+some testing framework isn't far fetched at all. Object level examples are a different story though IME... > You get the gist. What if learning Rails was *all about* learning > BDD? Would it make the Rails stuff easier to understand and develop > competence faster? I hypothesize that it would. > > Some things need to be easier in BDD before we can get there. To me > that means things need to be easier in RSpec. I believe my tutorial > above would be easy enough to do today on the model side, but it's > just too cumbersome to write a view or controller spec. You lose that > "holy crap look how *fast* this is coming!" vibe which is so > invigorating when you're doing something new. We could make that > tutorial happen when writing a controller spec takes about as long as > writing the controller *code.* There are some mitigators for this -- > the Shoulda macros may be great for this now that they work with RSpec > -- but even so I think it's probably a little bit of wading into the > swamp. > > I would like to see that world. I'd like to help *make* it. That > college guy I'm dating has asked me about learning Rails -- but I'm > planning to talk his ass off about Cucumber and RSpec before I agree > to help him with code. I'm hoping he'll be my experiment to test my > hypothesis, and I'll get a better sense of just how easy or hard it is > to learn agile Web development if BDD happens at the ground floor. > > Given time, I think the patterns facilitated by RSpec could > *completely* revolutionize the way software happens everywhere, *if* > the next generation of developers come to learn it first and not as an > "add-on." And that's why I'm picking on RSpec. I can't think of any > other technology in a better position to make this happen, with only > some moderate shifts of emphasis in both the tools and the culture. > > Does anyone else think that'd be pretty cool? > Yeah, I think having such resources available would be very cool. The most common complaint I hear in IRC rooms is that there is no good sample rails app that makes good use of RSpec and Cucumber. I think there are some examples out there, but an app built as a tutorial would be much more helpful with the proper git tags and such. I mentioned before that I was helping prepare a rails course. This is with my local Ruby group and we have started on a tutorial app: http://github.com/urug/media_lender/tree/master It thought it would be cool to use this project and BDD all the way through and teach it like that. However, I have other commitments so other people in the group will probably do most of the work without BDD... It is something I would like to revisit someday and provide such an app. Have you started on a tutorial app like this yet? -Ben From lists at ruby-forum.com Sat Jun 13 17:19:19 2009 From: lists at ruby-forum.com (Alexandre Da Silva) Date: Sat, 13 Jun 2009 23:19:19 +0200 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <57c63afe0906120720p5a32c281md7fee50650be5d9e@mail.gmail.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> <57c63afe0906120720p5a32c281md7fee50650be5d9e@mail.gmail.com> Message-ID: David Chelimsky wrote: > On Fri, Jun 12, 2009 at 6:42 AM, Alexandre Da > Silva wrote: >> rails blogapp >> cd blogapp >> script/generate rspec >> script/generate rspec_scaffold posts title:string body:text >> rake db:migrate >> autospec > > I just copied this all into a shell and the specs ran only once and > stopped, as expected. > > rspec-1.2.6 > rspec-rails-1.2.6 > ZenTest-4.1.1 > Mac OS 10.5.7 > ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] > > Anything different in your environment? > > Also, I tried this with and without some autotest exceptions set up in > my ~/.autotest file, and it worked correctly in either case. gems are the same... but I have a lot of other gems. I tested removing all gems and reinstaling one by one... after all gems installed (except remarkable gem) the test above ran as expected. After some inspects I found in different projects two possible sources of the problem. Source one: remarkable gem if you use remarkable, try do uninstall that gem and test if the testes continue looping Source two: localized_dates plugin if you use this plugin try removing it and run the tests again. I mean that localized_dates plugin is not needed in rails 2.3.3 anymore. -- Posted via http://www.ruby-forum.com/. From dgoldie15 at gmail.com Sat Jun 13 17:30:08 2009 From: dgoldie15 at gmail.com (Doug) Date: Sat, 13 Jun 2009 14:30:08 -0700 (PDT) Subject: [rspec-users] removing Mocha; 'spec spec' fails but the specific model file passes Message-ID: <7c6f7cdb-7c4f-43a9-85df-0f1c45dab029@y34g2000prb.googlegroups.com> I happened to mix ryan bates' authentication scaffold with rspec_scaffold on a demo project. and ran into the problem of mixing mock frameworks...ryan uses mocha. So, as a learning experience, I choose to redo ryan's tests without mocha but ran into a strange problem with tests of the User model. With debugging you can see.... If you run just the user_spec.rb file, everything is fine....rspec goes through the User model. However, if you run all the specs, it is somehow still using mocha instead of the User model. How is this possible since I removed the configuration for mocha.? In spec_helper.rb, I commented out the line: # config.mock_with :mocha I also saw a require 'mocha' statement in test_helper that I removed. --------------------------------------------------------------------------------------------------------------------- 11:41 /c/work/quizmaker_demo (questions)$ spec spec ...................................c:/work/quizmaker_demo/spec/models/ user_spec.rb:86 User.authenticate('nonexisting', 'secret').should be_nil (rdb:1) s c:/tools/ruby/ruby186/lib/ruby/gems/1.8/gems/mocha-0.9.5/lib/mocha/ class_method.rb:40 stubbee.__metaclass__.class_eval("def #{method}(*args, &block); mocha.method_missing(:#{method}, *a (rdb:1) c From dchelimsky at gmail.com Sat Jun 13 20:35:13 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 13 Jun 2009 19:35:13 -0500 Subject: [rspec-users] removing Mocha; 'spec spec' fails but the specific model file passes In-Reply-To: <7c6f7cdb-7c4f-43a9-85df-0f1c45dab029@y34g2000prb.googlegroups.com> References: <7c6f7cdb-7c4f-43a9-85df-0f1c45dab029@y34g2000prb.googlegroups.com> Message-ID: <57c63afe0906131735r36184a03g507859d2acf8c3aa@mail.gmail.com> On Sat, Jun 13, 2009 at 4:30 PM, Doug wrote: > I happened to mix ryan bates' authentication scaffold with > rspec_scaffold on a ?demo project. > and ran into the problem of mixing mock frameworks...ryan uses mocha. > > So, as a learning experience, I choose to redo ryan's tests without > mocha but ran into a strange problem with tests of the User model. > > With debugging you can see.... > If you run just the user_spec.rb file, everything is fine....rspec > goes through the User model. > However, if you run all the specs, it is somehow still using mocha > instead of the User model. > > How is this possible since I removed the configuration for mocha.? In rails 2.3, activesupport/lib/active_support/test_case.rb requires mocha. That's the base class for all of the rails test cases, and consequently, rspec example groups as well. > In spec_helper.rb, I commented out the ? line: # > config.mock_with :mocha > I also saw a require 'mocha' statement in test_helper that I removed. > > --------------------------------------------------------------------------------------------------------------------- > > 11:41 /c/work/quizmaker_demo (questions)$ spec spec > ...................................c:/work/quizmaker_demo/spec/models/ > user_spec.rb:86 > User.authenticate('nonexisting', 'secret').should be_nil > (rdb:1) s > c:/tools/ruby/ruby186/lib/ruby/gems/1.8/gems/mocha-0.9.5/lib/mocha/ > class_method.rb:40 > stubbee.__metaclass__.class_eval("def #{method}(*args, &block); > mocha.method_missing(:#{method}, *a > (rdb:1) c > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From 36srinu at gmail.com Mon Jun 15 01:25:41 2009 From: 36srinu at gmail.com (srinu) Date: Sun, 14 Jun 2009 22:25:41 -0700 (PDT) Subject: [rspec-users] Spec for image upload and resizing Message-ID: <179fc737-abca-48ce-a434-ff23cb03ec7b@r31g2000prh.googlegroups.com> Hi, I have a written spec for image upload model using paperclip plug- in. The sample code looks like http://gist.github.com/129954 Testing the upload image just not validation and saving to database, its about the input image has got cropped or not if the input image size exceeds the 600x600px. My input test images are saved in fixtures folder. But every time I run the test images are saving. Is there any way to test my asset model? Thanks in advance Srinivas From lists at ruby-forum.com Mon Jun 15 02:42:53 2009 From: lists at ruby-forum.com (Ninad Pol) Date: Mon, 15 Jun 2009 08:42:53 +0200 Subject: [rspec-users] Problem while generating rspec model in Rails Project In-Reply-To: <57c63afe0906120713s668371a5ta0fde3035282b4aa@mail.gmail.com> References: <6b6d18e516aac6bebcaa83dbf3222173@ruby-forum.com> <57c63afe0906120713s668371a5ta0fde3035282b4aa@mail.gmail.com> Message-ID: Thanks for your reply. No, above command does not give me same error. However it creates only the model file under \app\models and asks whether to overwrite it. But my aim is to create rspec file under \spec\models with the actual model file created under \app\models remaining unchanged. So using the rails generator does not meet my objective and i have to use rspec generator to meet the requirement. Ideal schenario should be that rspec generator creates the desired rspec file under \spec\models and while creating actual model file under \app\models it should ask for whether to overwrite it. I am not getting this schenario may be because i am missing something.It would be really helpful if you could help me out in this. David Chelimsky wrote: > On Fri, Jun 12, 2009 at 5:35 AM, Ninad Pol wrote: >> >> by on Rails. >> >> >> So can anybody please help me out regarding this issue. whether this is >> related to version problem or what else earliest? > > I'm not sure where this message is coming from but it's not coming > from rspec. Have you tried generating with the rails generator? > > ruby script/generate model Client > > Does that give you the same error? -- Posted via http://www.ruby-forum.com/. From zuperinfinite at gmail.com Mon Jun 15 08:18:33 2009 From: zuperinfinite at gmail.com (Bart Zonneveld) Date: Mon, 15 Jun 2009 14:18:33 +0200 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> <57c63afe0906120720p5a32c281md7fee50650be5d9e@mail.gmail.com> Message-ID: <0CBFC0A2-8500-485F-AEDE-5DBF527202A7@gmail.com> On Jun 13, 2009, at 11:19 PM, Alexandre Da Silva wrote: > David Chelimsky wrote: >> On Fri, Jun 12, 2009 at 6:42 AM, Alexandre Da >> Silva wrote: >>> rails blogapp >>> cd blogapp >>> script/generate rspec >>> script/generate rspec_scaffold posts title:string body:text >>> rake db:migrate >>> autospec >> >> I just copied this all into a shell and the specs ran only once and >> stopped, as expected. >> >> rspec-1.2.6 >> rspec-rails-1.2.6 >> ZenTest-4.1.1 >> Mac OS 10.5.7 >> ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] >> >> Anything different in your environment? >> >> Also, I tried this with and without some autotest exceptions set up >> in >> my ~/.autotest file, and it worked correctly in either case. > > gems are the same... but I have a lot of other gems. I tested removing > all gems and reinstaling one by one... after all gems installed > (except > remarkable gem) the test above ran as expected. > > After some inspects I found in different projects two possible sources > of the problem. > > Source one: remarkable gem > if you use remarkable, try do uninstall that gem and test if the > testes > continue looping > > Source two: localized_dates plugin > if you use this plugin try removing it and run the tests again. I mean > that localized_dates plugin is not needed in rails 2.3.3 anymore. I don't have these plugins or gems, but I found out that downgrading ZenTest to version 4.0.0 solved the problem. HTH, bartz From dchelimsky at gmail.com Mon Jun 15 08:34:36 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Jun 2009 07:34:36 -0500 Subject: [rspec-users] Problem while generating rspec model in Rails Project In-Reply-To: References: <6b6d18e516aac6bebcaa83dbf3222173@ruby-forum.com> <57c63afe0906120713s668371a5ta0fde3035282b4aa@mail.gmail.com> Message-ID: <57c63afe0906150534j6f7341a4n7436ff426fdc2687@mail.gmail.com> On Mon, Jun 15, 2009 at 1:42 AM, Ninad Pol wrote: > Thanks for your reply. > > No, above command does not give me same error. However it creates only > the model file under \app\models and asks whether to overwrite it. But > my aim is to create rspec file under \spec\models with the actual model > file created under \app\models remaining unchanged. So using the rails > generator does not meet my objective and i have to use rspec generator > to meet the requirement. I wasn't trying to meet your requirement with this - just trying to narrow down the problem. > Ideal schenario should be that rspec generator creates the desired rspec > file under \spec\models and while creating actual model file under > \app\models it should ask for whether to overwrite it. I am not getting > this schenario may be because i am missing something.It would be really > helpful if you could help me out in this. The rails code that triggers this will always raise this error if the Client constant (in your case) is already defined. This normally doesn't conflict with files in your app because they are not loaded when you run generators. So it seems that something other than app/models/client.rb is getting loaded that defines the Client constant (either a class or a module). Do you have any plugins that define a Client? Or perhaps you've got some extension in the lib directory? > David Chelimsky wrote: >> On Fri, Jun 12, 2009 at 5:35 AM, Ninad Pol wrote: >>> >>> by on Rails. >>> >>> >>> So can anybody please help me out regarding this issue. whether this is >>> related to version problem or what else earliest? >> >> I'm not sure where this message is coming from but it's not coming >> from rspec. Have you tried generating with the rails generator? >> >> ruby script/generate model Client >> >> Does that give you the same error? > > -- > 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 Mon Jun 15 08:36:25 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Jun 2009 07:36:25 -0500 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <0CBFC0A2-8500-485F-AEDE-5DBF527202A7@gmail.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> <57c63afe0906120720p5a32c281md7fee50650be5d9e@mail.gmail.com> <0CBFC0A2-8500-485F-AEDE-5DBF527202A7@gmail.com> Message-ID: <57c63afe0906150536i711e3799k9cc9ca8fdb780d88@mail.gmail.com> On Mon, Jun 15, 2009 at 7:18 AM, Bart Zonneveld wrote: > > On Jun 13, 2009, at 11:19 PM, Alexandre Da Silva wrote: > >> David Chelimsky wrote: >>> >>> On Fri, Jun 12, 2009 at 6:42 AM, Alexandre Da >>> Silva wrote: >>>> >>>> rails blogapp >>>> cd blogapp >>>> script/generate rspec >>>> script/generate rspec_scaffold posts title:string body:text >>>> rake db:migrate >>>> autospec >>> >>> I just copied this all into a shell and the specs ran only once and >>> stopped, as expected. >>> >>> rspec-1.2.6 >>> rspec-rails-1.2.6 >>> ZenTest-4.1.1 >>> Mac OS 10.5.7 >>> ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] >>> >>> Anything different in your environment? >>> >>> Also, I tried this with and without some autotest exceptions set up in >>> my ~/.autotest file, and it worked correctly in either case. >> >> gems are the same... but I have a lot of other gems. I tested removing >> all gems and reinstaling one by one... after all gems installed (except >> remarkable gem) the test above ran as expected. >> >> After some inspects I found in different projects two possible sources >> of the problem. >> >> Source one: remarkable gem >> if you use remarkable, try do uninstall that gem and test if the testes >> continue looping >> >> Source two: localized_dates plugin >> if you use this plugin try removing it and run the tests again. I mean >> that localized_dates plugin is not needed in rails 2.3.3 anymore. > > I don't have these plugins or gems, but I found out that downgrading ZenTest > to version 4.0.0 solved the problem. Did you install the autotest-rails gem per the ZenTest 4.1 release notes? > > HTH, > bartz > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Jun 15 09:04:07 2009 From: lists at ruby-forum.com (Ninad Pol) Date: Mon, 15 Jun 2009 15:04:07 +0200 Subject: [rspec-users] Problem while generating rspec model in Rails Project In-Reply-To: <57c63afe0906150534j6f7341a4n7436ff426fdc2687@mail.gmail.com> References: <6b6d18e516aac6bebcaa83dbf3222173@ruby-forum.com> <57c63afe0906120713s668371a5ta0fde3035282b4aa@mail.gmail.com> <57c63afe0906150534j6f7341a4n7436ff426fdc2687@mail.gmail.com> Message-ID: <9899a026050777dbe6b12120a7abbddd@ruby-forum.com> I think this problem is not related any plugin (that define a client) simply because if i try it with any other ruby file(other than Client.rb) also i am facing same problem.And what do you mean by some extension in the lib directory? David Chelimsky wrote: > On Mon, Jun 15, 2009 at 1:42 AM, Ninad Pol wrote: >> Thanks for your reply. >> >> No, above command does not give me same error. However it creates only >> the model file under \app\models and asks whether to overwrite it. But >> my aim is to create rspec file under \spec\models with the actual model >> file created under \app\models remaining unchanged. So using the rails >> generator does not meet my objective and i have to use rspec generator >> to meet the requirement. > > I wasn't trying to meet your requirement with this - just trying to > narrow down the problem. > >> Ideal schenario should be that rspec generator creates the desired rspec >> file under \spec\models and while creating actual model file under >> \app\models it should ask for whether to overwrite it. I am not getting >> this schenario may be because i am missing something.It would be really >> helpful if you could help me out in this. > > The rails code that triggers this will always raise this error if the > Client constant (in your case) is already defined. This normally > doesn't conflict with files in your app because they are not loaded > when you run generators. So it seems that something other than > app/models/client.rb is getting loaded that defines the Client > constant (either a class or a module). > > Do you have any plugins that define a Client? Or perhaps you've got > some extension in the lib directory? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Jun 15 09:18:40 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Jun 2009 08:18:40 -0500 Subject: [rspec-users] Problem while generating rspec model in Rails Project In-Reply-To: <9899a026050777dbe6b12120a7abbddd@ruby-forum.com> References: <6b6d18e516aac6bebcaa83dbf3222173@ruby-forum.com> <57c63afe0906120713s668371a5ta0fde3035282b4aa@mail.gmail.com> <57c63afe0906150534j6f7341a4n7436ff426fdc2687@mail.gmail.com> <9899a026050777dbe6b12120a7abbddd@ruby-forum.com> Message-ID: <57c63afe0906150618o7feb45e1pa359303de19dcf6@mail.gmail.com> On Mon, Jun 15, 2009 at 8:04 AM, Ninad Pol wrote: > I think this problem is not related any plugin (that define a client) > simply because if i try it with any other ruby file(other than > Client.rb) also i am facing same problem. So if you do this: rails widgets cd widgets script\generate model widget script\generate rspec script\generate rspec_model widget The last command tells you that Widget is already defined? > And what do you mean by some extension in the lib directory? I mean that you have a file in the lib directory in your Rails project that defines a client. I believe that loading the rails env (which happens when you run script\generate) loads the lib directory, so if you have a file in there that defines Client, then you'd run into this problem. > > David Chelimsky wrote: >> On Mon, Jun 15, 2009 at 1:42 AM, Ninad Pol wrote: >>> Thanks for your reply. >>> >>> No, above command does not give me same error. However it creates only >>> the model file under \app\models and asks whether to overwrite it. But >>> my aim is to create rspec file under \spec\models with the actual model >>> file created under \app\models remaining unchanged. So using the rails >>> generator does not meet my objective and i have to use rspec generator >>> to meet the requirement. >> >> I wasn't trying to meet your requirement with this - just trying to >> narrow down the problem. >> >>> Ideal schenario should be that rspec generator creates the desired rspec >>> file under \spec\models and while creating actual model file under >>> \app\models it should ask for whether to overwrite it. I am not getting >>> this schenario may be because i am missing something.It would be really >>> helpful if you could help me out in this. >> >> The rails code that triggers this will always raise this error if the >> Client constant (in your case) is already defined. This normally >> doesn't conflict with files in your app because they are not loaded >> when you run generators. So it seems that something other than >> app/models/client.rb is getting loaded that defines the Client >> constant (either a class or a module). >> >> Do you have any plugins that define a Client? Or perhaps you've got >> some extension in the lib directory? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Mon Jun 15 09:41:38 2009 From: sfeley at gmail.com (Stephen Eley) Date: Mon, 15 Jun 2009 09:41:38 -0400 Subject: [rspec-users] Spec for image upload and resizing In-Reply-To: <179fc737-abca-48ce-a434-ff23cb03ec7b@r31g2000prh.googlegroups.com> References: <179fc737-abca-48ce-a434-ff23cb03ec7b@r31g2000prh.googlegroups.com> Message-ID: <1fb4df0906150641r374b5cccxbc0cacdb349b52f1@mail.gmail.com> On Mon, Jun 15, 2009 at 1:25 AM, srinu<36srinu at gmail.com> wrote: > > ?But every time I run the test images are saving. Is there any way to > test my asset model? Well, it does have to save the processed image *somewhere* or you're not going to have anything to measure. My suggestion would be to override Paperclip's file path with a temporary directory (the 'tempdir' standard library can make one for you easily) in a before(:all) or before(:each), and then delete the temporary directory when you're done. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From scott at railsnewbie.com Mon Jun 15 09:43:12 2009 From: scott at railsnewbie.com (Scott Taylor) Date: Mon, 15 Jun 2009 09:43:12 -0400 Subject: [rspec-users] Spork and Merb and rSpec In-Reply-To: References: Message-ID: <4A364FF0.6030405@railsnewbie.com> Andy Shipman wrote: > When running spork on a merb application, whenever a spec is run I get > the following error from the Spork server. > > /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0.11/lib/merb-core/bootloader.rb:1358: > [BUG] rb_gc_mark(): unknown data type 0x3c(0x2203d0) non object > ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-darwin9] > > Which crashes the Spork server. Have you tried it on 1.8.6? Scott > > Anyone else out there had experience in getting Merb and Spork running > together nicely? > > Andy Shipman > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From zuperinfinite at gmail.com Mon Jun 15 09:56:22 2009 From: zuperinfinite at gmail.com (Bart Zonneveld) Date: Mon, 15 Jun 2009 15:56:22 +0200 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <57c63afe0906150536i711e3799k9cc9ca8fdb780d88@mail.gmail.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> <57c63afe0906120720p5a32c281md7fee50650be5d9e@mail.gmail.com> <0CBFC0A2-8500-485F-AEDE-5DBF527202A7@gmail.com> <57c63afe0906150536i711e3799k9cc9ca8fdb780d88@mail.gmail.com> Message-ID: <7733F66C-5813-47D3-9B0D-95FB8F721E9C@gmail.com> On Jun 15, 2009, at 2:36 PM, David Chelimsky wrote: > On Mon, Jun 15, 2009 at 7:18 AM, Bart Zonneveld > wrote: >> >> On Jun 13, 2009, at 11:19 PM, Alexandre Da Silva wrote: >> >>> David Chelimsky wrote: >>>> >>>> On Fri, Jun 12, 2009 at 6:42 AM, Alexandre Da >>>> Silva wrote: >>>>> >>>>> rails blogapp >>>>> cd blogapp >>>>> script/generate rspec >>>>> script/generate rspec_scaffold posts title:string body:text >>>>> rake db:migrate >>>>> autospec >>>> >>>> I just copied this all into a shell and the specs ran only once and >>>> stopped, as expected. >>>> >>>> rspec-1.2.6 >>>> rspec-rails-1.2.6 >>>> ZenTest-4.1.1 >>>> Mac OS 10.5.7 >>>> ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] >>>> >>>> Anything different in your environment? >>>> >>>> Also, I tried this with and without some autotest exceptions set >>>> up in >>>> my ~/.autotest file, and it worked correctly in either case. >>> >>> gems are the same... but I have a lot of other gems. I tested >>> removing >>> all gems and reinstaling one by one... after all gems installed >>> (except >>> remarkable gem) the test above ran as expected. >>> >>> After some inspects I found in different projects two possible >>> sources >>> of the problem. >>> >>> Source one: remarkable gem >>> if you use remarkable, try do uninstall that gem and test if the >>> testes >>> continue looping >>> >>> Source two: localized_dates plugin >>> if you use this plugin try removing it and run the tests again. I >>> mean >>> that localized_dates plugin is not needed in rails 2.3.3 anymore. >> >> I don't have these plugins or gems, but I found out that >> downgrading ZenTest >> to version 4.0.0 solved the problem. > > Did you install the autotest-rails gem per the ZenTest 4.1 release > notes? Of course not :). I just ran sudo gem update :). Will check, and report back though. gr, bartz From lists at ruby-forum.com Mon Jun 15 10:18:49 2009 From: lists at ruby-forum.com (Carlos A. da silva) Date: Mon, 15 Jun 2009 16:18:49 +0200 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: <57c63afe0906150536i711e3799k9cc9ca8fdb780d88@mail.gmail.com> References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <57c63afe0904061650v473ffeb4g2ae978d1ba00bed2@mail.gmail.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> <57c63afe0906120720p5a32c281md7fee50650be5d9e@mail.gmail.com> <0CBFC0A2-8500-485F-AEDE-5DBF527202A7@gmail.com> <57c63afe0906150536i711e3799k9cc9ca8fdb780d88@mail.gmail.com> Message-ID: David Chelimsky wrote: > On Mon, Jun 15, 2009 at 7:18 AM, Bart Zonneveld > wrote: >>>>> script/generate rspec >>>> Mac OS 10.5.7 >>> >> >> I don't have these plugins or gems, but I found out that downgrading ZenTest >> to version 4.0.0 solved the problem. > > Did you install the autotest-rails gem per the ZenTest 4.1 release > notes? Same issue here.. Installed autotest-rails gem and everything is working fine now. Thanks. Carlos. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Jun 15 10:32:59 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Jun 2009 09:32:59 -0500 Subject: [rspec-users] Autospec Infinite Loop ?? In-Reply-To: References: <80248ec8-a49b-492b-b63f-c5a46cc0e6a3@r33g2000yqn.googlegroups.com> <540e6cab9a9bfcd63526d67d72e5711e@ruby-forum.com> <00d23d04d6958aba373e1979ceba08ee@ruby-forum.com> <39d26454-a1f4-42ed-8d08-33ed10496fb3@i6g2000yqj.googlegroups.com> <967ea10f39707c878dc48489aa8d81c7@ruby-forum.com> <57c63afe0906120720p5a32c281md7fee50650be5d9e@mail.gmail.com> <0CBFC0A2-8500-485F-AEDE-5DBF527202A7@gmail.com> <57c63afe0906150536i711e3799k9cc9ca8fdb780d88@mail.gmail.com> Message-ID: <57c63afe0906150732s6a429de0n5d79cfa764f85729@mail.gmail.com> OK - top posting here so everyone on this thread will see this: If you upgrade to ZenTest 4.1, you must install the autotest-rails gem or you will get unexpected results. http://blog.davidchelimsky.net/2009/06/08/upgrading-to-zentest-410/ Cheers, David On Mon, Jun 15, 2009 at 9:18 AM, Carlos A. da silva wrote: > David Chelimsky wrote: >> On Mon, Jun 15, 2009 at 7:18 AM, Bart Zonneveld >> wrote: >>>>>> script/generate rspec >>>>> Mac OS 10.5.7 >>>> >>> >>> I don't have these plugins or gems, but I found out that downgrading ZenTest >>> to version 4.0.0 solved the problem. >> >> Did you install the autotest-rails gem per the ZenTest 4.1 release >> notes? > > Same issue here.. > > Installed autotest-rails gem and everything is working fine now. > > Thanks. > > Carlos. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From andy at cllearview.com Mon Jun 15 16:11:55 2009 From: andy at cllearview.com (Andy Shipman) Date: Mon, 15 Jun 2009 21:11:55 +0100 Subject: [rspec-users] Spork and Merb and rSpec In-Reply-To: <4A364FF0.6030405@railsnewbie.com> References: <4A364FF0.6030405@railsnewbie.com> Message-ID: On 15 Jun 2009, at 14:43, Scott Taylor wrote: > Andy Shipman wrote: >> When running spork on a merb application, whenever a spec is run I >> get the following error from the Spork server. >> /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0.11/lib/merb-core/ >> bootloader.rb:1358: [BUG] rb_gc_mark(): unknown data type >> 0x3c(0x2203d0) non object >> ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-darwin9] >> >> Which crashes the Spork server. > > Have you tried it on 1.8.6? I have now and it works on 1.8.6. Thanks for the suggestion. > > Scott > >> >> Anyone else out there had experience in getting Merb and Spork >> running together nicely? >> Andy Shipman >> From scott at railsnewbie.com Mon Jun 15 17:01:47 2009 From: scott at railsnewbie.com (Scott Taylor) Date: Mon, 15 Jun 2009 17:01:47 -0400 Subject: [rspec-users] Spork and Merb and rSpec In-Reply-To: References: <4A364FF0.6030405@railsnewbie.com> Message-ID: <5D8C3325-5E86-47CC-95DE-F9387C03B2F0@railsnewbie.com> On Jun 15, 2009, at 4:11 PM, Andy Shipman wrote: > > On 15 Jun 2009, at 14:43, Scott Taylor wrote: > >> Andy Shipman wrote: >>> When running spork on a merb application, whenever a spec is run I >>> get the following error from the Spork server. >>> /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0.11/lib/merb-core/ >>> bootloader.rb:1358: [BUG] rb_gc_mark(): unknown data type >>> 0x3c(0x2203d0) non object >>> ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-darwin9] >>> >>> Which crashes the Spork server. >> >> Have you tried it on 1.8.6? > > I have now and it works on 1.8.6. Thanks for the suggestion. I'd suggest filing a bug on their tracker, wherever it may lie. Scott > > >> >> Scott >> >>> >>> Anyone else out there had experience in getting Merb and Spork >>> running together nicely? >>> Andy Shipman >>> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From 36srinu at gmail.com Tue Jun 16 00:49:21 2009 From: 36srinu at gmail.com (srinu) Date: Mon, 15 Jun 2009 21:49:21 -0700 (PDT) Subject: [rspec-users] Spec for image upload and resizing In-Reply-To: <1fb4df0906150641r374b5cccxbc0cacdb349b52f1@mail.gmail.com> References: <179fc737-abca-48ce-a434-ff23cb03ec7b@r31g2000prh.googlegroups.com> <1fb4df0906150641r374b5cccxbc0cacdb349b52f1@mail.gmail.com> Message-ID: Well, thanks for the reply, as you suggested it is a better way to override the file path. Thanks Srinivas On Jun 15, 6:41?pm, Stephen Eley wrote: > On Mon, Jun 15, 2009 at 1:25 AM, srinu<36sr... at gmail.com> wrote: > > > ?But every time I run the test images are saving. Is there any way to > > test my asset model? > > Well, it does have to save the processed image *somewhere* or you're > not going to have anything to measure. ?My suggestion would be to > override Paperclip's file path with a temporary directory (the > 'tempdir' standard library can make one for you easily) in a > before(:all) or before(:each), and then delete the temporary directory > when you're done. > > -- > Have Fun, > ? ?Steve Eley (sfe... at gmail.com) > ? ?ESCAPE POD - The Science Fiction Podcast Magazine > ? ?http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Tue Jun 16 00:51:21 2009 From: ben at benmabey.com (Ben Mabey) Date: Mon, 15 Jun 2009 22:51:21 -0600 Subject: [rspec-users] Spork and Merb and rSpec In-Reply-To: <5D8C3325-5E86-47CC-95DE-F9387C03B2F0@railsnewbie.com> References: <4A364FF0.6030405@railsnewbie.com> <5D8C3325-5E86-47CC-95DE-F9387C03B2F0@railsnewbie.com> Message-ID: <4A3724C9.6000104@benmabey.com> Scott Taylor wrote: > > On Jun 15, 2009, at 4:11 PM, Andy Shipman wrote: > >> >> On 15 Jun 2009, at 14:43, Scott Taylor wrote: >> >>> Andy Shipman wrote: >>>> When running spork on a merb application, whenever a spec is run I >>>> get the following error from the Spork server. >>>> /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0.11/lib/merb-core/bootloader.rb:1358: >>>> [BUG] rb_gc_mark(): unknown data type 0x3c(0x2203d0) non object >>>> ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-darwin9] >>>> >>>> Which crashes the Spork server. >>> >>> Have you tried it on 1.8.6? >> >> I have now and it works on 1.8.6. Thanks for the suggestion. > > I'd suggest filing a bug on their tracker, wherever it may lie. > > Scott Spork uses github issues. Also, FYI, spork has it's own mailing list: http://groups.google.com/group/sporkgem -Ben From r_j_h_box-sf at yahoo.com Tue Jun 16 16:07:13 2009 From: r_j_h_box-sf at yahoo.com (r_j_h_box-sf at yahoo.com) Date: Tue, 16 Jun 2009 13:07:13 -0700 (PDT) Subject: [rspec-users] Problem verifying routing error In-Reply-To: <4A046AEF.1090307@benmabey.com> References: <49FCAAA6.6040600@yahoo.com> <4A046AEF.1090307@benmabey.com> Message-ID: <187508.72754.qm@web31806.mail.mud.yahoo.com> I finally figured this out. lambda { route_for(:controller => "designs", :action => "create").should == "anything" }.should raise_error( ActionController::RoutingError ) The clue was that I wasn't getting a routing error until I tried to compare route_for() with something. route_for() seems to generate an object that overrides ==(), and at that time it does raise the exception. Now we wrap that comparison in a lambda and assert that the *comparison* should raise the expected routing error. So - great, we can actually test it. But the syntax does leave something to be desired. dchelimsky, can you recommend any alternatives that would be a bit cleaner for testing that a route doesn't exist? Thanks, Randy ----- Original Message ---- > From: Ben Mabey > To: r_j_h_box-sf at yahoo.com; rspec-users > Sent: Friday, May 8, 2009 10:25:03 AM > Subject: Re: [rspec-users] Problem verifying routing error > > Randy Harmon wrote: > > Hi, > > > > When upgrading to rspec/rspec-rails 1.2.6 gem (from 1.1.12), I'm having > > a new problem verifying routes that should not exist. > > > > This is to support something like this in routes.rb: > > > > map.resources :orders do |orders| > > orders.resources :items, :except => [:index,:show] > > end > > > > I used to use lambda {}.should_raise( routing error ), but it stopped > > detecting any raised error. Requesting it through the browser produces > > ActionController::MethodNotAllowed (Only post requests are allowed). But > > that error wasn't detected. > > > > When I skip the lambda, and just ask it to verify that the route does > > exist (which *should* fail), I get the same result for those :except > > actions as for a made-up action name. Seems this must have something to > > do with the change in how route_for delegates back to ActionController's > > routing assertion (sez the backtrace :). > > > > > > NoMethodError in 'ItemsController route generation should NOT map > > #indewfefwex' > > You have a nil object when you didn't expect it! > > You might have expected an instance of Array. > > The error occurred while evaluating nil.first > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:134:in > > `recognized_request_for' > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:49:in > > `assert_recognizes' > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions.rb:54:in > > `clean_backtrace' > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:47:in > > `assert_recognizes' > > ./spec/controllers/thoughts_routing_spec.rb:9: > > > > > > I tried using bypass_rescue in my routing/items_routing_spec.rb file as > > mentioned by the upgrade doc, but it wasn't valid in the "routing" spec > > - worked fine when I moved the file back to spec/controllers/, though. > > Seems like that's not the issue, but I'm mentioning for more completeness. > > > > Any ideas what I should be doing instead, or how I can troubleshoot further? > > > > > Hmm.. yeah, it seems like it might have to do with how the exceptions > are being handled in the newer version of rspec-rials (see > https://rspec.lighthouseapp.com/projects/5645/tickets/85-11818-have-mode-for-rails-error-handling). > > I don't use RSpec to verify my routes very often and have never used it > to verify the non-existence of a route so I'm afraid I don't really have > any ideas... > > Does anyone else have an idea to do this? > > -Ben From dchelimsky at gmail.com Tue Jun 16 16:28:18 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 16 Jun 2009 15:28:18 -0500 Subject: [rspec-users] Problem verifying routing error In-Reply-To: <187508.72754.qm@web31806.mail.mud.yahoo.com> References: <49FCAAA6.6040600@yahoo.com> <4A046AEF.1090307@benmabey.com> <187508.72754.qm@web31806.mail.mud.yahoo.com> Message-ID: <57c63afe0906161328n5db41a0ajc0f4ca43ddb12ef1@mail.gmail.com> On Tue, Jun 16, 2009 at 3:07 PM, wrote: > > I finally figured this out. > > lambda { route_for(:controller => "designs", :action => "create").should == "anything" }.should raise_error( ActionController::RoutingError ) > > The clue was that I wasn't getting a routing error until I tried to compare route_for() with something. ?route_for() seems to generate an object that overrides ==(), and at that time it does raise the exception. ?Now we wrap that comparison in a lambda and assert that the *comparison* should raise the expected routing error. > > So - great, we can actually test it. ?But the syntax does leave something to be desired. ?dchelimsky, can you recommend any alternatives that would be a bit cleaner for testing that a route doesn't exist? > You don't need the .should == "anything" in there. So this is a bit cleaner: lambda { route_for(:controller => "designs", :action => "create") }.should raise_error( ActionController::RoutingError ) Also, since rspec-1.2.5 you can use expect/to: expect { route_for(:controller => "designs", :action => "create") }.to raise_error( ActionController::RoutingError ) You could always kick it old-school: e = nil begin route_for(:controller => "designs", :action => "create") rescue ActionController::RoutingError => e ensure e.should_not be_nil end And you could always wrap this in an new matcher: def be_routable Spec::Matchers.new :be_routable, self do |example| match do |params| e = nil begin example.route_for(params) rescue ActionController::RoutingError => e end !!e end end end {:controller => "designs", :action => "create"}.should_not be_routable In this case you need to wrap the matcher's construction in a method in order to provide access to the scope of the example (which is where route_for lives). Also, I just whipped that up off the top of my head - no idea if it actually works :) HTH, David > Thanks, > > Randy > > > > > ----- Original Message ---- >> From: Ben Mabey >> To: r_j_h_box-sf at yahoo.com; rspec-users >> Sent: Friday, May 8, 2009 10:25:03 AM >> Subject: Re: [rspec-users] Problem verifying routing error >> >> Randy Harmon wrote: >> > Hi, >> > >> > When upgrading to rspec/rspec-rails 1.2.6 gem (from 1.1.12), I'm having >> > a new problem verifying routes that should not exist. >> > >> > This is to support something like this in routes.rb: >> > >> > map.resources :orders do |orders| >> > ? ? orders.resources :items, :except => [:index,:show] >> > end >> > >> > I used to use lambda {}.should_raise( routing error ), but it stopped >> > detecting any raised error. ?Requesting it through the browser produces >> > ActionController::MethodNotAllowed (Only post requests are allowed). But >> > that error wasn't detected. >> > >> > When I skip the lambda, and just ask it to verify that the route does >> > exist (which *should* fail), I get the same result for those :except >> > actions as for a made-up action name. ?Seems this must have something to >> > do with the change in how route_for delegates back to ActionController's >> > routing assertion (sez the backtrace :). >> > >> > >> > NoMethodError in 'ItemsController route generation should NOT map >> > #indewfefwex' >> > You have a nil object when you didn't expect it! >> > You might have expected an instance of Array. >> > The error occurred while evaluating nil.first >> > >> /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:134:in >> > `recognized_request_for' >> > >> /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:49:in >> > `assert_recognizes' >> > >> /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions.rb:54:in >> > `clean_backtrace' >> > >> /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:47:in >> > `assert_recognizes' >> > ./spec/controllers/thoughts_routing_spec.rb:9: >> > >> > >> > I tried using bypass_rescue in my routing/items_routing_spec.rb file as >> > mentioned by the upgrade doc, but it wasn't valid in the "routing" spec >> > - worked fine when I moved the file back to spec/controllers/, though. >> > Seems like that's not the issue, but I'm mentioning for more completeness. >> > >> > Any ideas what I should be doing instead, or how I can troubleshoot further? >> > >> >> >> Hmm.. yeah, it seems like it might have to do with how the exceptions >> are being handled in the newer version of rspec-rials (see >> https://rspec.lighthouseapp.com/projects/5645/tickets/85-11818-have-mode-for-rails-error-handling). >> >> I don't use RSpec to verify my routes very often and have never used it >> to verify the non-existence of a route so I'm afraid I don't really have >> any ideas... >> >> Does anyone else have an idea to do this? >> >> -Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From r_j_h_box-sf at yahoo.com Tue Jun 16 17:14:52 2009 From: r_j_h_box-sf at yahoo.com (r_j_h_box-sf at yahoo.com) Date: Tue, 16 Jun 2009 14:14:52 -0700 (PDT) Subject: [rspec-users] Problem verifying routing error In-Reply-To: <57c63afe0906161328n5db41a0ajc0f4ca43ddb12ef1@mail.gmail.com> References: <49FCAAA6.6040600@yahoo.com> <4A046AEF.1090307@benmabey.com> <187508.72754.qm@web31806.mail.mud.yahoo.com> <57c63afe0906161328n5db41a0ajc0f4ca43ddb12ef1@mail.gmail.com> Message-ID: <55736.1826.qm@web31804.mail.mud.yahoo.com> David, thank you for your reply on this. I really dig the expect { }.to raise_error() syntax!! To clarify: All the things you're claiming match my expectation. Unfortunately, my expectation does not match reality according to my tests. The thing is, route_for([bad stuff]) does not in and of itself raise a routing error. It constructs an object that hasn't yet been compared with == to anything. 23 t = route_for(:controller => "designs", :action => "create") (rdb:1) puts t # According to my tests, the routing error only occurs after route_for()'s result gets compared to something. So lambda { route_for(...) } does not raise error. The following code passes with flying colors, either in lambda or expect {}.to form: t = route_for(:controller => "designs", :action => "create") expect { t == "anything" }.to raise_error( ActionController::RoutingError ) expect { t.should == "anything" }.to raise_error( ActionController::RoutingError ) Any further ideas? Randy ----- Original Message ---- > From: David Chelimsky > To: rspec-users > Sent: Tuesday, June 16, 2009 1:28:18 PM > Subject: Re: [rspec-users] Problem verifying routing error > > On Tue, Jun 16, 2009 at 3:07 PM, wrote: > > > > I finally figured this out. > > > > lambda { route_for(:controller => "designs", :action => "create").should == > "anything" }.should raise_error( ActionController::RoutingError ) > > > > The clue was that I wasn't getting a routing error until I tried to compare > route_for() with something. route_for() seems to generate an object that > overrides ==(), and at that time it does raise the exception. Now we wrap that > comparison in a lambda and assert that the *comparison* should raise the > expected routing error. > > > > So - great, we can actually test it. But the syntax does leave something to > be desired. dchelimsky, can you recommend any alternatives that would be a bit > cleaner for testing that a route doesn't exist? > > > > You don't need the .should == "anything" in there. So this is a bit cleaner: > > lambda { route_for(:controller => "designs", :action => "create") > }.should raise_error( ActionController::RoutingError ) > > Also, since rspec-1.2.5 you can use expect/to: > > expect { route_for(:controller => "designs", :action => "create") > }.to raise_error( ActionController::RoutingError ) > > You could always kick it old-school: > > e = nil > begin > route_for(:controller => "designs", :action => "create") > rescue ActionController::RoutingError => e > ensure > e.should_not be_nil > end > > And you could always wrap this in an new matcher: > > def be_routable > Spec::Matchers.new :be_routable, self do |example| > match do |params| > e = nil > begin > example.route_for(params) > rescue ActionController::RoutingError => e > end > !!e > end > end > end > > {:controller => "designs", :action => "create"}.should_not be_routable > > In this case you need to wrap the matcher's construction in a method > in order to provide access to the scope of the example (which is where > route_for lives). Also, I just whipped that up off the top of my head > - no idea if it actually works :) > > HTH, > David > > > > > > Thanks, > > > > Randy > > > > > > > > > > ----- Original Message ---- > >> From: Ben Mabey > >> To: r_j_h_box-sf at yahoo.com; rspec-users > >> Sent: Friday, May 8, 2009 10:25:03 AM > >> Subject: Re: [rspec-users] Problem verifying routing error > >> > >> Randy Harmon wrote: > >> > Hi, > >> > > >> > When upgrading to rspec/rspec-rails 1.2.6 gem (from 1.1.12), I'm having > >> > a new problem verifying routes that should not exist. > >> > > >> > This is to support something like this in routes.rb: > >> > > >> > map.resources :orders do |orders| > >> > orders.resources :items, :except => [:index,:show] > >> > end > >> > > >> > I used to use lambda {}.should_raise( routing error ), but it stopped > >> > detecting any raised error. Requesting it through the browser produces > >> > ActionController::MethodNotAllowed (Only post requests are allowed). But > >> > that error wasn't detected. > >> > > >> > When I skip the lambda, and just ask it to verify that the route does > >> > exist (which *should* fail), I get the same result for those :except > >> > actions as for a made-up action name. Seems this must have something to > >> > do with the change in how route_for delegates back to ActionController's > >> > routing assertion (sez the backtrace :). > >> > > >> > > >> > NoMethodError in 'ItemsController route generation should NOT map > >> > #indewfefwex' > >> > You have a nil object when you didn't expect it! > >> > You might have expected an instance of Array. > >> > The error occurred while evaluating nil.first > >> > > >> > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:134:in > >> > `recognized_request_for' > >> > > >> > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:49:in > >> > `assert_recognizes' > >> > > >> > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions.rb:54:in > >> > `clean_backtrace' > >> > > >> > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:47:in > >> > `assert_recognizes' > >> > ./spec/controllers/thoughts_routing_spec.rb:9: > >> > > >> > > >> > I tried using bypass_rescue in my routing/items_routing_spec.rb file as > >> > mentioned by the upgrade doc, but it wasn't valid in the "routing" spec > >> > - worked fine when I moved the file back to spec/controllers/, though. > >> > Seems like that's not the issue, but I'm mentioning for more completeness. > >> > > >> > Any ideas what I should be doing instead, or how I can troubleshoot > further? > >> > > >> > >> > >> Hmm.. yeah, it seems like it might have to do with how the exceptions > >> are being handled in the newer version of rspec-rials (see > >> > https://rspec.lighthouseapp.com/projects/5645/tickets/85-11818-have-mode-for-rails-error-handling). > >> > >> I don't use RSpec to verify my routes very often and have never used it > >> to verify the non-existence of a route so I'm afraid I don't really have > >> any ideas... > >> > >> Does anyone else have an idea to do this? > >> > >> -Ben > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From timcharper at gmail.com Tue Jun 16 17:11:26 2009 From: timcharper at gmail.com (Tim Harper) Date: Tue, 16 Jun 2009 15:11:26 -0600 Subject: [rspec-users] Spork and Merb and rSpec In-Reply-To: <4A3724C9.6000104@benmabey.com> References: <4A364FF0.6030405@railsnewbie.com> <5D8C3325-5E86-47CC-95DE-F9387C03B2F0@railsnewbie.com> <4A3724C9.6000104@benmabey.com> Message-ID: I'm interested to hear your experience with Spork and Merb. Right now Spork is doing some hooks in to rails (that are actually kind of aggressive right now) to help make spork work more out of the box - specifically, preventing rails from preloading application models and controllers before the fork occurs. Be sure to run spork -d and look to see which files are being preloaded. Every file listed there will be cached and not reloaded until spork is restarted. Tim On Mon, Jun 15, 2009 at 10:51 PM, Ben Mabey wrote: > Scott Taylor wrote: > >> >> On Jun 15, 2009, at 4:11 PM, Andy Shipman wrote: >> >> >>> On 15 Jun 2009, at 14:43, Scott Taylor wrote: >>> >>> Andy Shipman wrote: >>>> >>>>> When running spork on a merb application, whenever a spec is run I get >>>>> the following error from the Spork server. >>>>> /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0.11/lib/merb-core/bootloader.rb:1358: >>>>> [BUG] rb_gc_mark(): unknown data type 0x3c(0x2203d0) non object >>>>> ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-darwin9] >>>>> >>>>> Which crashes the Spork server. >>>>> >>>> >>>> Have you tried it on 1.8.6? >>>> >>> >>> I have now and it works on 1.8.6. Thanks for the suggestion. >>> >> >> I'd suggest filing a bug on their tracker, wherever it may lie. >> >> Scott >> > > > Spork uses github issues. Also, FYI, spork has it's own mailing list: > http://groups.google.com/group/sporkgem > > -Ben > > _______________________________________________ > 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 timcharper at gmail.com Tue Jun 16 17:11:26 2009 From: timcharper at gmail.com (Tim Harper) Date: Tue, 16 Jun 2009 15:11:26 -0600 Subject: [rspec-users] Spork and Merb and rSpec In-Reply-To: <4A3724C9.6000104@benmabey.com> References: <4A364FF0.6030405@railsnewbie.com> <5D8C3325-5E86-47CC-95DE-F9387C03B2F0@railsnewbie.com> <4A3724C9.6000104@benmabey.com> Message-ID: I'm interested to hear your experience with Spork and Merb. Right now Spork is doing some hooks in to rails (that are actually kind of aggressive right now) to help make spork work more out of the box - specifically, preventing rails from preloading application models and controllers before the fork occurs. Be sure to run spork -d and look to see which files are being preloaded. Every file listed there will be cached and not reloaded until spork is restarted. Tim On Mon, Jun 15, 2009 at 10:51 PM, Ben Mabey wrote: > Scott Taylor wrote: > >> >> On Jun 15, 2009, at 4:11 PM, Andy Shipman wrote: >> >> >>> On 15 Jun 2009, at 14:43, Scott Taylor wrote: >>> >>> Andy Shipman wrote: >>>> >>>>> When running spork on a merb application, whenever a spec is run I get >>>>> the following error from the Spork server. >>>>> /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0.11/lib/merb-core/bootloader.rb:1358: >>>>> [BUG] rb_gc_mark(): unknown data type 0x3c(0x2203d0) non object >>>>> ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-darwin9] >>>>> >>>>> Which crashes the Spork server. >>>>> >>>> >>>> Have you tried it on 1.8.6? >>>> >>> >>> I have now and it works on 1.8.6. Thanks for the suggestion. >>> >> >> I'd suggest filing a bug on their tracker, wherever it may lie. >> >> Scott >> > > > Spork uses github issues. Also, FYI, spork has it's own mailing list: > http://groups.google.com/group/sporkgem > > -Ben > > _______________________________________________ > 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 r_j_h_box-sf at yahoo.com Tue Jun 16 20:23:34 2009 From: r_j_h_box-sf at yahoo.com (r_j_h_box-sf at yahoo.com) Date: Tue, 16 Jun 2009 17:23:34 -0700 (PDT) Subject: [rspec-users] Problem verifying routing error In-Reply-To: <55736.1826.qm@web31804.mail.mud.yahoo.com> References: <49FCAAA6.6040600@yahoo.com> <4A046AEF.1090307@benmabey.com> <187508.72754.qm@web31806.mail.mud.yahoo.com> <57c63afe0906161328n5db41a0ajc0f4ca43ddb12ef1@mail.gmail.com> <55736.1826.qm@web31804.mail.mud.yahoo.com> Message-ID: <123149.78952.qm@web31815.mail.mud.yahoo.com> Here's another interesting symptom. After tracing through the code, I've come to the understanding that the current implementation (delegated to outside rspec, I understand) of route "generation" is not testing generation at all, but rather is using backward-recognition as a proxy. Further, that recognition doesn't correspond to what the real router does recognize. For clarity, here's the background: A resource that requires nesting for new, create; requires no nesting for edit, update, destroy, and has no index or show. > map.resources :designs, :only => [:edit, :update, :destroy] > map.resources :product, :member => { :redraw => :get } do |product| > product.resources :designs, :member => { :set_default => :put }, :except => [ :edit, :update, :destroy, :index, :show ] > end Okay: when I go to /designs/new in the browser, it borks with a RoutingError. That's the way I want it to behave, real-world. Yet, this fails: > expect { route_for(:controller => "designs", :action => "new") == "/designs/new" }.to raise_error( ActionController::RoutingError ) There's no error raised at all here. The following does gripe, but... what it's *really* griping about (in a hidden way) is "bogus path", not about the route_for() params at all. > expect { route_for(:controller => "designs", :action => "new") == "bogus path" }.to raise_error( ActionController::RoutingError ) (so if we replace route_for([bad]) with route_for([good]) == "bogus path", then we still get the routing error. Furthermore, the first one really recognizes the route string (/designs/new), without actually verifying that there is a route in the routing table for it. So I fear that it's not actually testing what I'm asking it to test. Taking it out of the expect {} *does* make it barf, but with evidence that something is just plain confused, not that it's actually testing what we're asking it to test: [wrapping is mine] > The recognized options <{"action"=>"1", "controller"=>"designs"}> > did not match <{"action"=>"show", "id"=>"1", "controller"=>"designs"}>, > difference: <{"action"=>"show", "id"=>"1"}> At the end of the day, what I find is: * Route generation tests are not testing generation at all, but recognition only * They're only testing recognition of ideal cases * Non-existence of routes is currently not testable with rspec I hoped to just assert something on url_for() - that's the practical application, here. Does, or does not, url_for() produce a useful result with specific args? But I see from ActionController::Base how that's not super practical. I sincerely hope that my understanding is wildly mistaken. Sorry if this is a sore spot; I know that this part has been a lot of painful effort so far, far more for others than for myself. I'll end with an expression of deep and sincere appreciation for this great software. Randy ----- Original Message ---- > From: "r_j_h_box-sf at yahoo.com" > To: rspec-users > Sent: Tuesday, June 16, 2009 2:14:52 PM > Subject: Re: [rspec-users] Problem verifying routing error > > > David, thank you for your reply on this. I really dig the expect { }.to > raise_error() syntax!! > > To clarify: All the things you're claiming match my expectation. Unfortunately, > my expectation does not match reality according to my tests. > > The thing is, route_for([bad stuff]) does not in and of itself raise a routing > error. It constructs an object that hasn't yet been compared with == to > anything. > > 23 t = route_for(:controller => "designs", :action => "create") > > (rdb:1) puts t > # > > According to my tests, the routing error only occurs after route_for()'s result > gets compared to something. So lambda { route_for(...) } does not raise error. > > The following code passes with flying colors, either in lambda or expect {}.to > form: > > t = route_for(:controller => "designs", :action => "create") > expect { t == "anything" }.to raise_error( ActionController::RoutingError ) > expect { t.should == "anything" }.to raise_error( > ActionController::RoutingError ) > > Any further ideas? > > Randy > > > > > > ----- Original Message ---- > > From: David Chelimsky > > To: rspec-users > > Sent: Tuesday, June 16, 2009 1:28:18 PM > > Subject: Re: [rspec-users] Problem verifying routing error > > > > On Tue, Jun 16, 2009 at 3:07 PM, wrote: > > > > > > I finally figured this out. > > > > > > lambda { route_for(:controller => "designs", :action => "create").should == > > "anything" }.should raise_error( ActionController::RoutingError ) > > > > > > The clue was that I wasn't getting a routing error until I tried to compare > > route_for() with something. route_for() seems to generate an object that > > overrides ==(), and at that time it does raise the exception. Now we wrap > that > > comparison in a lambda and assert that the *comparison* should raise the > > expected routing error. > > > > > > So - great, we can actually test it. But the syntax does leave something to > > > be desired. dchelimsky, can you recommend any alternatives that would be a > bit > > cleaner for testing that a route doesn't exist? > > > > > > > You don't need the .should == "anything" in there. So this is a bit cleaner: > > > > lambda { route_for(:controller => "designs", :action => "create") > > }.should raise_error( ActionController::RoutingError ) > > > > Also, since rspec-1.2.5 you can use expect/to: > > > > expect { route_for(:controller => "designs", :action => "create") > > }.to raise_error( ActionController::RoutingError ) > > > > You could always kick it old-school: > > > > e = nil > > begin > > route_for(:controller => "designs", :action => "create") > > rescue ActionController::RoutingError => e > > ensure > > e.should_not be_nil > > end > > > > And you could always wrap this in an new matcher: > > > > def be_routable > > Spec::Matchers.new :be_routable, self do |example| > > match do |params| > > e = nil > > begin > > example.route_for(params) > > rescue ActionController::RoutingError => e > > end > > !!e > > end > > end > > end > > > > {:controller => "designs", :action => "create"}.should_not be_routable > > > > In this case you need to wrap the matcher's construction in a method > > in order to provide access to the scope of the example (which is where > > route_for lives). Also, I just whipped that up off the top of my head > > - no idea if it actually works :) > > > > HTH, > > David > > > > > > > > > > > Thanks, > > > > > > Randy > > > > > > > > > > > > > > > ----- Original Message ---- > > >> From: Ben Mabey > > >> To: r_j_h_box-sf at yahoo.com; rspec-users > > >> Sent: Friday, May 8, 2009 10:25:03 AM > > >> Subject: Re: [rspec-users] Problem verifying routing error > > >> > > >> Randy Harmon wrote: > > >> > Hi, > > >> > > > >> > When upgrading to rspec/rspec-rails 1.2.6 gem (from 1.1.12), I'm having > > >> > a new problem verifying routes that should not exist. > > >> > > > >> > This is to support something like this in routes.rb: > > >> > > > >> > map.resources :orders do |orders| > > >> > orders.resources :items, :except => [:index,:show] > > >> > end > > >> > > > >> > I used to use lambda {}.should_raise( routing error ), but it stopped > > >> > detecting any raised error. Requesting it through the browser produces > > >> > ActionController::MethodNotAllowed (Only post requests are allowed). But > > >> > that error wasn't detected. > > >> > > > >> > When I skip the lambda, and just ask it to verify that the route does > > >> > exist (which *should* fail), I get the same result for those :except > > >> > actions as for a made-up action name. Seems this must have something to > > >> > do with the change in how route_for delegates back to ActionController's > > >> > routing assertion (sez the backtrace :). > > >> > > > >> > > > >> > NoMethodError in 'ItemsController route generation should NOT map > > >> > #indewfefwex' > > >> > You have a nil object when you didn't expect it! > > >> > You might have expected an instance of Array. > > >> > The error occurred while evaluating nil.first > > >> > > > >> > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:134:in > > >> > `recognized_request_for' > > >> > > > >> > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:49:in > > >> > `assert_recognizes' > > >> > > > >> > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions.rb:54:in > > >> > `clean_backtrace' > > >> > > > >> > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:47:in > > >> > `assert_recognizes' > > >> > ./spec/controllers/thoughts_routing_spec.rb:9: > > >> > > > >> > > > >> > I tried using bypass_rescue in my routing/items_routing_spec.rb file as > > >> > mentioned by the upgrade doc, but it wasn't valid in the "routing" spec > > >> > - worked fine when I moved the file back to spec/controllers/, though. > > >> > Seems like that's not the issue, but I'm mentioning for more > completeness. > > >> > > > >> > Any ideas what I should be doing instead, or how I can troubleshoot > > further? > > >> > > > >> > > >> > > >> Hmm.. yeah, it seems like it might have to do with how the exceptions > > >> are being handled in the newer version of rspec-rials (see > > >> > > > https://rspec.lighthouseapp.com/projects/5645/tickets/85-11818-have-mode-for-rails-error-handling). > > >> > > >> I don't use RSpec to verify my routes very often and have never used it > > >> to verify the non-existence of a route so I'm afraid I don't really have > > >> any ideas... > > >> > > >> Does anyone else have an idea to do this? > > >> > > >> -Ben > > > > > > _______________________________________________ > > > 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 From dchelimsky at gmail.com Wed Jun 17 11:21:29 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Jun 2009 10:21:29 -0500 Subject: [rspec-users] shared examples sharing methods In-Reply-To: <88fd8ddc0906170814h18ecbd50h86486c1089fb75d@mail.gmail.com> References: <88fd8ddc0906170814h18ecbd50h86486c1089fb75d@mail.gmail.com> Message-ID: <57c63afe0906170821t4258666scd390318884b233@mail.gmail.com> On Wed, Jun 17, 2009 at 10:14 AM, Andrew Premdas wrote: > Please have a look at > http://gist.github.com/131277 > What I'd like to do is create a shared_examples group which I can parametize > a method. So my shared example would perhaps use method named_address=, or > set_named_address and then groups that behave like "Named address" would be > able to override this method so it sets the correct address e.g. the last > billing address Here's the short version: There's been a lot of discussion on this list about parameterizing shared examples. Basically, given the current design it can't happen, and macros are a perfectly good solution to the problem, so there's not much incentive to change the design. I'll try to follow up later with a recommendation about a macro, unless somebody else beats me to it :) Cheers, David > TIA > Andrew > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at mattwynne.net Wed Jun 17 14:19:39 2009 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 17 Jun 2009 19:19:39 +0100 Subject: [rspec-users] shared examples sharing methods In-Reply-To: <57c63afe0906170821t4258666scd390318884b233@mail.gmail.com> References: <88fd8ddc0906170814h18ecbd50h86486c1089fb75d@mail.gmail.com> <57c63afe0906170821t4258666scd390318884b233@mail.gmail.com> Message-ID: On 17 Jun 2009, at 16:21, David Chelimsky wrote: > On Wed, Jun 17, 2009 at 10:14 AM, Andrew Premdas > wrote: >> Please have a look at >> http://gist.github.com/131277 >> What I'd like to do is create a shared_examples group which I can >> parametize >> a method. So my shared example would perhaps use method >> named_address=, or >> set_named_address and then groups that behave like "Named address" >> would be >> able to override this method so it sets the correct address e.g. >> the last >> billing address > > Here's the short version: There's been a lot of discussion on this > list about parameterizing shared examples. Basically, given the > current design it can't happen, and macros are a perfectly good > solution to the problem, so there's not much incentive to change the > design. You can use instance variables to pass values to the shared examples, though, right? cheers, Matt Wynne http://mattwynne.net +447974 430184 From dchelimsky at gmail.com Wed Jun 17 14:28:00 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Jun 2009 13:28:00 -0500 Subject: [rspec-users] shared examples sharing methods In-Reply-To: References: <88fd8ddc0906170814h18ecbd50h86486c1089fb75d@mail.gmail.com> <57c63afe0906170821t4258666scd390318884b233@mail.gmail.com> Message-ID: <57c63afe0906171128u4086d8a6icf25246c3a84ba6@mail.gmail.com> On Wed, Jun 17, 2009 at 1:19 PM, Matt Wynne wrote: > > On 17 Jun 2009, at 16:21, David Chelimsky wrote: > >> On Wed, Jun 17, 2009 at 10:14 AM, Andrew Premdas >> wrote: >>> >>> Please have a look at >>> http://gist.github.com/131277 >>> What I'd like to do is create a shared_examples group which I can >>> parametize >>> a method. So my shared example would perhaps use method named_address=, >>> or >>> set_named_address and then groups that behave like "Named address" would >>> be >>> able to override this method so it sets the correct address e.g. the last >>> billing address >> >> Here's the short version: There's been a lot of discussion on this >> list about parameterizing shared examples. Basically, given the >> current design it can't happen, and macros are a perfectly good >> solution to the problem, so there's not much incentive to change the >> design. > > You can use instance variables to pass values to the shared examples, > though, right? At your own risk, yes, of course :) > > cheers, > Matt Wynne > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dgoldie15 at gmail.com Wed Jun 17 15:29:17 2009 From: dgoldie15 at gmail.com (Doug) Date: Wed, 17 Jun 2009 12:29:17 -0700 (PDT) Subject: [rspec-users] removing Mocha; 'spec spec' fails but the specific model file passes In-Reply-To: <57c63afe0906131735r36184a03g507859d2acf8c3aa@mail.gmail.com> References: <7c6f7cdb-7c4f-43a9-85df-0f1c45dab029@y34g2000prb.googlegroups.com> <57c63afe0906131735r36184a03g507859d2acf8c3aa@mail.gmail.com> Message-ID: ok, I investigated further...and I'm still confused. this is testing a typical authenticate class method...... # login can be either username or email address def self.authenticate(login, pass) user = find_by_username(login) || find_by_email(login) return user if user && user.matching_password?(pass) end the 2 tests that fail only in spec spec....... before :each do @user = User.new end it "should not authenticate bad username" do #@user.attributes = valid_user_attributes @user = User.create!(valid_user_attributes) debugger @find_user = User.authenticate('nonexisting', 'secret') @find_user.should be_nil end it "should not authenticate bad password" do @user.attributes = valid_user_attributes @user.save! User.authenticate('joseph', 'badpassword').should be_nil end When you run the specific spec file, it works correctly, i.e. by executing this class method. When you run spec spec, it seems to mock the method with mocha (never passes through this method!) and returns the fixture object.....which fails the test. What is the correct way to do this? ... without using config.mock_with :mocha, of course thanks On Jun 13, 5:35?pm, David Chelimsky wrote: > On Sat, Jun 13, 2009 at 4:30 PM, Doug wrote: > > I happened to mix ryan bates' authentication scaffold with > > rspec_scaffold on a ?demo project. > > and ran into the problem of mixing mock frameworks...ryan uses mocha. > > > So, as a learning experience, I choose to redo ryan's tests without > > mocha but ran into a strange problem with tests of the User model. > > > With debugging you can see.... > > If you run just the user_spec.rb file, everything is fine....rspec > > goes through the User model. > > However, if you run all the specs, it is somehow still using mocha > > instead of the User model. > > > How is this possible since I removed the configuration for mocha.? > > In rails 2.3, activesupport/lib/active_support/test_case.rb requires > mocha. That's the base class for all of the rails test cases, and > consequently, rspec example groups as well. > > > > > In spec_helper.rb, I commented out the ? line: # > > config.mock_with :mocha > > I also saw a require 'mocha' statement in test_helper that I removed. > > > --------------------------------------------------------------------------------------------------------------------- > > > 11:41 /c/work/quizmaker_demo (questions)$ spec spec > > ...................................c:/work/quizmaker_demo/spec/models/ > > user_spec.rb:86 > > User.authenticate('nonexisting', 'secret').should be_nil > > (rdb:1) s > > c:/tools/ruby/ruby186/lib/ruby/gems/1.8/gems/mocha-0.9.5/lib/mocha/ > > class_method.rb:40 > > stubbee.__metaclass__.class_eval("def #{method}(*args, &block); > > mocha.method_missing(:#{method}, *a > > (rdb:1) c > > > _______________________________________________ > > 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 sfeley at gmail.com Wed Jun 17 17:36:54 2009 From: sfeley at gmail.com (Stephen Eley) Date: Wed, 17 Jun 2009 17:36:54 -0400 Subject: [rspec-users] shared examples sharing methods In-Reply-To: <88fd8ddc0906170814h18ecbd50h86486c1089fb75d@mail.gmail.com> References: <88fd8ddc0906170814h18ecbd50h86486c1089fb75d@mail.gmail.com> Message-ID: <1fb4df0906171436q641b6489y97c04231702307b@mail.gmail.com> On Wed, Jun 17, 2009 at 11:14 AM, Andrew Premdas wrote: > What I'd like to do is create a shared_examples group which I can parametize > a method. So my shared example would perhaps use method named_address=, or > set_named_address and then groups that behave like "Named address" would be > able to override this method so it sets the correct address e.g. the last > billing address This is horrendously ugly, but I was able to achieve something like what you're talking about using a combination of instance variables and 'eval' statements in the shared behavior. See: http://gist.github.com/131526 Readable and elegant? Not really. But I have to set up a crapload of these classes layered on top of somebody else's SOAP API, and spec completeness was more important to me than spec maintainability. (Also, it didn't occur to me to try macros.) >8-> -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From r_j_h_box-sf at yahoo.com Wed Jun 17 19:54:15 2009 From: r_j_h_box-sf at yahoo.com (r_j_h_box-sf at yahoo.com) Date: Wed, 17 Jun 2009 16:54:15 -0700 (PDT) Subject: [rspec-users] Problem verifying routing error In-Reply-To: <123149.78952.qm@web31815.mail.mud.yahoo.com> References: <49FCAAA6.6040600@yahoo.com> <4A046AEF.1090307@benmabey.com> <187508.72754.qm@web31806.mail.mud.yahoo.com> <57c63afe0906161328n5db41a0ajc0f4ca43ddb12ef1@mail.gmail.com> <55736.1826.qm@web31804.mail.mud.yahoo.com> <123149.78952.qm@web31815.mail.mud.yahoo.com> Message-ID: <772039.54312.qm@web31806.mail.mud.yahoo.com> Okay, after such a harsh analysis of the problem, I figured it was worth digging in just a little bit more. Side note, some of what I was seeing yesterday was a by-product of having default routes still existing. But there are still some essential facts that remain, which I present here. 1. The current implementation of route_for().should == "/something" is only consulting route recognition. A more descriptive phrasing of this behavior would be something like > route_recognize("/something").should == { :action ... :controller ... } 2. of course, params_for() was *also* consulting route recognition through a slightly different code path, but eventually using exactly the same test. Therefore, route generation and recognition are a) redundant and b) incomplete. I did dig in more to the problem and spiked out a fairly solid alternative, which is 100% backward-compatible, plus a bunch. Here's my thinking process: 1. If we were to use assert_generates(), it could test that the params result in the specified path, the way implied by the current route_for().should == syntax. Note, however, that it doesn't verify that the :method arg is correct (if the hash with :path, :method is provided, it actually causes failure). 2. assert_recognizes() does test the method of { :path ... :method } Therefore, if we can do both assert_generate() and assert_recognizes(), then we have covered testing a) actual route generation, b) method matching, and c) (bonus result) params_for() matching. This last is nice, though kind of a hidden benefit that doesn't make itself obvious to the reader of the briefer routing spec. Fortunately, it's optional - as I said, what I've done is 100% back-compatible. Also, to support my original goals, some methods (which require catching exceptions that would otherwise be informative) to provide: 1. Non-routeability tests (:action ... :controller).should_not be_routable 2. Path-cleanliness and negative method tests > route_for(:action ... :controller ... :args ).should_not be_post("/path") Hey, did you catch that? be_post(), I said. Well, because it catches exceptions, it's not so useful for positive cases. So: 42. A few extra methods that directly test expected positive cases, which can (but don't have to) replace .should == { :path ... :method } > route_for(:action ... :controller ... :args ).should post("/path") > route_for(:action ... :controller ... :args ).should put("/path") > route_for(:action ... :controller ... :args ).should get("/path") > route_for(:action ... :controller ... :args ).should delete("/path") This gist demonstrates a currently-working example of this method, annotated to introduce things step by step, including the results of my spike that makes it all work. http://gist.github.com/131569 I hope that this is both more helpful than just my griping of yesterday, and that it adds some value to the project. Randy ----- Original Message ---- > From: "r_j_h_box-sf at yahoo.com" > To: rspec-users > Sent: Tuesday, June 16, 2009 5:23:34 PM > Subject: Re: [rspec-users] Problem verifying routing error > > > Here's another interesting symptom. After tracing through the code, I've come > to the understanding that the current implementation (delegated to outside > rspec, I understand) of route "generation" is not > testing generation at all, but rather is using backward-recognition as a proxy. > Further, that recognition doesn't correspond to what the real router does > recognize. > > For clarity, here's the background: A resource that requires nesting for new, > create; requires > no nesting for edit, update, destroy, and has no index or show. > > > map.resources :designs, :only => [:edit, :update, :destroy] > > map.resources :product, :member => { :redraw => :get } do |product| > > product.resources :designs, :member => { :set_default => > :put }, :except => [ :edit, :update, :destroy, :index, :show ] > > end > > Okay: when I go to /designs/new in the browser, it borks with a RoutingError. > That's the way I want it to behave, real-world. Yet, this fails: > > > expect { route_for(:controller => "designs", :action => "new") == > "/designs/new" }.to raise_error( ActionController::RoutingError ) > > There's no error raised at all here. > > The following does gripe, but... what it's *really* griping about (in a hidden > way) is "bogus path", not about the route_for() params at all. > > > > expect { route_for(:controller => "designs", :action > => "new") == "bogus path" }.to raise_error( > ActionController::RoutingError ) > > (so if we replace route_for([bad]) with route_for([good]) == "bogus path", then > we still get the routing error. > > > Furthermore, the first one really recognizes the route string (/designs/new), > without actually verifying that there is a route in the routing table for it. > So I fear that it's not actually testing what I'm asking it to test. Taking it > out of the expect {} *does* make it barf, but with evidence that something is > just plain confused, not that it's actually testing what we're asking it to > test: > > [wrapping is mine] > > The recognized options <{"action"=>"1", "controller"=>"designs"}> > > did not match <{"action"=>"show", "id"=>"1", "controller"=>"designs"}>, > > difference: <{"action"=>"show", "id"=>"1"}> > > At the end of the day, what I find is: > > * Route generation tests are not testing generation at all, but recognition only > * They're only testing recognition of ideal cases > * Non-existence of routes is currently not testable with rspec > > I hoped to just assert something on url_for() - that's the practical > application, here. Does, or does not, url_for() produce a useful result with > specific args? But I see from ActionController::Base how that's not super > practical. > > I sincerely hope that my understanding is wildly mistaken. > > Sorry if this is a sore spot; I know that this part has been a lot of painful > effort so far, far more for others than for myself. I'll end with an expression > of deep and sincere appreciation for this great software. > > Randy > > > > > ----- Original Message ---- > > From: "r_j_h_box-sf at yahoo.com" > > To: rspec-users > > Sent: Tuesday, June 16, 2009 2:14:52 PM > > Subject: Re: [rspec-users] Problem verifying routing error > > > > > > David, thank you for your reply on this. I really dig the expect { }.to > > raise_error() syntax!! > > > > To clarify: All the things you're claiming match my expectation. > Unfortunately, > > my expectation does not match reality according to my tests. > > > > The thing is, route_for([bad stuff]) does not in and of itself raise a routing > > > error. It constructs an object that hasn't yet been compared with == to > > anything. > > > > 23 t = route_for(:controller => "designs", :action => "create") > > > > (rdb:1) puts t > > # > > > > According to my tests, the routing error only occurs after route_for()'s > result > > gets compared to something. So lambda { route_for(...) } does not raise > error. > > > > The following code passes with flying colors, either in lambda or expect {}.to > > > form: > > > > t = route_for(:controller => "designs", :action => "create") > > expect { t == "anything" }.to raise_error( ActionController::RoutingError > ) > > expect { t.should == "anything" }.to raise_error( > > ActionController::RoutingError ) > > > > Any further ideas? > > > > Randy > > > > > > > > > > > > ----- Original Message ---- > > > From: David Chelimsky > > > To: rspec-users > > > Sent: Tuesday, June 16, 2009 1:28:18 PM > > > Subject: Re: [rspec-users] Problem verifying routing error > > > > > > On Tue, Jun 16, 2009 at 3:07 PM, wrote: > > > > > > > > I finally figured this out. > > > > > > > > lambda { route_for(:controller => "designs", :action => "create").should > == > > > "anything" }.should raise_error( ActionController::RoutingError ) > > > > > > > > The clue was that I wasn't getting a routing error until I tried to > compare > > > route_for() with something. route_for() seems to generate an object that > > > overrides ==(), and at that time it does raise the exception. Now we wrap > > that > > > comparison in a lambda and assert that the *comparison* should raise the > > > expected routing error. > > > > > > > > So - great, we can actually test it. But the syntax does leave something > to > > > > > be desired. dchelimsky, can you recommend any alternatives that would be a > > bit > > > cleaner for testing that a route doesn't exist? > > > > > > > > > > You don't need the .should == "anything" in there. So this is a bit cleaner: > > > > > > lambda { route_for(:controller => "designs", :action => "create") > > > }.should raise_error( ActionController::RoutingError ) > > > > > > Also, since rspec-1.2.5 you can use expect/to: > > > > > > expect { route_for(:controller => "designs", :action => "create") > > > }.to raise_error( ActionController::RoutingError ) > > > > > > You could always kick it old-school: > > > > > > e = nil > > > begin > > > route_for(:controller => "designs", :action => "create") > > > rescue ActionController::RoutingError => e > > > ensure > > > e.should_not be_nil > > > end > > > > > > And you could always wrap this in an new matcher: > > > > > > def be_routable > > > Spec::Matchers.new :be_routable, self do |example| > > > match do |params| > > > e = nil > > > begin > > > example.route_for(params) > > > rescue ActionController::RoutingError => e > > > end > > > !!e > > > end > > > end > > > end > > > > > > {:controller => "designs", :action => "create"}.should_not be_routable > > > > > > In this case you need to wrap the matcher's construction in a method > > > in order to provide access to the scope of the example (which is where > > > route_for lives). Also, I just whipped that up off the top of my head > > > - no idea if it actually works :) > > > > > > HTH, > > > David > > > > > > > > > > > > > > > > Thanks, > > > > > > > > Randy > > > > > > > > > > > > > > > > > > > > ----- Original Message ---- > > > >> From: Ben Mabey > > > >> To: r_j_h_box-sf at yahoo.com; rspec-users > > > >> Sent: Friday, May 8, 2009 10:25:03 AM > > > >> Subject: Re: [rspec-users] Problem verifying routing error > > > >> > > > >> Randy Harmon wrote: > > > >> > Hi, > > > >> > > > > >> > When upgrading to rspec/rspec-rails 1.2.6 gem (from 1.1.12), I'm having > > > >> > a new problem verifying routes that should not exist. > > > >> > > > > >> > This is to support something like this in routes.rb: > > > >> > > > > >> > map.resources :orders do |orders| > > > >> > orders.resources :items, :except => [:index,:show] > > > >> > end > > > >> > > > > >> > I used to use lambda {}.should_raise( routing error ), but it stopped > > > >> > detecting any raised error. Requesting it through the browser produces > > > >> > ActionController::MethodNotAllowed (Only post requests are allowed). > But > > > >> > that error wasn't detected. > > > >> > > > > >> > When I skip the lambda, and just ask it to verify that the route does > > > >> > exist (which *should* fail), I get the same result for those :except > > > >> > actions as for a made-up action name. Seems this must have something > to > > > >> > do with the change in how route_for delegates back to > ActionController's > > > >> > routing assertion (sez the backtrace :). > > > >> > > > > >> > > > > >> > NoMethodError in 'ItemsController route generation should NOT map > > > >> > #indewfefwex' > > > >> > You have a nil object when you didn't expect it! > > > >> > You might have expected an instance of Array. > > > >> > The error occurred while evaluating nil.first > > > >> > > > > >> > > > > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:134:in > > > >> > `recognized_request_for' > > > >> > > > > >> > > > > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:49:in > > > >> > `assert_recognizes' > > > >> > > > > >> > > > > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions.rb:54:in > > > >> > `clean_backtrace' > > > >> > > > > >> > > > > > > /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:47:in > > > >> > `assert_recognizes' > > > >> > ./spec/controllers/thoughts_routing_spec.rb:9: > > > >> > > > > >> > > > > >> > I tried using bypass_rescue in my routing/items_routing_spec.rb file as > > > >> > mentioned by the upgrade doc, but it wasn't valid in the "routing" spec > > > >> > - worked fine when I moved the file back to spec/controllers/, though. > > > >> > Seems like that's not the issue, but I'm mentioning for more > > completeness. > > > >> > > > > >> > Any ideas what I should be doing instead, or how I can troubleshoot > > > further? > > > >> > > > > >> > > > >> > > > >> Hmm.. yeah, it seems like it might have to do with how the exceptions > > > >> are being handled in the newer version of rspec-rials (see > > > >> > > > > > > https://rspec.lighthouseapp.com/projects/5645/tickets/85-11818-have-mode-for-rails-error-handling). > > > >> > > > >> I don't use RSpec to verify my routes very often and have never used it > > > >> to verify the non-existence of a route so I'm afraid I don't really have > > > >> any ideas... > > > >> > > > >> Does anyone else have an idea to do this? > > > >> > > > >> -Ben > > > > > > > > _______________________________________________ > > > > 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 From dchelimsky at gmail.com Wed Jun 17 23:30:47 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Jun 2009 22:30:47 -0500 Subject: [rspec-users] Problem verifying routing error In-Reply-To: <772039.54312.qm@web31806.mail.mud.yahoo.com> References: <49FCAAA6.6040600@yahoo.com> <4A046AEF.1090307@benmabey.com> <187508.72754.qm@web31806.mail.mud.yahoo.com> <57c63afe0906161328n5db41a0ajc0f4ca43ddb12ef1@mail.gmail.com> <55736.1826.qm@web31804.mail.mud.yahoo.com> <123149.78952.qm@web31815.mail.mud.yahoo.com> <772039.54312.qm@web31806.mail.mud.yahoo.com> Message-ID: <57c63afe0906172030l10e8a8a4pf269e7df5810b4e@mail.gmail.com> On Wed, Jun 17, 2009 at 6:54 PM, wrote: > > > Okay, after such a harsh analysis of the problem, I figured it was worth digging in just a little bit more. ?Side note, some of what I was seeing yesterday was a by-product of having default routes still existing. ?But there are still some essential facts that remain, which I present here. > > 1. The current implementation of route_for().should == "/something" is only consulting route recognition. A more descriptive phrasing of this behavior would be something like > >> ? route_recognize("/something").should == { :action ... :controller ... } > > 2. of course, params_for() was *also* consulting route recognition through a slightly different code path, but eventually using exactly the same test. > > Therefore, route generation and recognition are a) redundant and b) incomplete. > > > I did dig in more to the problem and spiked out a fairly solid > alternative, which is 100% backward-compatible, plus a bunch. ?Here's > my thinking process: > > 1. If we were to use assert_generates(), it could test that the params result in the specified path, the way implied by the current route_for().should == syntax. ?Note, however, that it doesn't verify that the :method arg is correct (if the hash with :path, :method is provided, it actually causes failure). > > 2. assert_recognizes() does test the method of { :path ... :method ?} > > Therefore, if we can do both assert_generate() and assert_recognizes(), then we have covered testing a) actual route generation, b) method matching, and c) (bonus result) params_for() matching. ?This last is nice, though kind of a hidden benefit that doesn't make itself obvious to the reader of the briefer routing spec. ?Fortunately, it's optional - as I said, what I've done is 100% back-compatible. > > > Also, to support my original goals, some methods (which require catching exceptions that would otherwise be informative) to provide: > > 1. ?Non-routeability tests (:action ... :controller).should_not be_routable > > 2. ?Path-cleanliness and negative method tests > >> route_for(:action ... :controller ... :args ).should_not be_post("/path") > > Hey, did you catch that? ?be_post(), I said. ?Well, because it catches exceptions, it's not so useful for positive cases. ?So: > > 42. ?A few extra methods that directly test expected positive cases, which can (but don't have to) replace .should == { :path ... :method } > >> route_for(:action ... :controller ... :args ).should post("/path") >> route_for(:action ... :controller ... :args ).should put("/path") >> route_for(:action ... :controller ... :args ).should get("/path") >> route_for(:action ... :controller ... :args ).should delete("/path") > > This gist demonstrates a currently-working example of this method, annotated to introduce things step by step, including the results of my spike that makes it all work. > > http://gist.github.com/131569 > > I hope that this is both more helpful than just my griping of yesterday, and that it adds some value to the project. This is all good stuff Randy. Thanks. Wanna make it a lighthouse ticket with patch? We can talk about the get/put/post/delete-ish methods there. Cheers, David > > Randy > > > > ----- Original Message ---- >> From: "r_j_h_box-sf at yahoo.com" >> To: rspec-users >> Sent: Tuesday, June 16, 2009 5:23:34 PM >> Subject: Re: [rspec-users] Problem verifying routing error >> >> >> Here's another interesting symptom. ?After tracing through the code, I've come >> to the understanding that the current implementation (delegated to outside >> rspec, I understand) of route "generation" is not >> testing generation at all, but rather is using backward-recognition as a proxy. >> Further, that recognition doesn't correspond to what the real router does >> recognize. >> >> For clarity, here's the background: A resource that requires nesting for new, >> create; requires >> no nesting for edit, update, destroy, and has no index or show. >> >> > ?map.resources :designs, :only => [:edit, :update, :destroy] >> > map.resources :product, :member => { :redraw => :get } do |product| >> > ? product.resources :designs, :member => { :set_default => >> :put }, :except => [ :edit, :update, :destroy, :index, :show ] >> > end >> >> Okay: when I go to /designs/new in the browser, it borks with a RoutingError. >> That's the way I want it to behave, real-world. ?Yet, this fails: >> >> > expect { route_for(:controller => "designs", :action => "new") == >> "/designs/new" }.to raise_error( ActionController::RoutingError ) >> >> There's no error raised at all here. >> >> The following does gripe, but... what it's *really* griping about (in a hidden >> way) is "bogus path", not about the route_for() params at all. >> >> >> > expect { ?route_for(:controller => "designs", :action >> => "new") == "bogus path" }.to raise_error( >> ActionController::RoutingError ) >> >> (so if we replace route_for([bad]) with route_for([good]) == "bogus path", then >> we still get the routing error. >> >> >> Furthermore, the first one really recognizes the route string (/designs/new), >> without actually verifying that there is a route in the routing table for it. >> So I fear that it's not actually testing what I'm asking it to test. ?Taking it >> out of the expect {} *does* make it barf, but with evidence that something is >> just plain confused, not that it's actually testing what we're asking it to >> test: >> >> [wrapping is mine] >> > The recognized options <{"action"=>"1", "controller"=>"designs"}> >> > did not match <{"action"=>"show", "id"=>"1", "controller"=>"designs"}>, >> > difference: <{"action"=>"show", "id"=>"1"}> >> >> At the end of the day, what I find is: >> >> * Route generation tests are not testing generation at all, but recognition only >> * They're only testing recognition of ideal cases >> * Non-existence of routes is currently not testable with rspec >> >> I hoped to just assert something on url_for() - that's the practical >> application, here. ?Does, or does not, url_for() produce a useful result with >> specific args? ?But I see from ActionController::Base how that's not super >> practical. >> >> I sincerely hope that my understanding is wildly mistaken. >> >> Sorry if this is a sore spot; I know that this part has been a lot of painful >> effort so far, far more for others than for myself. ?I'll end with an expression >> of deep and sincere appreciation for this great software. >> >> Randy >> >> >> >> >> ----- Original Message ---- >> > From: "r_j_h_box-sf at yahoo.com" >> > To: rspec-users >> > Sent: Tuesday, June 16, 2009 2:14:52 PM >> > Subject: Re: [rspec-users] Problem verifying routing error >> > >> > >> > David, thank you for your reply on this. ?I really dig the expect { }.to >> > raise_error() syntax!! >> > >> > To clarify: All the things you're claiming match my expectation. >> Unfortunately, >> > my expectation does not match reality according to my tests. >> > >> > The thing is, route_for([bad stuff]) does not in and of itself raise a routing >> >> > error. ?It constructs an object that hasn't yet been compared with == to >> > anything. >> > >> > 23 ? t = route_for(:controller => "designs", :action => "create") >> > >> > (rdb:1) puts t >> > # >> > >> > According to my tests, the routing error only occurs after route_for()'s >> result >> > gets compared to something. ?So lambda { route_for(...) } does not raise >> error. >> > >> > The following code passes with flying colors, either in lambda or expect {}.to >> >> > form: >> > >> > ? ? t = route_for(:controller => "designs", :action => "create") >> > ? ? expect { t == "anything" }.to raise_error( ActionController::RoutingError >> ) >> > ? ? expect { t.should == "anything" }.to raise_error( >> > ActionController::RoutingError ) >> > >> > Any further ideas? >> > >> > Randy >> > >> > >> > >> > >> > >> > ----- Original Message ---- >> > > From: David Chelimsky >> > > To: rspec-users >> > > Sent: Tuesday, June 16, 2009 1:28:18 PM >> > > Subject: Re: [rspec-users] Problem verifying routing error >> > > >> > > On Tue, Jun 16, 2009 at 3:07 PM, wrote: >> > > > >> > > > I finally figured this out. >> > > > >> > > > lambda { route_for(:controller => "designs", :action => "create").should >> == >> > > "anything" }.should raise_error( ActionController::RoutingError ) >> > > > >> > > > The clue was that I wasn't getting a routing error until I tried to >> compare >> > > route_for() with something. ?route_for() seems to generate an object that >> > > overrides ==(), and at that time it does raise the exception. ?Now we wrap >> > that >> > > comparison in a lambda and assert that the *comparison* should raise the >> > > expected routing error. >> > > > >> > > > So - great, we can actually test it. ?But the syntax does leave something >> to >> > >> > > be desired. ?dchelimsky, can you recommend any alternatives that would be a >> > bit >> > > cleaner for testing that a route doesn't exist? >> > > > >> > > >> > > You don't need the .should == "anything" in there. So this is a bit cleaner: >> > > >> > > ? lambda { route_for(:controller => "designs", :action => "create") >> > > }.should raise_error( ActionController::RoutingError ) >> > > >> > > Also, since rspec-1.2.5 you can use expect/to: >> > > >> > > ? expect { route_for(:controller => "designs", :action => "create") >> > > }.to raise_error( ActionController::RoutingError ) >> > > >> > > You could always kick it old-school: >> > > >> > > ? e = nil >> > > ? begin >> > > ? ? route_for(:controller => "designs", :action => "create") >> > > ? rescue ActionController::RoutingError => e >> > > ? ensure >> > > ? ? e.should_not be_nil >> > > ? end >> > > >> > > And you could always wrap this in an new matcher: >> > > >> > > def be_routable >> > > ? Spec::Matchers.new :be_routable, self do |example| >> > > ? ? match do |params| >> > > ? ? ? e = nil >> > > ? ? ? begin >> > > ? ? ? ? example.route_for(params) >> > > ? ? ? rescue ActionController::RoutingError => e >> > > ? ? ? end >> > > ? ? ? !!e >> > > ? ? end >> > > ? end >> > > end >> > > >> > > {:controller => "designs", :action => "create"}.should_not be_routable >> > > >> > > In this case you need to wrap the matcher's construction in a method >> > > in order to provide access to the scope of the example (which is where >> > > route_for lives). Also, I just whipped that up off the top of my head >> > > - no idea if it actually works :) >> > > >> > > HTH, >> > > David >> > > >> > > >> > > >> > > >> > > > Thanks, >> > > > >> > > > Randy >> > > > >> > > > >> > > > >> > > > >> > > > ----- Original Message ---- >> > > >> From: Ben Mabey >> > > >> To: r_j_h_box-sf at yahoo.com; rspec-users >> > > >> Sent: Friday, May 8, 2009 10:25:03 AM >> > > >> Subject: Re: [rspec-users] Problem verifying routing error >> > > >> >> > > >> Randy Harmon wrote: >> > > >> > Hi, >> > > >> > >> > > >> > When upgrading to rspec/rspec-rails 1.2.6 gem (from 1.1.12), I'm having >> > > >> > a new problem verifying routes that should not exist. >> > > >> > >> > > >> > This is to support something like this in routes.rb: >> > > >> > >> > > >> > map.resources :orders do |orders| >> > > >> > ? ? orders.resources :items, :except => [:index,:show] >> > > >> > end >> > > >> > >> > > >> > I used to use lambda {}.should_raise( routing error ), but it stopped >> > > >> > detecting any raised error. ?Requesting it through the browser produces >> > > >> > ActionController::MethodNotAllowed (Only post requests are allowed). >> But >> > > >> > that error wasn't detected. >> > > >> > >> > > >> > When I skip the lambda, and just ask it to verify that the route does >> > > >> > exist (which *should* fail), I get the same result for those :except >> > > >> > actions as for a made-up action name. ?Seems this must have something >> to >> > > >> > do with the change in how route_for delegates back to >> ActionController's >> > > >> > routing assertion (sez the backtrace :). >> > > >> > >> > > >> > >> > > >> > NoMethodError in 'ItemsController route generation should NOT map >> > > >> > #indewfefwex' >> > > >> > You have a nil object when you didn't expect it! >> > > >> > You might have expected an instance of Array. >> > > >> > The error occurred while evaluating nil.first >> > > >> > >> > > >> >> > > >> > >> /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:134:in >> > > >> > `recognized_request_for' >> > > >> > >> > > >> >> > > >> > >> /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:49:in >> > > >> > `assert_recognizes' >> > > >> > >> > > >> >> > > >> > >> /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions.rb:54:in >> > > >> > `clean_backtrace' >> > > >> > >> > > >> >> > > >> > >> /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:47:in >> > > >> > `assert_recognizes' >> > > >> > ./spec/controllers/thoughts_routing_spec.rb:9: >> > > >> > >> > > >> > >> > > >> > I tried using bypass_rescue in my routing/items_routing_spec.rb file as >> > > >> > mentioned by the upgrade doc, but it wasn't valid in the "routing" spec >> > > >> > - worked fine when I moved the file back to spec/controllers/, though. >> > > >> > Seems like that's not the issue, but I'm mentioning for more >> > completeness. >> > > >> > >> > > >> > Any ideas what I should be doing instead, or how I can troubleshoot >> > > further? >> > > >> > >> > > >> >> > > >> >> > > >> Hmm.. yeah, it seems like it might have to do with how the exceptions >> > > >> are being handled in the newer version of rspec-rials (see >> > > >> >> > > >> > >> https://rspec.lighthouseapp.com/projects/5645/tickets/85-11818-have-mode-for-rails-error-handling). >> > > >> >> > > >> I don't use RSpec to verify my routes very often and have never used it >> > > >> to verify the non-existence of a route so I'm afraid I don't really have >> > > >> any ideas... >> > > >> >> > > >> Does anyone else have an idea to do this? >> > > >> >> > > >> -Ben >> > > > >> > > > _______________________________________________ >> > > > 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 > From ben at benmabey.com Thu Jun 18 00:17:29 2009 From: ben at benmabey.com (Ben Mabey) Date: Wed, 17 Jun 2009 22:17:29 -0600 Subject: [rspec-users] shared examples sharing methods In-Reply-To: <57c63afe0906171128u4086d8a6icf25246c3a84ba6@mail.gmail.com> References: <88fd8ddc0906170814h18ecbd50h86486c1089fb75d@mail.gmail.com> <57c63afe0906170821t4258666scd390318884b233@mail.gmail.com> <57c63afe0906171128u4086d8a6icf25246c3a84ba6@mail.gmail.com> Message-ID: <4A39BFD9.4070205@benmabey.com> David Chelimsky wrote: > On Wed, Jun 17, 2009 at 1:19 PM, Matt Wynne wrote: > >> On 17 Jun 2009, at 16:21, David Chelimsky wrote: >> >> >>> On Wed, Jun 17, 2009 at 10:14 AM, Andrew Premdas >>> wrote: >>> >>>> Please have a look at >>>> http://gist.github.com/131277 >>>> What I'd like to do is create a shared_examples group which I can >>>> parametize >>>> a method. So my shared example would perhaps use method named_address=, >>>> or >>>> set_named_address and then groups that behave like "Named address" would >>>> be >>>> able to override this method so it sets the correct address e.g. the last >>>> billing address >>>> >>> Here's the short version: There's been a lot of discussion on this >>> list about parameterizing shared examples. Basically, given the >>> current design it can't happen, and macros are a perfectly good >>> solution to the problem, so there's not much incentive to change the >>> design. >>> >> You can use instance variables to pass values to the shared examples, >> though, right? >> > > At your own risk, yes, of course :) > If you do go down that route, I recommend method calls instead of instance variables. That way it will yell out you when you forget to define one. :) -Ben > >> cheers, >> Matt Wynne >> >> http://mattwynne.net >> +447974 430184 >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Thu Jun 18 00:36:17 2009 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 18 Jun 2009 00:36:17 -0400 Subject: [rspec-users] shared examples sharing methods In-Reply-To: <4A39BFD9.4070205@benmabey.com> References: <88fd8ddc0906170814h18ecbd50h86486c1089fb75d@mail.gmail.com> <57c63afe0906170821t4258666scd390318884b233@mail.gmail.com> <57c63afe0906171128u4086d8a6icf25246c3a84ba6@mail.gmail.com> <4A39BFD9.4070205@benmabey.com> Message-ID: <1fb4df0906172136t137d8adeja823bde526d8dff6@mail.gmail.com> On Thu, Jun 18, 2009 at 12:17 AM, Ben Mabey wrote: > > If you do go down that route, I recommend method calls instead of instance > variables. ?That way it will yell out you when you forget to define one. :) Hey, instance variables do that too. Yelling == "my tests fail." >8-> (And if they don't, I'm *really* doing something wrong...) -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From godfoca at gmail.com Thu Jun 18 01:04:22 2009 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 18 Jun 2009 02:04:22 -0300 Subject: [rspec-users] shared examples sharing methods In-Reply-To: <1fb4df0906172136t137d8adeja823bde526d8dff6@mail.gmail.com> References: <88fd8ddc0906170814h18ecbd50h86486c1089fb75d@mail.gmail.com> <57c63afe0906170821t4258666scd390318884b233@mail.gmail.com> <57c63afe0906171128u4086d8a6icf25246c3a84ba6@mail.gmail.com> <4A39BFD9.4070205@benmabey.com> <1fb4df0906172136t137d8adeja823bde526d8dff6@mail.gmail.com> Message-ID: On Thu, Jun 18, 2009 at 1:36 AM, Stephen Eley wrote: > On Thu, Jun 18, 2009 at 12:17 AM, Ben Mabey wrote: >> >> If you do go down that route, I recommend method calls instead of instance >> variables. ?That way it will yell out you when you forget to define one. :) > > Hey, instance variables do that too. ?Yelling == "my tests fail." ?>8-> > > (And if they don't, I'm *really* doing something wrong...) But methods are more explicit. Suppose you want to parametrize on the value of a certain property named "bar". Not defining @bar will raise an NoMethodError because you called something on nil. Not defining the method will raise a NoMethodError because bar isn't defined, which tells you immediately what you need to solve. You could also do something like def bar raise NotImplementedError, "please define this method in each of your example groups that use this shared behavior" end and it will be even more explicit. *But* this means you have to define the method *after* you include the shared examples, or it will fail (which is a code smell, IMO). -foca > > > -- > Have Fun, > ? Steve Eley (sfeley at gmail.com) > ? ESCAPE POD - The Science Fiction Podcast Magazine > ? http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Thu Jun 18 01:14:25 2009 From: ben at benmabey.com (Ben Mabey) Date: Wed, 17 Jun 2009 23:14:25 -0600 Subject: [rspec-users] shared examples sharing methods In-Reply-To: <57c63afe0906170821t4258666scd390318884b233@mail.gmail.com> References: <88fd8ddc0906170814h18ecbd50h86486c1089fb75d@mail.gmail.com> <57c63afe0906170821t4258666scd390318884b233@mail.gmail.com> Message-ID: <4A39CD31.3080301@benmabey.com> David Chelimsky wrote: > On Wed, Jun 17, 2009 at 10:14 AM, Andrew Premdas wrote: > >> Please have a look at >> http://gist.github.com/131277 >> What I'd like to do is create a shared_examples group which I can parametize >> a method. So my shared example would perhaps use method named_address=, or >> set_named_address and then groups that behave like "Named address" would be >> able to override this method so it sets the correct address e.g. the last >> billing address >> > > Here's the short version: There's been a lot of discussion on this > list about parameterizing shared examples. Basically, given the > current design it can't happen, and macros are a perfectly good > solution to the problem, so there's not much incentive to change the > design. > > I'll try to follow up later with a recommendation about a macro, > unless somebody else beats me to it :) > I beat David to it. :) Here are some options: http://gist.github.com/131701 I think I like #7 and #8 the best with the eval and #subject use. With #8 I intentionally modify the backtrace so that the when errors happen it points to where the macro was called, not defined. Sometimes this is desirable, YMMV. FWIW, I question the value of such specs... but that is the macro approach. -Ben From bkocik at gmail.com Thu Jun 18 11:57:24 2009 From: bkocik at gmail.com (Bill Kocik) Date: Thu, 18 Jun 2009 11:57:24 -0400 Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <86BE0CC1-0FEC-4FE7-9407-62D440BD1806@ultrasaurus.com> References: <86BE0CC1-0FEC-4FE7-9407-62D440BD1806@ultrasaurus.com> Message-ID: <310c80f00906180857r300fedc1w6dc12f0de93acdeb@mail.gmail.com> Just to add a couple cents in... I've been working as either a sysadmin or software developer for the last 10 years (software development pretty much exclusively for the last 5 or 6). I started picking up Rails about 2 years ago, and though I was always aware of TDD - and even occasionally dabbled in it - I never really embraced it. Not because I didn't see its importance, but because the barrier to entry always seemed too high, and schedules never allowed for it (as a friend of mine is fond of saying, "You mean we don't have time to do it right, but we have time to do it over and over again?"). Right now I'm working on a personal project for which I have no QA team to watch my back, so instead I'm doggedly using top-down BDD with Cucumber (and unit tests) to help keep me in line. I think the biggest hurdle to learning it is this: Pretty much all the tutorials and docs written on the topic center around some simple example app that's easy to test. But in the real world, software is messy, and tends to resist being tested. I know the traditional counter argument is that this means your design is flawed, but that isn't always true. One of the biggest challenges I faced was how to test authentication in my application, in which users sign in using their Twitter credentials via OAuth[1]. Another was in testing my own endpoints that create JSON that's rendered via JS in the browser[2]. Maybe Selenium could have helped here, but creating tests in general was already slowing me to the point that I'm a good deal behind schedule, and I couldn't take another day or so to learn how to use Selenium with the risk that it might not really suit my situation for one reason or another - because software is messy. One that I haven't tackled yet but will have to soon is how to test code that runs as a BackgrounDRb worker. I came up with solutions for all of this (except for the BDRb stuff), but I'm not entirely sure of their quality. They certainly feel hackish, but I can't put my finger on why. I suspect David Chelimsky or Ben Mabey or Aslak or any of a hundred or more other people could have come up with beautiful, elegant solutions to the challenges I faced, but since none of them were standing over my shoulder I have no way of knowing, and none of this is covered in the write-a-blog-in-10-minutes Rails demo. That has been my challenge in learning and using BDD. [1] My solution: http://tr.im/oW8y [2] I defined these two custom steps (JSON_CALLBACK is defined as the :callback arg I pass in my 'render :json' calls - but it will trip the JSON parser if its there): Then /^I should get valid JSON$/ do assert_nothing_raised do assert JSON.parse(@response.body.gsub(/^#{JSON_CALLBACK}\((.*)\)/, '\1')) end end Then /^I should find "(.+)" in JSON/ do |xpath| json_hash = JSON.parse(@response.body.gsub(/^#{JSON_CALLBACK}\((.*)\)/, '\1')) xmldoc = Nokogiri::XML(json_hash.to_xml) xpath.gsub!('_', '-') # in XML, underscores will be dashes. xpath = "./hash" + xpath unless xpath =~ /^\/\// assert !xmldoc.xpath(xpath).blank? end -- Bill Kocik http://bkocik.net From ben at benmabey.com Thu Jun 18 13:36:25 2009 From: ben at benmabey.com (Ben Mabey) Date: Thu, 18 Jun 2009 11:36:25 -0600 Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <310c80f00906180857r300fedc1w6dc12f0de93acdeb@mail.gmail.com> References: <86BE0CC1-0FEC-4FE7-9407-62D440BD1806@ultrasaurus.com> <310c80f00906180857r300fedc1w6dc12f0de93acdeb@mail.gmail.com> Message-ID: <4A3A7B19.2060609@benmabey.com> Bill Kocik wrote: > Just to add a couple cents in... > > I've been working as either a sysadmin or software developer for the > last 10 years (software development pretty much exclusively for the > last 5 or 6). I started picking up Rails about 2 years ago, and though > I was always aware of TDD - and even occasionally dabbled in it - I > never really embraced it. Not because I didn't see its importance, but > because the barrier to entry always seemed too high, and schedules > never allowed for it (as a friend of mine is fond of saying, "You mean > we don't have time to do it right, but we have time to do it over and > over again?"). > > Right now I'm working on a personal project for which I have no QA > team to watch my back, so instead I'm doggedly using top-down BDD with > Cucumber (and unit tests) to help keep me in line. I think the biggest > hurdle to learning it is this: Pretty much all the tutorials and docs > written on the topic center around some simple example app that's easy > to test. But in the real world, software is messy, and tends to resist > being tested. I know the traditional counter argument is that this > means your design is flawed, but that isn't always true. One of the > biggest challenges I faced was how to test authentication in my > application, in which users sign in using their Twitter credentials > via OAuth[1]. Another was in testing my own endpoints that create JSON > that's rendered via JS in the browser[2]. Maybe Selenium could have > helped here, but creating tests in general was already slowing me to > the point that I'm a good deal behind schedule, and I couldn't take > another day or so to learn how to use Selenium with the risk that it > might not really suit my situation for one reason or another - because > software is messy. > > One that I haven't tackled yet but will have to soon is how to test > code that runs as a BackgrounDRb worker. > > I came up with solutions for all of this (except for the BDRb stuff), > but I'm not entirely sure of their quality. They certainly feel > hackish, but I can't put my finger on why. I suspect David Chelimsky > or Ben Mabey or Aslak or any of a hundred or more other people could > have come up with beautiful, elegant solutions I'm flattered, but FWIW I am always struggling on how best to test things as well. In cases like you are describing it seems like testing it is often harder than the actual implementation. Making those tests valuable without being too brittle can be challenging. > to the challenges I > faced, but since none of them were standing over my shoulder I have no > way of knowing, and none of this is covered in the > write-a-blog-in-10-minutes Rails demo. > > That has been my challenge in learning and using BDD. Thanks for sharing Bill. I totally understand where you are coming from. IME, it is hard when writing a tutorial or giving a presentation to not teach to the least common denominator in the audience (the beginner). Time constraints usually set in too that don't allow you to do more advanced topics that would require more explanation. Thats why for most presentations I try to focus more on the process and ideas rather than the example and tools (i.e stuff you can't learn from a wiki so easily). I do see your point however. I often feel frustrated in other presentations at the simplicity of examples given and wish for more in-depth and challenging examples. Your point is noted: a good tutorial app for BDD should involve harder to test components (web services, asynchronous messaging/processing, caching, etc) since this is what pops up in real projects. > > [1] My solution: http://tr.im/oW8y > This is more or less how I would of done this with Cucumber. And you were complaining about no advanced tutorials. ;) Nice writeup. > [2] I defined these two custom steps (JSON_CALLBACK is defined as the > :callback arg I pass in my 'render :json' calls - but it will trip the > JSON parser if its there): > > Then /^I should get valid JSON$/ do > assert_nothing_raised do > assert JSON.parse(@response.body.gsub(/^#{JSON_CALLBACK}\((.*)\)/, '\1')) > end > end > > Then /^I should find "(.+)" in JSON/ do |xpath| > json_hash = JSON.parse(@response.body.gsub(/^#{JSON_CALLBACK}\((.*)\)/, '\1')) > xmldoc = Nokogiri::XML(json_hash.to_xml) > xpath.gsub!('_', '-') # in XML, underscores will be dashes. > xpath = "./hash" + xpath unless xpath =~ /^\/\// > assert !xmldoc.xpath(xpath).blank? > end > I probably would of done this in RSpec instead of Cucumber. Then I would manually tested in a browser.. since you are going to want to do that anyways. I take this stance quite a bit as I feel adding Selenium (or another automated browser solution) can potentially add much more of a maintenance burden than webrat in :rails mode. Thanks, Ben From bkocik at gmail.com Thu Jun 18 14:05:40 2009 From: bkocik at gmail.com (Bill Kocik) Date: Thu, 18 Jun 2009 14:05:40 -0400 Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <4A3A7B19.2060609@benmabey.com> References: <86BE0CC1-0FEC-4FE7-9407-62D440BD1806@ultrasaurus.com> <310c80f00906180857r300fedc1w6dc12f0de93acdeb@mail.gmail.com> <4A3A7B19.2060609@benmabey.com> Message-ID: <310c80f00906181105j4f48c4b3h7dcf3270c6ec42e6@mail.gmail.com> Thanks for the encouragement, Ben. :) On Thu, Jun 18, 2009 at 1:36 PM, Ben Mabey wrote: >> Then /^I should find "(.+)" in JSON/ do |xpath| >> ?json_hash = JSON.parse(@response.body.gsub(/^#{JSON_CALLBACK}\((.*)\)/, '\1')) >> ?xmldoc = Nokogiri::XML(json_hash.to_xml) >> ?xpath.gsub!('_', '-') # in XML, underscores will be dashes. >> ?xpath = "./hash" + xpath unless xpath =~ /^\/\// >> ?assert !xmldoc.xpath(xpath).blank? >> end >> > > I probably would of done this in RSpec instead of Cucumber. ?Then I would manually tested in a browser.. since you are going to want to do that anyways. ?I take this stance quite a bit as I feel adding Selenium (or another automated browser solution) can potentially add much more of a maintenance burden than webrat in :rails mode. In this particular project, all the JS is written by my partner (I'm completely JS-clueless). Having a bunch of lines in my cucumber tests validating everything that should be in the JSON structure my controllers generate in order for the JS to work (and I have a lot of them) is the best way for me to be able to tell if I've broken something (and if I have, in what way I broke it). If the page doesn't work, I will likely have difficulty figuring out why - unless Cucumber is there to tell me it didn't find "/response/statusCode" in the JSON like it should have, then I know what to fix. :) Though I suppose there's probably no reason RSpec couldn't have done the same thing. I haven't used it yet in this project. -- Bill Kocik http://bkocik.net From powertoaster at hotmail.com Thu Jun 18 16:22:24 2009 From: powertoaster at hotmail.com (powertoaster) Date: Thu, 18 Jun 2009 13:22:24 -0700 (PDT) Subject: [rspec-users] I am having a problem testing a date in a rails view In-Reply-To: <24002045.post@talk.nabble.com> References: <23992350.post@talk.nabble.com> <57c63afe0906112239h52d66873t71e1fc7a679f0d95@mail.gmail.com> <24002045.post@talk.nabble.com> Message-ID: <24099603.post@talk.nabble.com> I fixed this problem, I was only checking for a partial string rather than the full string in the element. The way I discovere dit for those who are interested was by printing out the response.body object so that I could view the actuall content I was testing against.:jumping: -- View this message in context: http://www.nabble.com/I-am-having-a-problem-testing-a-date-in-a-rails-view-tp23992350p24099603.html Sent from the rspec-users mailing list archive at Nabble.com. From andy at cllearview.com Thu Jun 18 17:42:57 2009 From: andy at cllearview.com (Andy Shipman) Date: Thu, 18 Jun 2009 22:42:57 +0100 Subject: [rspec-users] Spork and Merb and rSpec In-Reply-To: References: <4A364FF0.6030405@railsnewbie.com> <5D8C3325-5E86-47CC-95DE-F9387C03B2F0@railsnewbie.com> <4A3724C9.6000104@benmabey.com> Message-ID: <2D1C7E84-360D-4227-A866-BCF4A11C8659@cllearview.com> On 16 Jun 2009, at 22:11, Tim Harper wrote: > I'm interested to hear your experience with Spork and Merb. Right > now Spork is doing some hooks in to rails (that are actually kind of > aggressive right now) to help make spork work more out of the box - > specifically, preventing rails from preloading application models > and controllers before the fork occurs. > > Be sure to run spork -d and look to see which files are being > preloaded. Every file listed there will be cached and not reloaded > until spork is restarted. > > Tim On a brand new merb app, its clear that Spork isn't going to work too well for me then! 6> ~/dev/spork-test % spork -d Using RSpec Loading Spork.prefork block... - Spork Diagnosis - -- Summary -- app/controllers/application.rb app/controllers/exceptions.rb app/helpers/global_helpers.rb app/models/user.rb config/dependencies.rb config/environments/test.rb config/init.rb config/router.rb merb/merb-auth/setup.rb merb/merb-auth/strategies.rb merb/session/session.rb spec/spec_helper.rb Looking at the way that you're dealing with Rails, and given my lack of understanding of Merb internals, I'm not sure that I'm going to get too far, tbh. Any suggestions as to where to start to review this to see if it _can_ be made to work? Or should I just wait until Merb becomes Rails 3 ;-) Andy From lists at ruby-forum.com Thu Jun 18 21:51:57 2009 From: lists at ruby-forum.com (Auto Bot) Date: Fri, 19 Jun 2009 03:51:57 +0200 Subject: [rspec-users] Can't use Cucumber with Webrat and Selenium In-Reply-To: <20c51567-6c06-48bd-a8e9-07c8cb0defbe@j12g2000vbl.googlegroups.com> References: <20c51567-6c06-48bd-a8e9-07c8cb0defbe@j12g2000vbl.googlegroups.com> Message-ID: John Small wrote: > Well I can't help you but I do have a similar problem. In my case > Cucumber-Selenium works, Cucumber-Webrat works but Cucmber-Webrat- > Selenium doesn't work because Webrat issues requests to www.example.com > and Selenium starts up a mongrel on localhost:3001, connects to it via > Firefox and then throws up when it gets a request to go to > www.example.com. > I need to find a way to change the host name that Webrat uses when it > connects via Selenium. In env.rb Webrat.configure do |config| config.mode = :selenium config.application_environment = :test # Tell where the application is running on for selenium to test config.application_address = "#{app_server_host}" config.application_port = "#{app_port}" # Tell where selenium server is running on, when not specified defaults to nil (server starts in webrat process and runs locally) config.selenium_server_address = "#{selenium_server_host}" config.selenium_server_port = "4444" # Set the key that Selenium uses to determine the browser running config.selenium_browser_key = '#{browser}' end -- Posted via http://www.ruby-forum.com/. From hayafirst at gmail.com Fri Jun 19 10:24:53 2009 From: hayafirst at gmail.com (Yi Wen) Date: Fri, 19 Jun 2009 09:24:53 -0500 Subject: [rspec-users] Spork 0.57 In-Reply-To: References: <20c51567-6c06-48bd-a8e9-07c8cb0defbe@j12g2000vbl.googlegroups.com> Message-ID: <6DEBA903-A481-4009-B91F-B6B317923F34@gmail.com> Hello, I has spork 0.5.0 and worked fine. now I updated to spork 0.5.7 which seems to break the existing setting. The stack trace looks like this: Using RSpec Preloading Rails environment Loading Spork.prefork block... uninitialized constant MissingSourceFile (NameError) /my_proj/vendor/gems/rspec-rails-1.2.6/lib/spec/rails.rb:5 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' /my_porj/spec/spec_helper.rb:8 /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ spork.rb:11:in `prefork' /my_porj/spec/spec_helper.rb:4 /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ spork/server.rb:166:in `load' /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ spork/server.rb:166:in `preload' /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ spork/app_framework/rails.rb:121:in `preload' /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ spork/server.rb:162:in `preload' /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ spork.rb:41:in `exec_prefork' /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ spork/server.rb:148:in `preload' /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ spork/runner.rb:95:in `run' /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ spork/runner.rb:10:in `run' /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/spork:11 /usr/local/bin/spork:19:in `load' /usr/local/bin/spork:19 It's missing application_controller. THe environment.rb is loaded before require 'spec/rails'. Any idea? Thanks Yi From dchelimsky at gmail.com Fri Jun 19 10:33:42 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 19 Jun 2009 09:33:42 -0500 Subject: [rspec-users] Spork 0.57 In-Reply-To: <6DEBA903-A481-4009-B91F-B6B317923F34@gmail.com> References: <20c51567-6c06-48bd-a8e9-07c8cb0defbe@j12g2000vbl.googlegroups.com> <6DEBA903-A481-4009-B91F-B6B317923F34@gmail.com> Message-ID: <57c63afe0906190733l5915e3f1y1f440c212a0b27f3@mail.gmail.com> On Fri, Jun 19, 2009 at 9:24 AM, Yi Wen wrote: > Hello, > > I has spork 0.5.0 and worked fine. now I updated to spork 0.5.7 which seems > to break the existing setting. The stack trace looks like this: > > Using RSpec > Preloading Rails environment > Loading Spork.prefork block... > uninitialized constant MissingSourceFile (NameError) > /my_proj/vendor/gems/rspec-rails-1.2.6/lib/spec/rails.rb:5 > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in > `gem_original_require' > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' > /my_porj/spec/spec_helper.rb:8 > /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork.rb:11:in > `prefork' > /my_porj/spec/spec_helper.rb:4 > /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/server.rb:166:in > `load' > /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/server.rb:166:in > `preload' > /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/app_framework/rails.rb:121:in > `preload' > /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/server.rb:162:in > `preload' > /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork.rb:41:in > `exec_prefork' > /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/server.rb:148:in > `preload' > /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/runner.rb:95:in > `run' > /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/runner.rb:10:in > `run' > /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/spork:11 > /usr/local/bin/spork:19:in `load' > /usr/local/bin/spork:19 > > > It's missing application_controller. THe environment.rb is loaded before > require 'spec/rails'. Any idea? It's probably because of this: https://rspec.lighthouseapp.com/projects/5645/tickets/839 If so, just remove the conditional from the line that requires environment.rb > > Thanks > > Yi > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 19 10:34:16 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 19 Jun 2009 09:34:16 -0500 Subject: [rspec-users] Spork 0.57 In-Reply-To: <57c63afe0906190733l5915e3f1y1f440c212a0b27f3@mail.gmail.com> References: <20c51567-6c06-48bd-a8e9-07c8cb0defbe@j12g2000vbl.googlegroups.com> <6DEBA903-A481-4009-B91F-B6B317923F34@gmail.com> <57c63afe0906190733l5915e3f1y1f440c212a0b27f3@mail.gmail.com> Message-ID: <57c63afe0906190734v4118ffc7lc54e276359d78d3@mail.gmail.com> On Fri, Jun 19, 2009 at 9:33 AM, David Chelimsky wrote: > On Fri, Jun 19, 2009 at 9:24 AM, Yi Wen wrote: >> Hello, >> >> I has spork 0.5.0 and worked fine. now I updated to spork 0.5.7 which seems >> to break the existing setting. The stack trace looks like this: >> >> Using RSpec >> Preloading Rails environment >> Loading Spork.prefork block... >> uninitialized constant MissingSourceFile (NameError) >> /my_proj/vendor/gems/rspec-rails-1.2.6/lib/spec/rails.rb:5 >> /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in >> `gem_original_require' >> /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' >> /my_porj/spec/spec_helper.rb:8 >> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork.rb:11:in >> `prefork' >> /my_porj/spec/spec_helper.rb:4 >> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/server.rb:166:in >> `load' >> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/server.rb:166:in >> `preload' >> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/app_framework/rails.rb:121:in >> `preload' >> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/server.rb:162:in >> `preload' >> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork.rb:41:in >> `exec_prefork' >> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/server.rb:148:in >> `preload' >> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/runner.rb:95:in >> `run' >> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/spork/runner.rb:10:in >> `run' >> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/spork:11 >> /usr/local/bin/spork:19:in `load' >> /usr/local/bin/spork:19 >> >> >> It's missing application_controller. THe environment.rb is loaded before >> require 'spec/rails'. Any idea? > > It's probably because of this: > https://rspec.lighthouseapp.com/projects/5645/tickets/839 > > If so, just remove the conditional from the line that requires environment.rb If that's not it, you may want to try the spork google group: http://groups.google.com/group/sporkgem > > > >> >> Thanks >> >> Yi >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From hayafirst at gmail.com Fri Jun 19 10:40:26 2009 From: hayafirst at gmail.com (Yi Wen) Date: Fri, 19 Jun 2009 09:40:26 -0500 Subject: [rspec-users] Spork 0.57 In-Reply-To: <57c63afe0906190734v4118ffc7lc54e276359d78d3@mail.gmail.com> References: <20c51567-6c06-48bd-a8e9-07c8cb0defbe@j12g2000vbl.googlegroups.com> <6DEBA903-A481-4009-B91F-B6B317923F34@gmail.com> <57c63afe0906190733l5915e3f1y1f440c212a0b27f3@mail.gmail.com> <57c63afe0906190734v4118ffc7lc54e276359d78d3@mail.gmail.com> Message-ID: Yup, removing the condition fixed the problem. Thanks! On Jun 19, 2009, at 9:34 AM, David Chelimsky wrote: > On Fri, Jun 19, 2009 at 9:33 AM, David > Chelimsky wrote: >> On Fri, Jun 19, 2009 at 9:24 AM, Yi Wen wrote: >>> Hello, >>> >>> I has spork 0.5.0 and worked fine. now I updated to spork 0.5.7 >>> which seems >>> to break the existing setting. The stack trace looks like this: >>> >>> Using RSpec >>> Preloading Rails environment >>> Loading Spork.prefork block... >>> uninitialized constant MissingSourceFile (NameError) >>> /my_proj/vendor/gems/rspec-rails-1.2.6/lib/spec/rails.rb:5 >>> /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in >>> `gem_original_require' >>> /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in >>> `require' >>> /my_porj/spec/spec_helper.rb:8 >>> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ >>> lib/spork.rb:11:in >>> `prefork' >>> /my_porj/spec/spec_helper.rb:4 >>> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ >>> lib/spork/server.rb:166:in >>> `load' >>> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ >>> lib/spork/server.rb:166:in >>> `preload' >>> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ >>> lib/spork/app_framework/rails.rb:121:in >>> `preload' >>> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ >>> lib/spork/server.rb:162:in >>> `preload' >>> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ >>> lib/spork.rb:41:in >>> `exec_prefork' >>> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ >>> lib/spork/server.rb:148:in >>> `preload' >>> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ >>> lib/spork/runner.rb:95:in >>> `run' >>> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ >>> lib/spork/runner.rb:10:in >>> `run' >>> /usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/spork: >>> 11 >>> /usr/local/bin/spork:19:in `load' >>> /usr/local/bin/spork:19 >>> >>> >>> It's missing application_controller. THe environment.rb is loaded >>> before >>> require 'spec/rails'. Any idea? >> >> It's probably because of this: >> https://rspec.lighthouseapp.com/projects/5645/tickets/839 >> >> If so, just remove the conditional from the line that requires >> environment.rb > > If that's not it, you may want to try the spork google group: > > http://groups.google.com/group/sporkgem > > >> >> >> >>> >>> Thanks >>> >>> Yi >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From powertoaster at hotmail.com Fri Jun 19 14:30:16 2009 From: powertoaster at hotmail.com (powertoaster) Date: Fri, 19 Jun 2009 11:30:16 -0700 (PDT) Subject: [rspec-users] Testing my rails authentication controller In-Reply-To: <57c63afe0906052038t588fb3b6h362a86bfd11e628c@mail.gmail.com> References: <004f01c9e619$a7466870$f5d33950$@com> <57c63afe0906052038t588fb3b6h362a86bfd11e628c@mail.gmail.com> Message-ID: <24116711.post@talk.nabble.com> David thank you, that worked great. I am doing this and am very happy with the result. Employee.stub(:authenticate).with(params[:username], params[:password]).and_return(nil) post :login, params session[:employee_id].should be_nil response.should redirect_to(:controller => "access", :action => "login") The question I have now is how do I test the other controllers. Since all of my other pages are going to require authentication. How do I mock the login functionality in a way that allows me to test my protected pages as if I were logged in without using an actual post to the login controller, and still get the :employee_id in the session? I tried adding this in a before each do @params = {:username => 'MyString', :password => 'MyString'} Employee.stub(:authenticate).with(params[:username], params[:password]).and_return(mock_model(Employee, :id => 1)) session[:employee_id] = 1 Which successfully sets the session variable, but my test fails. describe "GET index" do it "assigns all details as @details" do Detail.stub!(:find).with(:all).and_return([mock_detail]) get :index session[:employee_id].should == 1 <+++++++++ This passes assigns[:details].should == [mock_detail] <+++++++++ This fails end end I get expected: [#], got: nil (using ==) -- View this message in context: http://www.nabble.com/Testing-my-rails-authentication-controller-tp23895779p24116711.html Sent from the rspec-users mailing list archive at Nabble.com. From timcharper at gmail.com Sat Jun 20 21:39:57 2009 From: timcharper at gmail.com (Tim Harper) Date: Sat, 20 Jun 2009 19:39:57 -0600 Subject: [rspec-users] Spork and Merb and rSpec In-Reply-To: <2D1C7E84-360D-4227-A866-BCF4A11C8659@cllearview.com> References: <4A364FF0.6030405@railsnewbie.com> <5D8C3325-5E86-47CC-95DE-F9387C03B2F0@railsnewbie.com> <4A3724C9.6000104@benmabey.com> <2D1C7E84-360D-4227-A866-BCF4A11C8659@cllearview.com> Message-ID: Hey Andy, I'd be happy to work with you on getting merb support going. I'm not a merb developer myself, but I am interested in expanding spork to work with other frameworks. I'll create a merb app and see what I can do to get it to work. Tim On Thu, Jun 18, 2009 at 3:42 PM, Andy Shipman wrote: > On 16 Jun 2009, at 22:11, Tim Harper wrote: > > I'm interested to hear your experience with Spork and Merb. Right now >> Spork is doing some hooks in to rails (that are actually kind of aggressive >> right now) to help make spork work more out of the box - specifically, >> preventing rails from preloading application models and controllers before >> the fork occurs. >> >> Be sure to run spork -d and look to see which files are being preloaded. >> Every file listed there will be cached and not reloaded until spork is >> restarted. >> >> Tim >> > > On a brand new merb app, its clear that Spork isn't going to work too well > for me then! > > 6> ~/dev/spork-test % spork -d > Using RSpec > Loading Spork.prefork block... > - Spork Diagnosis - > -- Summary -- > app/controllers/application.rb > app/controllers/exceptions.rb > app/helpers/global_helpers.rb > app/models/user.rb > config/dependencies.rb > config/environments/test.rb > config/init.rb > config/router.rb > merb/merb-auth/setup.rb > merb/merb-auth/strategies.rb > merb/session/session.rb > spec/spec_helper.rb > > Looking at the way that you're dealing with Rails, and given my lack of > understanding of Merb internals, I'm not sure that I'm going to get too far, > tbh. > > Any suggestions as to where to start to review this to see if it _can_ be > made to work? Or should I just wait until Merb becomes Rails 3 ;-) > > Andy > > > _______________________________________________ > 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 lists at ruby-forum.com Mon Jun 22 02:53:15 2009 From: lists at ruby-forum.com (Wolfram Arnold) Date: Mon, 22 Jun 2009 08:53:15 +0200 Subject: [rspec-users] [Cucumber] Successive requests with xml Content-Type fail? Message-ID: <889342016bcb9f8f7ada63734f1d1e25@ruby-forum.com> I'm writing a cucumber test for an xml webservice. When making POST's the Content-Type in the header is set to "application/xml" and for any request, the Accept header is set to "application/xml" (aka Mime::XML.to_s) I'm running into the following issue: When I make two successive requests, the first one being a POST to log the user in; the second one a GET to retrieve some data, the second request always seems to fail with this error: private method `split' called for # (NoMethodError) /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/mime_type.rb:206:in `method_missing' /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:51:in `media_type' /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:117:in `parseable_data?' /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:138:in `POST' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/request.rb:428:in `request_parameters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/request.rb:381:in `parameters' This started happening only in Rails 2.3. It previously worked fine with Rails 2.0 Now, I dug into this some more; the Session class in webrat core seems to get instantiated once for the entire scenario and the instance sticks around for all of the requests. I noticed by checking with the debugger, that the header object gets transformed into a Rack header object and acquires things like the referrer field from the first request. On the second request (the GET), the Content-Type is set but it probably shouldn't--as there is no payload data, it's a GET--and that causes havoc. I'm kind of lost as to whether this is a bug in Rack or Rails or Webrat or whether I'm doing something wrong. Any advice is appreciated. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Jun 22 04:22:32 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 22 Jun 2009 03:22:32 -0500 Subject: [rspec-users] [Cucumber] Successive requests with xml Content-Type fail? In-Reply-To: <889342016bcb9f8f7ada63734f1d1e25@ruby-forum.com> References: <889342016bcb9f8f7ada63734f1d1e25@ruby-forum.com> Message-ID: <57c63afe0906220122o3ea21887nf74f734cd9a71f92@mail.gmail.com> On Mon, Jun 22, 2009 at 1:53 AM, Wolfram Arnold wrote: > I'm writing a cucumber test for an xml webservice. ?When making POST's > the Content-Type in the header is set to "application/xml" and for any > request, the Accept header is set to "application/xml" (aka > Mime::XML.to_s) > > I'm running into the following issue: > > When I make two successive requests, the first one being a POST to log > the user in; the second one a GET to retrieve some data, the second > request always seems to fail with this error: > > ? ? ?private method `split' called for # > (NoMethodError) > ? ? ?/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/mime_type.rb:206:in > `method_missing' > ? ? ?/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:51:in > `media_type' > ? ? ?/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:117:in > `parseable_data?' > ? ? ?/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:138:in > `POST' > ? ? ?/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/request.rb:428:in > `request_parameters' > ? ? ?/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/request.rb:381:in > `parameters' > > > This started happening only in Rails 2.3. ?It previously worked fine > with Rails 2.0 > > Now, I dug into this some more; the Session class in webrat core seems > to get instantiated once for the entire scenario and the instance sticks > around for all of the requests. ?I noticed by checking with the > debugger, that the header object gets transformed into a Rack header > object and acquires things like the referrer field from the first > request. ?On the second request (the GET), the Content-Type is set but > it probably shouldn't--as there is no payload data, it's a GET--and that > causes havoc. ?I'm kind of lost as to whether this is a bug in Rack or > Rails or Webrat or whether I'm doing something wrong. > > Any advice is appreciated. Cucumber has had a separate list for some time now. Please post this to http://groups.google.com/group/cukes. Cheers, David From dchelimsky at gmail.com Mon Jun 22 11:52:46 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 22 Jun 2009 10:52:46 -0500 Subject: [rspec-users] [Cucumber] Autospec run "only" features ? In-Reply-To: <670a00380906220850o6633b505ia03749441741a22e@mail.gmail.com> References: <670a00380906220850o6633b505ia03749441741a22e@mail.gmail.com> Message-ID: <57c63afe0906220852q29791401m6886521e2f536b3b@mail.gmail.com> On Mon, Jun 22, 2009 at 10:50 AM, Peter Fitzgibbons wrote: > Hello All, > Is there a way to Autospec "only" my features? Autospec is RSpec's thin wrapper that specifically enables running specs. If you don't want to run your specs, use the autotest command instead. > I know this is an anti-pattern. ?Just trying to auto-cycle while figuring > out some things with Cucumber. > Once I get the Cuke code ironed out, I'd happily return to correct > Rspec-Then-Cuke auto-cycling. > Thoughts? > Peter Fitzgibbons > (847) 687-7646 > Email: peter.fitzgibbons at gmail.com > IM GTalk: peter.fitzgibbons > IM Yahoo: pjfitzgibbons > IM MSN: pjfitzgibbons at hotmail.com > IM AOL: peter.fitzgibbons at gmail.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Jun 22 12:37:53 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 22 Jun 2009 11:37:53 -0500 Subject: [rspec-users] Where to put macros In-Reply-To: <88fd8ddc0906220928mddfb98au899e0fbfac3df7ac@mail.gmail.com> References: <88fd8ddc0906220928mddfb98au899e0fbfac3df7ac@mail.gmail.com> Message-ID: <57c63afe0906220937w6983d5b2u725747a6dfbd9ed5@mail.gmail.com> On Mon, Jun 22, 2009 at 11:28 AM, Andrew Premdas wrote: > Recently I got some wonderful help from the list to create my NamedAddress > module/macro which tests NamedAddresses for a number of different resources. > The question I have is where should I put this module? At the moment I've > got it in spec_helper, but this feels a bit messy > Many thanks > Andrew The convention that I see emerging is to keep macros, helpers, and any other spec supporting material in spec/support/macros, spec/support/matchers, etc. Then you do this in spec/spec_helper.rb: Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f} What would folks think if that was included in the generated spec_helper in spec-rails? Cheers, David From ben at benmabey.com Mon Jun 22 12:43:23 2009 From: ben at benmabey.com (Ben Mabey) Date: Mon, 22 Jun 2009 10:43:23 -0600 Subject: [rspec-users] Where to put macros In-Reply-To: <88fd8ddc0906220928mddfb98au899e0fbfac3df7ac@mail.gmail.com> References: <88fd8ddc0906220928mddfb98au899e0fbfac3df7ac@mail.gmail.com> Message-ID: On Jun 22, 2009, at 10:28 AM, Andrew Premdas wrote: > Recently I got some wonderful help from the list to create my > NamedAddress module/macro which tests NamedAddresses for a number of > different resources. > > The question I have is where should I put this module? At the moment > I've got it in spec_helper, but this feels a bit messy > > Many thanks > > Andrew > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Hey Andrew, I don't think there is a known convention for this. If I only use the macro for a single set of examples then I leave the macro code inline with the actual examples. Once I need it in multiple files then I will move it to my root spec dir. I suppose you could create a spec/ macros dir if you want (this would make it easier to require all of the ones you have). I generally don't have a whole lot so I just put my macros and matchers under spec/ and let spec_helper require them. Then in your spec helper if you want all of your examples to have access to these macros you can say: Spec::Runner.configure do |config| config.extend(MyMacro, MyOtherMacro) end HTH, Ben From ben at benmabey.com Mon Jun 22 12:44:42 2009 From: ben at benmabey.com (Ben Mabey) Date: Mon, 22 Jun 2009 10:44:42 -0600 Subject: [rspec-users] Where to put macros In-Reply-To: <57c63afe0906220937w6983d5b2u725747a6dfbd9ed5@mail.gmail.com> References: <88fd8ddc0906220928mddfb98au899e0fbfac3df7ac@mail.gmail.com> <57c63afe0906220937w6983d5b2u725747a6dfbd9ed5@mail.gmail.com> Message-ID: On Jun 22, 2009, at 10:37 AM, David Chelimsky wrote: > On Mon, Jun 22, 2009 at 11:28 AM, Andrew Premdas > wrote: >> Recently I got some wonderful help from the list to create my >> NamedAddress >> module/macro which tests NamedAddresses for a number of different >> resources. >> The question I have is where should I put this module? At the >> moment I've >> got it in spec_helper, but this feels a bit messy >> Many thanks >> Andrew > > The convention that I see emerging is to keep macros, helpers, and any > other spec supporting material in spec/support/macros, > spec/support/matchers, etc. Then you do this in spec/spec_helper.rb: > > Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f} > > What would folks think if that was included in the generated > spec_helper in spec-rails? Just as I said there was no written convention... :) I like it. +1 -Ben From sfeley at gmail.com Mon Jun 22 13:55:54 2009 From: sfeley at gmail.com (Stephen Eley) Date: Mon, 22 Jun 2009 13:55:54 -0400 Subject: [rspec-users] Where to put macros In-Reply-To: <57c63afe0906220937w6983d5b2u725747a6dfbd9ed5@mail.gmail.com> References: <88fd8ddc0906220928mddfb98au899e0fbfac3df7ac@mail.gmail.com> <57c63afe0906220937w6983d5b2u725747a6dfbd9ed5@mail.gmail.com> Message-ID: <1fb4df0906221055p9d0ffa8o7971f4ab767716b6@mail.gmail.com> On Mon, Jun 22, 2009 at 12:37 PM, David Chelimsky wrote: > > The convention that I see emerging is to keep macros, helpers, and any > other spec supporting material in spec/support/macros, > spec/support/matchers, etc. +1 from me too. I've been calling my directory spec/helpers, but I've been working on non-Rails projects lately and it only just now occurred to me that it would cause a name collision. >8-> > Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f} On a total non sequitur: has anyone ever come up with a clean, general syntactic sugar for cleaning up all of these ubiquitous File/Dir class methods and __FILE__ constants and other ugly filesystem machinery on requires? If no one knows of such a convenience, I might have to take a day or so and write something. Most of the rest of Ruby is so elegant and pretty that seeing this stuff at the top of every file hurts my eyes a bit. It's like getting a small static shock each time you settle into your comfortable luxury car. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From dchelimsky at gmail.com Mon Jun 22 13:57:54 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 22 Jun 2009 12:57:54 -0500 Subject: [rspec-users] Testing a FormBuilder In-Reply-To: <5a24fdec0906221053o537f017fv574968e1967cca07@mail.gmail.com> References: <5a24fdec0906221053o537f017fv574968e1967cca07@mail.gmail.com> Message-ID: <57c63afe0906221057q5817cb13g77a01292d6eaef96@mail.gmail.com> On Mon, Jun 22, 2009 at 12:53 PM, Peer Allan wrote: > Hello all, > In a bit of a conundrum here. ?I have a custom form builder I am trying to > test and can't seem to get it to work. ?I found this > http://www.pathf.com/blogs/2007/12/rspec-and-rails/ Things have changed a bit since Dec 07. The helper module is no longer included directly in the example group, but are exposed through a helper object instead. > which helps in that it > points me to the?HelperExampleGroup to get the @template methods I am going > to need. ?The problem is that we have our form builders in their own folder > (app/form_builders) and hence their own spec folder (spec/form_builders). > ?How can I get the specs in that folder (spec/form_builders) to behave like > they were helper tests so that I have access to the @template object? > Thanks > Peer describe "thing", :type => :helper do ... end Cheers, David From dchelimsky at gmail.com Mon Jun 22 15:31:56 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 22 Jun 2009 14:31:56 -0500 Subject: [rspec-users] Testing a FormBuilder In-Reply-To: <5a24fdec0906221207mbaf4fdawe78dd33aea3f9df3@mail.gmail.com> References: <5a24fdec0906221053o537f017fv574968e1967cca07@mail.gmail.com> <57c63afe0906221057q5817cb13g77a01292d6eaef96@mail.gmail.com> <5a24fdec0906221207mbaf4fdawe78dd33aea3f9df3@mail.gmail.com> Message-ID: <57c63afe0906221231u202848bg3a5954428ec4baaa@mail.gmail.com> On Mon, Jun 22, 2009 at 2:07 PM, Peer Allan wrote: > Still having trouble, here is my code. > Code: > class?MyFormBuilder?< ActionView::Helpers::FormBuilder > ??def custom_select(field_name, *args) > ?? ?field_name ||= :salutation > ?? ?salutations = > Lookup.for_type_and_column('Contact','salutation').map{|lookup| > lookup.description} > ?? ?select(field_name, salutations, :include_blank => true, :prompt => > "Please select salutation..") > ??end > end > Spec: > ??before(:each) do > ?? ?@object = mock_model(Company) > ?? ?@builder = MyFormBuilder.new(:company, @object, self, {}, nil) > ??end > > ??it "should return collection of currency codes" do > ??? @builder.custom_select(:salutation, {}) > ??end > No assertion in there, but it doesn't matter because I get this error: > private method `select' called for > # > I haven't had any success getting around this one, without stubbing beyond > recognition. ?Any ideas? This is what I was saying before - that you can't use self anymore because the helper module is not included in the current context. Instead, use the helper object: @builder = MyFormBuilder.new(:company, @object, helper, {}, nil) HTH, David > peer > On Mon, Jun 22, 2009 at 12:57 PM, David Chelimsky > wrote: >> >> On Mon, Jun 22, 2009 at 12:53 PM, Peer Allan >> wrote: >> > Hello all, >> > In a bit of a conundrum here. ?I have a custom form builder I am trying >> > to >> > test and can't seem to get it to work. ?I found this >> > http://www.pathf.com/blogs/2007/12/rspec-and-rails/ >> >> Things have changed a bit since Dec 07. The helper module is no longer >> included directly in the example group, but are exposed through a >> helper object instead. >> >> > which helps in that it >> > points me to the?HelperExampleGroup to get the @template methods I am >> > going >> > to need. ?The problem is that we have our form builders in their own >> > folder >> > (app/form_builders) and hence their own spec folder >> > (spec/form_builders). >> > ?How can I get the specs in that folder (spec/form_builders) to behave >> > like >> > they were helper tests so that I have access to the @template object? >> > Thanks >> > Peer >> >> describe "thing", :type => :helper do >> ?... >> end >> >> Cheers, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Jun 22 16:02:52 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 22 Jun 2009 15:02:52 -0500 Subject: [rspec-users] Testing a FormBuilder In-Reply-To: <5a24fdec0906221257v2800338am8400b3ce5cb63d01@mail.gmail.com> References: <5a24fdec0906221053o537f017fv574968e1967cca07@mail.gmail.com> <57c63afe0906221057q5817cb13g77a01292d6eaef96@mail.gmail.com> <5a24fdec0906221207mbaf4fdawe78dd33aea3f9df3@mail.gmail.com> <57c63afe0906221231u202848bg3a5954428ec4baaa@mail.gmail.com> <5a24fdec0906221257v2800338am8400b3ce5cb63d01@mail.gmail.com> Message-ID: <57c63afe0906221302q66754a1cy9e5b2c78b58ee676@mail.gmail.com> On Mon, Jun 22, 2009 at 2:57 PM, Peer Allan wrote: > Thanks David, I completely missed that in your first response. No problem. Let me know if it helps :) > Peer > > On Mon, Jun 22, 2009 at 2:31 PM, David Chelimsky > wrote: >> >> On Mon, Jun 22, 2009 at 2:07 PM, Peer Allan >> wrote: >> > Still having trouble, here is my code. >> > Code: >> > class?MyFormBuilder?< ActionView::Helpers::FormBuilder >> > ??def custom_select(field_name, *args) >> > ?? ?field_name ||= :salutation >> > ?? ?salutations = >> > Lookup.for_type_and_column('Contact','salutation').map{|lookup| >> > lookup.description} >> > ?? ?select(field_name, salutations, :include_blank => true, :prompt => >> > "Please select salutation..") >> > ??end >> > end >> > Spec: >> > ??before(:each) do >> > ?? ?@object = mock_model(Company) >> > ?? ?@builder = MyFormBuilder.new(:company, @object, self, {}, nil) >> > ??end >> > >> > ??it "should return collection of currency codes" do >> > ??? @builder.custom_select(:salutation, {}) >> > ??end >> > No assertion in there, but it doesn't matter because I get this error: >> > private method `select' called for >> > # >> > I haven't had any success getting around this one, without stubbing >> > beyond >> > recognition. ?Any ideas? >> >> This is what I was saying before - that you can't use self anymore >> because the helper module is not included in the current context. >> Instead, use the helper object: >> >> @builder = MyFormBuilder.new(:company, @object, helper, {}, nil) >> >> HTH, >> David >> >> > peer >> > On Mon, Jun 22, 2009 at 12:57 PM, David Chelimsky >> > wrote: >> >> >> >> On Mon, Jun 22, 2009 at 12:53 PM, Peer Allan >> >> wrote: >> >> > Hello all, >> >> > In a bit of a conundrum here. ?I have a custom form builder I am >> >> > trying >> >> > to >> >> > test and can't seem to get it to work. ?I found this >> >> > http://www.pathf.com/blogs/2007/12/rspec-and-rails/ >> >> >> >> Things have changed a bit since Dec 07. The helper module is no longer >> >> included directly in the example group, but are exposed through a >> >> helper object instead. >> >> >> >> > which helps in that it >> >> > points me to the?HelperExampleGroup to get the @template methods I am >> >> > going >> >> > to need. ?The problem is that we have our form builders in their own >> >> > folder >> >> > (app/form_builders) and hence their own spec folder >> >> > (spec/form_builders). >> >> > ?How can I get the specs in that folder (spec/form_builders) to >> >> > behave >> >> > like >> >> > they were helper tests so that I have access to the @template object? >> >> > Thanks >> >> > Peer >> >> >> >> describe "thing", :type => :helper do >> >> ?... >> >> end >> >> >> >> Cheers, >> >> David >> >> _______________________________________________ >> >> rspec-users mailing list >> >> rspec-users at rubyforge.org >> >> http://rubyforge.org/mailman/listinfo/rspec-users >> > >> > >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-users at rubyforge.org >> > http://rubyforge.org/mailman/listinfo/rspec-users >> > >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From stefan.kanev at gmail.com Mon Jun 22 17:18:17 2009 From: stefan.kanev at gmail.com (Stefan Kanev) Date: Tue, 23 Jun 2009 00:18:17 +0300 Subject: [rspec-users] Where to put macros In-Reply-To: <57c63afe0906220937w6983d5b2u725747a6dfbd9ed5@mail.gmail.com> References: <88fd8ddc0906220928mddfb98au899e0fbfac3df7ac@mail.gmail.com> <57c63afe0906220937w6983d5b2u725747a6dfbd9ed5@mail.gmail.com> Message-ID: <285b75bb0906221418m260d8196x6684566c3f81cee6@mail.gmail.com> On Mon, Jun 22, 2009 at 7:37 PM, David Chelimsky wrote: > On Mon, Jun 22, 2009 at 11:28 AM, Andrew Premdas > wrote:What would folks think if that was included in the generated > spec_helper in spec-rails? > I, while not a regular patron in this mailing list, +1 this too. It would be very nice if the autogenerated Rails files specify a conventional place to put macros/matchers. I would have a lot lower psychological barrier to adding few of those in my Rails applications. -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony.h.burns at gmail.com Mon Jun 22 17:36:56 2009 From: anthony.h.burns at gmail.com (Anthony Burns) Date: Tue, 23 Jun 2009 00:36:56 +0300 Subject: [rspec-users] Expected output matches rendered output but still getting error in view spec Message-ID: <4A3FF978.6000504@dirtyalpaca.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all, I've just gotten started using BDD with RSpec/Cucumber/Webrat and Rails and I've run into some frustration trying to get my view spec to pass. First of all, I am running Ruby 1.9.1p129 with Rails 2.3.2, RSpec and RSpec-Rails 1.2.6, Cucumber 0.3.11, and Webrat 0.4.4. Here is the code relevant to my question config/routes.rb: map.b_posts 'backend/posts', :controller => 'backend/ posts', :action => 'backend_index', :conditions => { :method => :get } map.connect 'backend/posts', :controller => 'backend/ posts', :action => 'create', :conditions => { :method => :post } views/backend/posts/create.html.erb: <% form_tag do %> <% end %> *spec/views/backend/posts/create.html.erb_spec.rb:* describe "backend/posts/create.html.erb" do it "should render a form to create a post" do render "backend/posts/create.html.erb" response.should have_selector("form", :method => 'post', :action => b_posts_path) do |form| # Nothing here yet. end end end Here is the relevant part of the output when I run script/spec: 'backend/posts/create.html.erb should render a form to create a post' FAILED expected following output to contain a
tag:
It would appear to me that what have_selector is looking for is exactly what the template generates, yet the example still fails. I am very much looking forward to seeing my error (because I have a feeling it is my error). Any help is much appreciated! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAko/+XMACgkQaSfff6Oi7PgTrACfdLx7gDTgYZUT8vc+CVuzuSVg JoUAnRuSVqaM2Ag4orIQAv3gAZpqrDB7 =G8v7 -----END PGP SIGNATURE----- From pj at crushlovely.com Mon Jun 22 18:19:56 2009 From: pj at crushlovely.com (PJ Kelly) Date: Mon, 22 Jun 2009 15:19:56 -0700 (PDT) Subject: [rspec-users] Spec'ing the result of rescue_from Message-ID: Hey All, In my app, I have actions that are restricted to only POST requests in config/routes.rb. We were getting a fair number of MethodNotAllowed errors on these actions. In most cases, we're ok with sending the user back to the homepage, however there are a few exceptions where we'd like to send them a specific action. My spec looks like this: describe "GET process_step_2" do it "should redirect to step_2" do rescue_action_in_public! get :process_step_2 response.should redirect_to(application_step_2_url) end end Then my application controller, I decided to rescue_from, so it looks like this: class ApplicationController < ActionController::Base rescue_from ActionController::MethodNotAllowed, :with => :invalid_method protected def invalid_method redirect_to previous_step_url end def previous_step_url case request.env["REQUEST_URI"] when /step_2\/process/ application_step_2_url else root_url end end end The spec fails even though when you re-create the situation in the browser, the code works. What am I doing wrong here? Am I even going about this in the right way? Thanks in advance for your help. Best, PJ From dchelimsky at gmail.com Mon Jun 22 18:43:14 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 22 Jun 2009 17:43:14 -0500 Subject: [rspec-users] Spec'ing the result of rescue_from In-Reply-To: References: Message-ID: <57c63afe0906221543x1068deeehe035cc35ee2499da@mail.gmail.com> On Mon, Jun 22, 2009 at 5:19 PM, PJ Kelly wrote: > Hey All, > > In my app, I have actions that are restricted to only POST requests in > config/routes.rb. ?We were getting a fair number of MethodNotAllowed > errors on these actions. ?In most cases, we're ok with sending the > user back to the homepage, however there are a few exceptions where > we'd like to send them a specific action. ?My spec looks like this: > > ?describe "GET process_step_2" do > ? ?it "should redirect to step_2" do > ? ? ?rescue_action_in_public! > ? ? ?get :process_step_2 > ? ? ?response.should redirect_to(application_step_2_url) > ? ?end > ?end > > Then my application controller, I decided to rescue_from, so it looks > like this: > > class ApplicationController < ActionController::Base > ?rescue_from ActionController::MethodNotAllowed, :with > => :invalid_method > > ?protected > > ?def invalid_method > ? ?redirect_to previous_step_url > ?end > > ?def previous_step_url > ? ?case request.env["REQUEST_URI"] > ? ?when /step_2\/process/ > ? ? ?application_step_2_url > ? ?else > ? ? ?root_url > ? ?end > ?end > end > > The spec fails even though when you re-create the situation in the > browser, the code works. What's the failure message? > > What am I doing wrong here? ?Am I even going about this in the right > way? > > Thanks in advance for your help. > > Best, PJ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Jun 22 22:21:32 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 22 Jun 2009 21:21:32 -0500 Subject: [rspec-users] [ANN] rspec 1.2.7 Released Message-ID: <57c63afe0906221921j35f3926brd7a6f377d069c3@mail.gmail.com> rspec-1.2.7 has been released! * * * * * Behaviour Driven Development for Ruby. Changes: ### Version 1.2.7 / 2009-06-22 * enhancments * added support for fakes using obj.stub(:method) { # implementation } * allow subject { self } (Jarmo Pertman). Closes #816. * friendly error message when a matcher returns nil on a failure message * add ruby_cmd option to SpecTask (Rick DeNatale). Closes #823. * also added missing specs for SpecTask - thanks Rick! * add support for generating matchers with fluent interfaces with the Matcher DSL * bug fixes * NegativeOperatorMatcher now returns false (Wesley Beary). Closes #812. * derive MockExpectationError from Exception rather than StandardError (Kerry Buckley). Closes #830. * fix bug where multi-line failure messages weren't getting picked up by autotest (Jarmo Pertman). Closes #832. * --line_number now works for it { should xxx } format (assist from Fred Lee) * warn instead of raise when there is no description supplied for an example. Closes #840. * * * * * From dchelimsky at gmail.com Mon Jun 22 22:21:40 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 22 Jun 2009 21:21:40 -0500 Subject: [rspec-users] [ANN] rspec-rails 1.2.7 Released Message-ID: <57c63afe0906221921x7b874e0fs813b172a4675af97@mail.gmail.com> rspec-rails-1.2.7 has been released! Behaviour Driven Development for Ruby on Rails. Changes: ### Version 1.2.7 / 2009-06-22 * enhancements * alias :stub!, :stub so rspec-rails extensions of rspec stubs can use the same syntax as rspec (core) * integration specs (Ben Mabey and David Chelimsky) * added support for references and belongs_to generated model specs (Jos? Valim). Closes #792. * add discovery for autotest-rails to keep compatible with ZenTest-4.0.0 (Ryan Davis). Closes #838. * controller specs in isolation mode don't care whether the file exists anymore! * bug fixes * allow rspec-rails to work without ActiveRecord. Closes #810. * fix bug with have() matcher failure message (Dave Giunta). Closes #818. * fix bug where render_template('new') would pass if 'newer' was rendered (or anything that started with 'new') * deprecations * spec_server is now deprecated - use spork instead (gem install spork). Closes #827. * * * * * From dchelimsky at gmail.com Tue Jun 23 01:16:51 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 23 Jun 2009 00:16:51 -0500 Subject: [rspec-users] [ANN] rspec-rails 1.2.7 Released In-Reply-To: <57c63afe0906221921x7b874e0fs813b172a4675af97@mail.gmail.com> References: <57c63afe0906221921x7b874e0fs813b172a4675af97@mail.gmail.com> Message-ID: <57c63afe0906222216p2a62cf68i4a311d8399e1d44e@mail.gmail.com> I just pushed 1.2.7.1 to fix a bug in "script/generate rspec". Please use this instead of the 1.2.7 gem. Cheers, David On Mon, Jun 22, 2009 at 9:21 PM, David Chelimsky wrote: > rspec-rails-1.2.7 has been released! > > Behaviour Driven Development for Ruby on Rails. > > Changes: > > ### Version 1.2.7 / 2009-06-22 > > * enhancements > ?* alias :stub!, :stub so rspec-rails extensions of rspec stubs can use the > ? ?same syntax as rspec (core) > ?* integration specs (Ben Mabey and David Chelimsky) > ?* added support for references and belongs_to generated model specs (Jos? > ? ?Valim). Closes #792. > ?* add discovery for autotest-rails to keep compatible with ZenTest-4.0.0 > ? ?(Ryan Davis). Closes #838. > ?* controller specs in isolation mode don't care whether the file exists > ? ?anymore! > > * bug fixes > ?* allow rspec-rails to work without ActiveRecord. Closes #810. > ?* fix bug with have() matcher failure message (Dave Giunta). Closes #818. > ?* fix bug where render_template('new') would pass if 'newer' was rendered > ? ?(or anything that started with 'new') > > * deprecations > ?* spec_server is now deprecated - use spork instead (gem install spork). > ? ?Closes #827. > > * > * > * > * > * > From lists at ruby-forum.com Tue Jun 23 05:12:00 2009 From: lists at ruby-forum.com (Tom Hoen) Date: Tue, 23 Jun 2009 11:12:00 +0200 Subject: [rspec-users] any idea why spec_server gets 'cannot remove Object' error? Message-ID: <7df13a180210246a40d87100c25a9e7d@ruby-forum.com> I am sure better minds than mine can figure this out, but I am stumped. When I run any spec using spec_server, a get 0 failures and the command prompt returns without issue. If I run the same spec again, I still get 0 failures, but it concludes with the following error: (druby://127.0.0.1:8989) c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:603:in `remove_const': Cannot remove Object::ClassMethods (NameError) from (druby://127.0.0.1:8989) c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:603:in `remove_constant' from (druby://127.0.0.1:8989) c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:603:in `instance_eval' from (druby://127.0.0.1:8989) c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:603:in `remove_constant' from (druby://127.0.0.1:8989) c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:450:in `remove_unloadable_constants!' from (druby://127.0.0.1:8989) c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:450:in `each' from (druby://127.0.0.1:8989) c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:450:in `remove_unloadable_constants!' from (druby://127.0.0.1:8989) c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:236:in `clear' from (druby://127.0.0.1:8989) c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:65:in `cleanup_application' from (druby://127.0.0.1:8989) c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-rails-1.2.6/lib/spec/rails/spec_server.rb:106:in `run' from c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/drb_command_line.rb:14:in `run' from c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/option_parser.rb:193:in `parse_drb' from c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/option_parser.rb:130:in `order!' from c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner.rb:51:in `options' from c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/command_line.rb:6:in `run' from c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/bin/spec:4 from c:/InstantRails-2.0-win/ruby/bin/spec:19:in `load' from c:/InstantRails-2.0-win/ruby/bin/spec:19 running the spec a third time, most of my tests fail with the following sample error: TypeError in 'School can add staff_members' can't dup NilClass If I kill the spec_server, restart it, the cycle begins again. Previously, spec server ran without issue, using individual I am running: rspec and rspec on rails 1.2.6 Rails 2.3.2 ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] Windows Vista Any thoughts would be greatly appreciated. Tom -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Jun 23 10:19:02 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 23 Jun 2009 09:19:02 -0500 Subject: [rspec-users] any idea why spec_server gets 'cannot remove Object' error? In-Reply-To: <7df13a180210246a40d87100c25a9e7d@ruby-forum.com> References: <7df13a180210246a40d87100c25a9e7d@ruby-forum.com> Message-ID: <57c63afe0906230719t211872abm67200c5aa1d22d5c@mail.gmail.com> On Tue, Jun 23, 2009 at 4:12 AM, Tom Hoen wrote: > I am sure better minds than mine can figure this out, but I am stumped. > > When I run any spec using spec_server, a get 0 failures and the command > prompt returns without issue. > > If I run the same spec again, I still get 0 failures, but it concludes > with the following error: > > (druby://127.0.0.1:8989) > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:603:in > `remove_const': Cannot remove Object::ClassMethods (NameError) > ? ? ? ?from (druby://127.0.0.1:8989) > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:603:in > `remove_constant' > ? ? ? ?from (druby://127.0.0.1:8989) > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:603:in > `instance_eval' > ? ? ? ?from (druby://127.0.0.1:8989) > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:603:in > `remove_constant' > ? ? ? ?from (druby://127.0.0.1:8989) > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:450:in > `remove_unloadable_constants!' > ? ? ? ?from (druby://127.0.0.1:8989) > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:450:in > `each' > ? ? ? ?from (druby://127.0.0.1:8989) > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:450:in > `remove_unloadable_constants!' > ? ? ? ?from (druby://127.0.0.1:8989) > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:236:in > `clear' > ? ? ? ?from (druby://127.0.0.1:8989) > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:65:in > `cleanup_application' > ? ? ? ?from (druby://127.0.0.1:8989) > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-rails-1.2.6/lib/spec/rails/spec_server.rb:106:in > `run' > ? ? ? ?from > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/drb_command_line.rb:14:in > `run' > ? ? ? ?from > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/option_parser.rb:193:in > `parse_drb' > ? ? ? ?from > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/option_parser.rb:130:in > `order!' > ? ? ? ?from > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner.rb:51:in > `options' > ? ? ? ?from > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/command_line.rb:6:in > `run' > ? ? ? ?from > c:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/bin/spec:4 > ? ? ? ?from c:/InstantRails-2.0-win/ruby/bin/spec:19:in `load' > ? ? ? ?from c:/InstantRails-2.0-win/ruby/bin/spec:19 > > > running the spec a third time, most of my tests fail with the following > sample error: > TypeError in 'School can add staff_members' > can't dup NilClass > > If I kill the spec_server, restart it, the cycle begins again. > > Previously, spec server ran without issue, using individual Previously to what? What changed? Also - just a heads up that spec_server is deprecated in 1.2.7 and will be removed in 1.2.8. I prefer to avoid removing things in point releases, but spec_server has been problematic (behaving very differently for a lot of different environments and configurations), and Tim Harper's new spork gem [1] serves the same purpose in a very elegant way, so the migration path is simple. gem install spork cd path/to/project spork bootstrap --rspec # edit spec/spec_helper.rb You may have better luck if you migrate now. Cheers, David [1] http://github.com/timcharper/spork > > I am running: > rspec and rspec on rails 1.2.6 > Rails 2.3.2 > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] > Windows Vista > > Any thoughts would be greatly appreciated. > > Tom > -- > 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 Tue Jun 23 10:38:21 2009 From: lists at ruby-forum.com (Tom Hoen) Date: Tue, 23 Jun 2009 16:38:21 +0200 Subject: [rspec-users] any idea why spec_server gets 'cannot remove Object' error? In-Reply-To: <57c63afe0906230719t211872abm67200c5aa1d22d5c@mail.gmail.com> References: <7df13a180210246a40d87100c25a9e7d@ruby-forum.com> <57c63afe0906230719t211872abm67200c5aa1d22d5c@mail.gmail.com> Message-ID: David - Thank you for responding. > > Previously to what? What changed? > The only changes were some additional models/controllers and specs for both, and I installed and used (in one of the models) open_ssl. My plan it to revert until I find a point at which things start to work again, unless someone has a better idea. > > gem install spork > cd path/to/project > spork bootstrap --rspec > # edit spec/spec_helper.rb > Alas, I develop on Windows. So no spork. As of yet. Thanks for your advice. Tom -- Posted via http://www.ruby-forum.com/. From mbread at m-bread.com Tue Jun 23 11:24:34 2009 From: mbread at m-bread.com (mBread) Date: Tue, 23 Jun 2009 08:24:34 -0700 (PDT) Subject: [rspec-users] Asynchronous requests (effectively in multiple browser windows) Message-ID: <24167319.post@talk.nabble.com> Hi. I'm using cucumber on a rails app along with rspec & webrat. Is there any way in cucumber to write scenarios that would use more than one window in an equivalent manual test? I am wanting to write a feature scenario for this manual test: log in, load up a form that it only visible to logged in users, log out in a different window, then submit the form in the original window. is this possible, and should it be in cucumber that I am testing this, or is it a lower-level test? Thanks, mBread -- View this message in context: http://www.nabble.com/Asynchronous-requests-%28effectively-in-multiple-browser-windows%29-tp24167319p24167319.html Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Tue Jun 23 13:34:31 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 23 Jun 2009 12:34:31 -0500 Subject: [rspec-users] Asynchronous requests (effectively in multiple browser windows) In-Reply-To: <24167319.post@talk.nabble.com> References: <24167319.post@talk.nabble.com> Message-ID: <57c63afe0906231034i1a2068eudff40501e7543ee3@mail.gmail.com> On Tue, Jun 23, 2009 at 10:24 AM, mBread wrote: > > Hi. I'm using cucumber on a rails app along with rspec & webrat. Is there any > way in cucumber to write scenarios that would use more than one window in an > equivalent manual test? > > I am wanting to write a feature scenario for this manual test: log in, load > up a form that it only visible to logged in users, log out in a different > window, then submit the form in the original window. is this possible, and > should it be in cucumber that I am testing this, or is it a lower-level > test? Cucumber has its own group now. Please post this to http://groups.google.com/group/cukes Cheers, David > > Thanks, > mBread > -- > View this message in context: http://www.nabble.com/Asynchronous-requests-%28effectively-in-multiple-browser-windows%29-tp24167319p24167319.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pj at crushlovely.com Tue Jun 23 14:27:17 2009 From: pj at crushlovely.com (PJ Kelly) Date: Tue, 23 Jun 2009 11:27:17 -0700 (PDT) Subject: [rspec-users] Spec'ing the result of rescue_from In-Reply-To: <57c63afe0906221543x1068deeehe035cc35ee2499da@mail.gmail.com> References: <57c63afe0906221543x1068deeehe035cc35ee2499da@mail.gmail.com> Message-ID: <7327761d-2709-4cd6-9c7f-ad337fe5bb23@q3g2000pra.googlegroups.com> Hi David, thanks for the speedy response yesterday. Much appreciated. On Jun 22, 3:43?pm, David Chelimsky wrote: > What's the failure message? 'MembersController GET process_step_2 should redirect to step_2' FAILED expected redirect to "http://test.host/application/step_2", got no redirect I did some more digging, and found a couple things. When I try this in the browser (by visiting /application/step_2/process) and look at the development log, the request is actually being made to ApplicationController#index: Processing ApplicationController#index (for 127.0.0.1 at 2009-06-23 11:08:18) [GET] Redirected to http://byassociation.local/application/step_2 However when the specs are run, the test log shows: Processing MembersController#process_step_2 (for 208.77.188.166 at 2009-06-23 11:19:50) [GET] I guess the question then, is that if this is how things are handled when using rescue_from, how do I spec out that users are being redirected to the right location? Do you think the inconsistency between the development test logs needs to be brought up with Rails core? Thanks in advance! Best, PJ From joe at pinkpucker.net Tue Jun 23 18:15:05 2009 From: joe at pinkpucker.net (Joe Van Dyk) Date: Tue, 23 Jun 2009 15:15:05 -0700 Subject: [rspec-users] html::document errors Message-ID: And Joe should see a radio button representing the answer 'OJ' # features/step_definitions/trat_steps.rb:111 uninitialized constant HTML::Document (NameError) /home/joe/projects/cisv/vendor/plugins/rspec/lib/spec/matchers/method_missing.rb:6:in `method_missing' /home/joe/projects/cisv/vendor/plugins/rspec-rails/lib/spec/rails/matchers/assert_select.rb:25:in `__send__' /home/joe/projects/cisv/vendor/plugins/rspec-rails/lib/spec/rails/matchers/assert_select.rb:25:in `matches?' /home/joe/projects/cisv/vendor/plugins/rspec/lib/spec/expectations/handler.rb:11:in `handle_matcher' /home/joe/projects/cisv/vendor/plugins/rspec/lib/spec/expectations/extensions/kernel.rb:27:in `should' ./features/step_definitions/trat_steps.rb:113:in `/should see a radio button representing the answer '(.*)'/' features/trat/taking/answer_sheet.feature:53:in `And Joe should see a radio button representing the answer 'OJ'' Any ideas? Where's HTML::Document supposed to be defined? Joe From joe at pinkpucker.net Tue Jun 23 18:43:15 2009 From: joe at pinkpucker.net (Joe Van Dyk) Date: Tue, 23 Jun 2009 15:43:15 -0700 Subject: [rspec-users] html::document errors In-Reply-To: References: Message-ID: Oh, latest version of rspec and rspec-rails installed as a plugin. On Tue, Jun 23, 2009 at 3:15 PM, Joe Van Dyk wrote: > ? ?And Joe should see a radio button representing the answer 'OJ' > ?# features/step_definitions/trat_steps.rb:111 > ? ? ?uninitialized constant HTML::Document (NameError) > ? ? ?/home/joe/projects/cisv/vendor/plugins/rspec/lib/spec/matchers/method_missing.rb:6:in > `method_missing' > ? ? ?/home/joe/projects/cisv/vendor/plugins/rspec-rails/lib/spec/rails/matchers/assert_select.rb:25:in > `__send__' > ? ? ?/home/joe/projects/cisv/vendor/plugins/rspec-rails/lib/spec/rails/matchers/assert_select.rb:25:in > `matches?' > ? ? ?/home/joe/projects/cisv/vendor/plugins/rspec/lib/spec/expectations/handler.rb:11:in > `handle_matcher' > ? ? ?/home/joe/projects/cisv/vendor/plugins/rspec/lib/spec/expectations/extensions/kernel.rb:27:in > `should' > ? ? ?./features/step_definitions/trat_steps.rb:113:in `/should see a > radio button representing the answer '(.*)'/' > ? ? ?features/trat/taking/answer_sheet.feature:53:in `And Joe should > see a radio button representing the answer 'OJ'' > > > Any ideas? ?Where's HTML::Document supposed to be defined? > > Joe > From dchelimsky at gmail.com Tue Jun 23 20:15:17 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 23 Jun 2009 19:15:17 -0500 Subject: [rspec-users] spec_server is dead! Long live spork! Message-ID: <57c63afe0906231715t53f3331cn67fada3c7dda3efa@mail.gmail.com> Hey all, Just a heads up that the rspec-rails-1.2.7.1 release deprecates spec_server in favor of Tim Harper's spork gem. http://github.com/timcharper/spork I've already removed spec_server from the rspec-rails git repo, so it will no longer be part of the rspec-rails gem beginning with the next release. I understand that this presents a conundrum for folks on Windows, as there is no spork love for Windows just yet. To that end, I've posted the spec_server to its own repo on github: http://github.com/dchelimsky/spec_server As the readme suggests, I do not plan to maintain this. It is posted solely for the purpose of making it easily accessible for those who want to (or don't have other options yet) continue to use it. Admittedly, I didn't go very far to make it a single command install or a gem, so if anybody cares to take that on I'm sure it would be appreciated by many. Cheers, David From brian.takita at gmail.com Tue Jun 23 21:45:30 2009 From: brian.takita at gmail.com (Brian Takita) Date: Tue, 23 Jun 2009 18:45:30 -0700 Subject: [rspec-users] spec_server is dead! Long live spork! In-Reply-To: <57c63afe0906231715t53f3331cn67fada3c7dda3efa@mail.gmail.com> References: <57c63afe0906231715t53f3331cn67fada3c7dda3efa@mail.gmail.com> Message-ID: <1d7ddd110906231845n4eb7b38fsa17718d50d8ff548@mail.gmail.com> Huhzah! On Tue, Jun 23, 2009 at 5:15 PM, David Chelimsky wrote: > Hey all, > > Just a heads up that the rspec-rails-1.2.7.1 release deprecates > spec_server in favor of Tim Harper's spork gem. > > ?http://github.com/timcharper/spork > > I've already removed spec_server from the rspec-rails git repo, so it > will no longer be part of the rspec-rails gem beginning with the next > release. I understand that this presents a conundrum for folks on > Windows, as there is no spork love for Windows just yet. To that end, > I've posted the spec_server to its own repo on github: > > ?http://github.com/dchelimsky/spec_server > > As the readme suggests, I do not plan to maintain this. It is posted > solely for the purpose of making it easily accessible for those who > want to (or don't have other options yet) continue to use it. > Admittedly, I didn't go very far to make it a single command install > or a gem, so if anybody cares to take that on I'm sure it would be > appreciated by many. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From yoann.zimero at gmail.com Tue Jun 23 21:13:57 2009 From: yoann.zimero at gmail.com (Yoann-Z) Date: Tue, 23 Jun 2009 18:13:57 -0700 (PDT) Subject: [rspec-users] undefined method `blueprint' with rspec/machinist/faker Message-ID: <2ba73627-1b4d-439d-9927-ea2e23bd72ec@o5g2000prh.googlegroups.com> Hi, I just started using Machinist for my project. So I successfully installed notahat-machinist and faker gems and as soon as I run a spec I get the following error : /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ base.rb:1964:in `method_missing': undefined method `blueprint' for # (NoMethodError) Can you help me please? Thank you by advance. -Yoann-Z From lists at ruby-forum.com Wed Jun 24 08:58:24 2009 From: lists at ruby-forum.com (Tom Hoen) Date: Wed, 24 Jun 2009 14:58:24 +0200 Subject: [rspec-users] any idea why spec_server gets 'cannot remove Object' error? In-Reply-To: References: <7df13a180210246a40d87100c25a9e7d@ruby-forum.com> <57c63afe0906230719t211872abm67200c5aa1d22d5c@mail.gmail.com> Message-ID: Tom Hoen wrote: In order to suss out what might be cause, i modified the remove_constant method in the LoadingModule class '\ruby\lib\ruby\gems\1.8\gems\activesupport-2.3.2\lib\active_support\dependencies.rb', adding in begin/rescue/end statements. def remove_constant(const) #:nodoc: begin return false unless qualified_const_defined? const const = $1 if /\A::(.*)\Z/ =~ const.to_s names = const.to_s.split('::') if names.size == 1 # It's under Object parent = Object else parent = (names[0..-2] * '::').constantize end log "removing constant #{const}" parent.instance_eval { remove_const names.last } return true rescue log 'error when removing constant #{const}' end end This seems to allow the spec_server to operate properly, but I honestly don't know what repercussions it may cause. -- Posted via http://www.ruby-forum.com/. From yoann.zimero at gmail.com Wed Jun 24 13:35:41 2009 From: yoann.zimero at gmail.com (Yoann-Z) Date: Wed, 24 Jun 2009 10:35:41 -0700 (PDT) Subject: [rspec-users] undefined method `blueprint' with rspec/machinist/faker In-Reply-To: References: <2ba73627-1b4d-439d-9927-ea2e23bd72ec@o5g2000prh.googlegroups.com> Message-ID: Hi, Thank you for your reply. I found the answer elsewhere this morning. I had to require Machinist and Sham in the file blueprints.rb : require 'machinist/active_record' require 'sham' It works fine right now. Thank you very much -Yoann-Z From timcharper at gmail.com Wed Jun 24 19:06:25 2009 From: timcharper at gmail.com (Tim Harper) Date: Wed, 24 Jun 2009 17:06:25 -0600 Subject: [rspec-users] any idea why spec_server gets 'cannot remove Object' error? In-Reply-To: References: <7df13a180210246a40d87100c25a9e7d@ruby-forum.com> <57c63afe0906230719t211872abm67200c5aa1d22d5c@mail.gmail.com> Message-ID: There is no voting love on the windows feature request: http://github.com/timcharper/spork/issues :) On Tue, Jun 23, 2009 at 8:38 AM, Tom Hoen wrote: > David - Thank you for responding. > > > > > > > Previously to what? What changed? > > > > > The only changes were some additional models/controllers and specs for > both, and I installed and used (in one of the models) open_ssl. My plan > it to revert until I find a point at which things start to work again, > unless someone has a better idea. > > > > > > gem install spork > > cd path/to/project > > spork bootstrap --rspec > > # edit spec/spec_helper.rb > > > > Alas, I develop on Windows. So no spork. As of yet. > > Thanks for your advice. > Tom > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.denatale at gmail.com Wed Jun 24 19:54:35 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 24 Jun 2009 19:54:35 -0400 Subject: [rspec-users] Running RSpec under MultiRuby Message-ID: I just published a quick article showing how to use the patch I provided and David just release in RSpec 1.2.7 to run your specs using multiruby: http://talklikeaduck.denhaven2.com/2009/06/24/rspec-meet-multiruby -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From luislavena at gmail.com Wed Jun 24 20:18:28 2009 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 24 Jun 2009 21:18:28 -0300 Subject: [rspec-users] Running RSpec under MultiRuby In-Reply-To: References: Message-ID: <71166b3b0906241718o3e9a3afdvdafc61f2812c1bcb@mail.gmail.com> On Wed, Jun 24, 2009 at 8:54 PM, Rick DeNatale wrote: > I just published a quick article showing how to use the patch I > provided and David just release in RSpec 1.2.7 to run your specs using > multiruby: > > http://talklikeaduck.denhaven2.com/2009/06/24/rspec-meet-multiruby > Tried to leave you this comment: I have setup 'mr' as alias for multiruby, so I can do mr -S rake spec Which is going to produce the exact same results than your task (without inject system calls for which). Also, going with above example, this will work on Windows too, using Pik: pik run "rake spec" -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From rick.denatale at gmail.com Wed Jun 24 22:24:26 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 24 Jun 2009 22:24:26 -0400 Subject: [rspec-users] Running RSpec under MultiRuby In-Reply-To: <71166b3b0906241718o3e9a3afdvdafc61f2812c1bcb@mail.gmail.com> References: <71166b3b0906241718o3e9a3afdvdafc61f2812c1bcb@mail.gmail.com> Message-ID: On Wed, Jun 24, 2009 at 8:18 PM, Luis Lavena wrote: > On Wed, Jun 24, 2009 at 8:54 PM, Rick DeNatale wrote: >> I just published a quick article showing how to use the patch I >> provided and David just release in RSpec 1.2.7 to run your specs using >> multiruby: >> >> http://talklikeaduck.denhaven2.com/2009/06/24/rspec-meet-multiruby >> > > Tried to leave you this comment: > > I have setup 'mr' as alias for multiruby, so I can do > > mr -S rake spec As far as I can tell, this requires that you install rake in all the various multiruby setups. But the real reason I went the way I did was that it allows other rake tasks to depend on the multiruby rspec tasks without requiring ALL rake tests to run under multiruby. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From luislavena at gmail.com Thu Jun 25 00:15:32 2009 From: luislavena at gmail.com (Luis Lavena) Date: Thu, 25 Jun 2009 01:15:32 -0300 Subject: [rspec-users] Running RSpec under MultiRuby In-Reply-To: References: <71166b3b0906241718o3e9a3afdvdafc61f2812c1bcb@mail.gmail.com> Message-ID: <71166b3b0906242115w205df1f5u90e3bb134ab6a5@mail.gmail.com> On Wed, Jun 24, 2009 at 11:24 PM, Rick DeNatale wrote: > On Wed, Jun 24, 2009 at 8:18 PM, Luis Lavena wrote: >> On Wed, Jun 24, 2009 at 8:54 PM, Rick DeNatale wrote: >>> I just published a quick article showing how to use the patch I >>> provided and David just release in RSpec 1.2.7 to run your specs using >>> multiruby: >>> >>> http://talklikeaduck.denhaven2.com/2009/06/24/rspec-meet-multiruby >>> >> >> Tried to leave you this comment: >> >> I have setup 'mr' as alias for multiruby, so I can do >> >> mr -S rake spec > > As far as I can tell, this requires that you install rake in all the > various multiruby setups. > Yes, but that should be true for environment isolation since different versions of ruby behave in different ways, add to the mix the Gems and you have a Molotov coctail on your hands ;-) But you can use multiruby_setup rubygems:merge Which should symlink the rubygems installations of your different ruby versions and get those shared. (beware of gems with native extensions and having ruby 1.8 and 1.9 with multiruby). > But the real reason I went the way I did was that it allows other rake > tasks to depend on the multiruby rspec tasks without requiring ALL > rake tests to run under multiruby. But that is kind of cheating. Let say I have only 1.9 on my system, I checkout a project and try to get the list of task of that project with rake -T Now, since I was not testing 100% against Ruby 1.9, I never found that one of the gems I depend on (let's say Hoe) was not 1.9 compatible. Then I get people complaining about my project not working with Ruby 1.9... but "it worked on my computer" you would say. Anyhow, different approaches I believe, and in any case, is good to know that RSpec now supports setting the ruby interpreter and not leveraging on RUBY definition itself. Thank you for the patch. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From lists at ruby-forum.com Thu Jun 25 07:03:44 2009 From: lists at ruby-forum.com (Tom Hoen) Date: Thu, 25 Jun 2009 13:03:44 +0200 Subject: [rspec-users] any idea why spec_server gets 'cannot remove Object' error? In-Reply-To: References: <7df13a180210246a40d87100c25a9e7d@ruby-forum.com> <57c63afe0906230719t211872abm67200c5aa1d22d5c@mail.gmail.com> Message-ID: Tim Harper wrote: > There is no voting love on the windows feature request: > > http://github.com/timcharper/spork/issues > :) I tried to vote a +1, but get this after clicking the Comment button: There was a problem serving the requested page. Now you're wondering, "what can I do about it!?!". Well... Have you heard of anyone that has rspec/spork/cucumber etc running under cygwin, colinux, andLinux, or Ulteo Virtual Desktop. Do any of them allow for fork? -- Posted via http://www.ruby-forum.com/. From rick.denatale at gmail.com Thu Jun 25 12:13:09 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 25 Jun 2009 12:13:09 -0400 Subject: [rspec-users] Running RSpec under MultiRuby In-Reply-To: <71166b3b0906242115w205df1f5u90e3bb134ab6a5@mail.gmail.com> References: <71166b3b0906241718o3e9a3afdvdafc61f2812c1bcb@mail.gmail.com> <71166b3b0906242115w205df1f5u90e3bb134ab6a5@mail.gmail.com> Message-ID: On Thu, Jun 25, 2009 at 12:15 AM, Luis Lavena wrote: > On Wed, Jun 24, 2009 at 11:24 PM, Rick DeNatale wrote: >> On Wed, Jun 24, 2009 at 8:18 PM, Luis Lavena wrote: >>> On Wed, Jun 24, 2009 at 8:54 PM, Rick DeNatale wrote: >> But the real reason I went the way I did was that it allows other rake >> tasks to depend on the multiruby rspec tasks without requiring ALL >> rake tests to run under multiruby. > > But that is kind of cheating. > > Let say I have only 1.9 on my system, I checkout a project and try to > get the list of task of that project with rake -T > > Now, since I was not testing 100% against Ruby 1.9, I never found that > one of the gems I depend on (let's say Hoe) was not 1.9 compatible. I think that hoe is a good example of when 1.9 compatibility is optional. Hoe is only used to deploy the gem to rubyforge... It doesn't affect the compatibility of the gem being released. And the rake tasks I'm thinking of are things like having a deploy/publish task which pre-regs running the specs for the thing being deployed and making sure they run under multiruby as a pre-req to deployment/publication. I this case you want to be able to run only the specs under multiruby, not the whole deployment/publication task, which would (try) to deploy/publish 2/3/4 times depending on how many ruby installations you have set up for multiruby. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From marekj.com at gmail.com Thu Jun 25 15:47:30 2009 From: marekj.com at gmail.com (marekj) Date: Thu, 25 Jun 2009 14:47:30 -0500 Subject: [rspec-users] When spec/test/unit is used then TestUnit Console Runner.run TestCase does not run testcases Message-ID: Hi, I have some old test/unit testcases (used for browser acceptance tests) that I want to convert to rspec. I first started converting assertions to matchers and my tests ran fine using TestRunner.run method 1) Here is my test that works when Spec::Matchers were added to TestUnit only require 'test/unit' require 'spec/expectations' class Test::Unit::TestCase include Spec::Matchers end class Test_spec < Test::Unit::TestCase def test_a 'a'.should == 'a' end end # TestRunner require 'test/unit/ui/console/testrunner' puts "before runner some code" Test::Unit::UI::Console::TestRunner.run Test_spec puts "after runner some code" The reason I use TestRunner is for some browser driving and desktop cleanup and other non test stuff. Then console runner runs testcase and I follow with some other code (email, notifications etc...) When I now started using 'spec/test/unit' the Console runner will not run tests. 2) here is the setup with 'spec/test/unit' that does not run require 'spec/test/unit' class Test_spec < Test::Unit::TestCase def test_a 'a'.should == 'a' end end # This now will not run Test_spec class require 'test/unit/ui/console/testrunner' puts "before runner" Test::Unit::UI::Console::TestRunner.run Test_spec puts "after runner" == I use rspec 1.2.7 (with Ruby 1.8.6 on Windows) Am I missing something? I would appreciate feedback Thanks. marekj Watirloo: Semantic Page Objects in UseCases http://github.com/marekj/watirloo/ From dchelimsky at gmail.com Thu Jun 25 15:55:23 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Jun 2009 14:55:23 -0500 Subject: [rspec-users] When spec/test/unit is used then TestUnit Console Runner.run TestCase does not run testcases In-Reply-To: References: Message-ID: <57c63afe0906251255k38306e2aj8a6b88d7c60ca6eb@mail.gmail.com> On Thu, Jun 25, 2009 at 2:47 PM, marekj wrote: > Hi, I have some old test/unit testcases (used for browser acceptance > tests) that I want to convert to rspec. > I first started converting assertions to matchers ?and my tests ran > fine using TestRunner.run method > > 1) Here is my test that works when Spec::Matchers were added to TestUnit only > > require 'test/unit' > require 'spec/expectations' > class Test::Unit::TestCase > ?include Spec::Matchers > end > > class Test_spec < Test::Unit::TestCase > ?def test_a > ? ?'a'.should == 'a' > ?end > end > > # TestRunner > require 'test/unit/ui/console/testrunner' > puts "before runner some code" > Test::Unit::UI::Console::TestRunner.run Test_spec > puts "after runner some code" > > The reason I use TestRunner is for some browser driving and desktop > cleanup and other non test stuff. > Then console runner runs testcase and I follow with some other code > (email, notifications etc...) > > When I now started using 'spec/test/unit' the Console runner will not run tests. > > 2) here is the setup with 'spec/test/unit' that does not run > > require 'spec/test/unit' > class Test_spec < Test::Unit::TestCase > ?def test_a > ? ?'a'.should == 'a' > ?end > end > > # This now will not run Test_spec class > require 'test/unit/ui/console/testrunner' > puts "before runner" > Test::Unit::UI::Console::TestRunner.run Test_spec > puts "after runner" > > > == I use rspec 1.2.7 (with Ruby 1.8.6 on Windows) > > > Am I missing something? This is by design. When you run with RSpec, RSpec takes over the run, taking test/unit's runner out of the picture. Sorry I can't give you a better answer, except to say that future versions of RSpec may not suffer this problem. But that's a few months off (at least), and just a gleam in my eye. Cheers, David > I would appreciate feedback > Thanks. > > > > marekj > > Watirloo: Semantic Page Objects in UseCases > http://github.com/marekj/watirloo/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From marekj.com at gmail.com Thu Jun 25 16:14:16 2009 From: marekj.com at gmail.com (marekj) Date: Thu, 25 Jun 2009 15:14:16 -0500 Subject: [rspec-users] When spec/test/unit is used then TestUnit Console Runner.run TestCase does not run testcases In-Reply-To: <57c63afe0906251255k38306e2aj8a6b88d7c60ca6eb@mail.gmail.com> References: <57c63afe0906251255k38306e2aj8a6b88d7c60ca6eb@mail.gmail.com> Message-ID: On Thu, Jun 25, 2009 at 2:55 PM, David Chelimsky wrote: > On Thu, Jun 25, 2009 at 2:47 PM, marekj wrote: >> Hi, I have some old test/unit testcases (used for browser acceptance >> tests) that I want to convert to rspec. >> I first started converting assertions to matchers ?and my tests ran >> fine using TestRunner.run method >> ...snip... >> >> 2) here is the setup with 'spec/test/unit' that does not run >> >> require 'spec/test/unit' >> class Test_spec < Test::Unit::TestCase >> ?def test_a >> ? ?'a'.should == 'a' >> ?end >> end >> >> # This now will not run Test_spec class >> require 'test/unit/ui/console/testrunner' >> puts "before runner" >> Test::Unit::UI::Console::TestRunner.run Test_spec >> puts "after runner" >> >> >> Am I missing something? > > This is by design. When you run with RSpec, RSpec takes over the run, > taking test/unit's runner out of the picture. Sorry I can't give you a > better answer, except to say that future versions of RSpec may not > suffer this problem. But that's a few months off (at least), and just > a gleam in my eye. > > Cheers, > David Thanks David, And is there another mechanism I could use from Rspec that explicitly calls TestCase or ExampleGroup class? I just want to retain that mechanism of 'run some code then run tests then run some code' This is for Watir Browser tests so I have workflow setup code that then drives test cases Thanks again marekj From dchelimsky at gmail.com Thu Jun 25 16:33:07 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Jun 2009 15:33:07 -0500 Subject: [rspec-users] When spec/test/unit is used then TestUnit Console Runner.run TestCase does not run testcases In-Reply-To: References: <57c63afe0906251255k38306e2aj8a6b88d7c60ca6eb@mail.gmail.com> Message-ID: <57c63afe0906251333kd82eebcod2304cdad67ab8e@mail.gmail.com> On Thu, Jun 25, 2009 at 3:14 PM, marekj wrote: > On Thu, Jun 25, 2009 at 2:55 PM, David Chelimsky wrote: >> On Thu, Jun 25, 2009 at 2:47 PM, marekj wrote: >>> Hi, I have some old test/unit testcases (used for browser acceptance >>> tests) that I want to convert to rspec. >>> I first started converting assertions to matchers ?and my tests ran >>> fine using TestRunner.run method >>> ?...snip... >>> >>> 2) here is the setup with 'spec/test/unit' that does not run >>> >>> require 'spec/test/unit' >>> class Test_spec < Test::Unit::TestCase >>> ?def test_a >>> ? ?'a'.should == 'a' >>> ?end >>> end >>> >>> # This now will not run Test_spec class >>> require 'test/unit/ui/console/testrunner' >>> puts "before runner" >>> Test::Unit::UI::Console::TestRunner.run Test_spec >>> puts "after runner" >>> >>> >>> Am I missing something? >> >> This is by design. When you run with RSpec, RSpec takes over the run, >> taking test/unit's runner out of the picture. Sorry I can't give you a >> better answer, except to say that future versions of RSpec may not >> suffer this problem. But that's a few months off (at least), and just >> a gleam in my eye. >> >> Cheers, >> David > > Thanks David, > And is there another mechanism I could use from Rspec that explicitly > calls TestCase or ExampleGroup class? Others have written custom runners before. It's not really optimized for that but it's doable. You may want to take a look at micronaut, which I believe is rspec and test/unit compatible and hackable. > I just want to retain that mechanism of 'run some code then run tests > then run some code' > This is for Watir Browser tests so I have workflow setup code that > then drives test cases > > Thanks again > marekj > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Jun 26 08:37:18 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 26 Jun 2009 07:37:18 -0500 Subject: [rspec-users] mock object in array is getting size called on it In-Reply-To: <50873a360906260513v5c927db0m60960ff197475fb1@mail.gmail.com> References: <50873a360906260513v5c927db0m60960ff197475fb1@mail.gmail.com> Message-ID: <57c63afe0906260537y4f31747ejbb33b944e1859466@mail.gmail.com> On Fri, Jun 26, 2009 at 7:13 AM, doug livesey wrote: > Hi, I have this code: > > ? def self.bulk_create_from_holly( params ) > ??? params.map do |param| > ????? new( param ) > ??? end > ? end > > That is testeb by this expectation: > > ??? it "should generate a new property with each set of params" do > ????? [ @params, @properties ].transpose.each do |(param, property)| > ??????? Property.should_receive( :new ).with( param ).and_return( property ) > ????? end > > ????? do_call > ??? end > > In it, @params and @properties are of the same size (they are generated > together). The objects in the @properties array are not mocked active record > objects, but just plain old mocks (ie. mock( property1 ) ). This has to be > so, as I am using a third party ar adapter that does not support the rails > spec stubs & mocks. > In the spec, I am simply trying to assert that a new property should be > generated for each item in @params. > However, I am getting this message when I run the expectation: > > NoMethodError in 'Property.bulk_create_from_holly( params ) should generate > a new property with each set of params' > undefined method `size' for > # > /home/doug/work/rails/neville/app/models/property.rb:20:in > `bulk_create_from_holly' > /home/doug/work/rails/neville/app/models/property.rb:19:in `map' > /home/doug/work/rails/neville/app/models/property.rb:19:in > `bulk_create_from_holly' > ./spec/models/property_spec.rb:38:in `do_call' > ./spec/models/property_spec.rb:52: > ./script/spec:10: > > As you can see, nowhere do I call size(), and so can only think that this is > some bizarre internal thing. Why don't you debug it and find out where the call is coming from? If you've updated to rspec-1.2.7 you can do this: prop1 = mock(property1) prop1.stub(:size) { puts caller(0)[1]; 37 } Then at least we'll know what we're dealing with :) > Or I'm being really dumb & missing something obvious. > Can anyone spot where I'm going wrong, or maybe suggest a way around this? > Cheers, > ?? Doug. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 26 09:24:10 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 26 Jun 2009 08:24:10 -0500 Subject: [rspec-users] mock object in array is getting size called on it In-Reply-To: <50873a360906260615r55c307ddob7078feb778b392f@mail.gmail.com> References: <50873a360906260513v5c927db0m60960ff197475fb1@mail.gmail.com> <57c63afe0906260537y4f31747ejbb33b944e1859466@mail.gmail.com> <50873a360906260615r55c307ddob7078feb778b392f@mail.gmail.com> Message-ID: <57c63afe0906260624j28981a47ldd559ad24bdaf153@mail.gmail.com> On Fri, Jun 26, 2009 at 8:15 AM, doug livesey wrote: >> Why don't you debug it and find out where the call is coming from? > > I get: > > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/message_expectation.rb:171:in > `call' > > That block's a very useful feature I was unaware of! ;) Yeah - it's in the release notes, but I should really blog about it. Maybe next year :) Anyhow - that's the code that's calling the block I asked you to put in there :) Doesn't help much - try going back a few frames in the stack: prop1 = mock(property1) prop1.stub(:size) { puts caller(0)[1..5]; 37 } > ?? Doug. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 26 09:34:35 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 26 Jun 2009 08:34:35 -0500 Subject: [rspec-users] mock object in array is getting size called on it In-Reply-To: <50873a360906260630s17231e77s1df86e68daaf35e9@mail.gmail.com> References: <50873a360906260513v5c927db0m60960ff197475fb1@mail.gmail.com> <57c63afe0906260537y4f31747ejbb33b944e1859466@mail.gmail.com> <50873a360906260615r55c307ddob7078feb778b392f@mail.gmail.com> <57c63afe0906260624j28981a47ldd559ad24bdaf153@mail.gmail.com> <50873a360906260630s17231e77s1df86e68daaf35e9@mail.gmail.com> Message-ID: <57c63afe0906260634h13934ddet4d75f8e57d891a03@mail.gmail.com> On Fri, Jun 26, 2009 at 8:30 AM, doug livesey wrote: > Copying that (a-la monkey see, monkey do), I get: > > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/message_expectation.rb:171:in > `call' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/message_expectation.rb:171:in > `invoke_return_block' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/message_expectation.rb:122:in > `invoke' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/proxy.rb:99:in > `message_received' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/proxy.rb:142:in > `size' Ah - so close!!!!!! Try [1..10] - I'm pretty sure that the next line will reveal our culprit, as that will show the code that is actually calling the size method. From dchelimsky at gmail.com Fri Jun 26 09:59:38 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 26 Jun 2009 08:59:38 -0500 Subject: [rspec-users] html::document errors In-Reply-To: References: Message-ID: <57c63afe0906260659t2ac55b9al587c63d1d0c6b464@mail.gmail.com> On Tue, Jun 23, 2009 at 5:43 PM, Joe Van Dyk wrote: > Oh, latest version of rspec and rspec-rails installed as a plugin. > > On Tue, Jun 23, 2009 at 3:15 PM, Joe Van Dyk wrote: >> ? ?And Joe should see a radio button representing the answer 'OJ' >> ?# features/step_definitions/trat_steps.rb:111 >> ? ? ?uninitialized constant HTML::Document (NameError) >> ? ? ?/home/joe/projects/cisv/vendor/plugins/rspec/lib/spec/matchers/method_missing.rb:6:in >> `method_missing' >> ? ? ?/home/joe/projects/cisv/vendor/plugins/rspec-rails/lib/spec/rails/matchers/assert_select.rb:25:in >> `__send__' >> ? ? ?/home/joe/projects/cisv/vendor/plugins/rspec-rails/lib/spec/rails/matchers/assert_select.rb:25:in >> `matches?' This is using rspec's have_tag matcher. I'd strongly recommend installing webrat and using it's have_selector matcher instead. Cheers, David >> ? ? ?/home/joe/projects/cisv/vendor/plugins/rspec/lib/spec/expectations/handler.rb:11:in >> `handle_matcher' >> ? ? ?/home/joe/projects/cisv/vendor/plugins/rspec/lib/spec/expectations/extensions/kernel.rb:27:in >> `should' >> ? ? ?./features/step_definitions/trat_steps.rb:113:in `/should see a >> radio button representing the answer '(.*)'/' >> ? ? ?features/trat/taking/answer_sheet.feature:53:in `And Joe should >> see a radio button representing the answer 'OJ'' >> >> >> Any ideas? ?Where's HTML::Document supposed to be defined? >> >> Joe >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Jun 26 10:03:36 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 26 Jun 2009 09:03:36 -0500 Subject: [rspec-users] Spec'ing the result of rescue_from In-Reply-To: <7327761d-2709-4cd6-9c7f-ad337fe5bb23@q3g2000pra.googlegroups.com> References: <57c63afe0906221543x1068deeehe035cc35ee2499da@mail.gmail.com> <7327761d-2709-4cd6-9c7f-ad337fe5bb23@q3g2000pra.googlegroups.com> Message-ID: <57c63afe0906260703tafb20ataafb5eee6c5df3b3@mail.gmail.com> On Tue, Jun 23, 2009 at 1:27 PM, PJ Kelly wrote: > Hi David, thanks for the speedy response yesterday. ?Much appreciated. > > On Jun 22, 3:43?pm, David Chelimsky wrote: >> What's the failure message? > > 'MembersController GET process_step_2 should redirect to step_2' > FAILED > expected redirect to "http://test.host/application/step_2", got no > redirect > > I did some more digging, and found a couple things. ?When I try this > in the browser (by visiting /application/step_2/process) and look at > the development log, the request is actually being made to > ApplicationController#index: > > Processing ApplicationController#index (for 127.0.0.1 at 2009-06-23 > 11:08:18) [GET] > Redirected to http://byassociation.local/application/step_2 > > However when the specs are run, the test log shows: > > Processing MembersController#process_step_2 (for 208.77.188.166 at > 2009-06-23 11:19:50) [GET] > > I guess the question then, is that if this is how things are handled > when using rescue_from, how do I spec out that users are being > redirected to the right location? ?Do you think the inconsistency > between the development test logs needs to be brought up with Rails > core? You've got a route named application :) I'm sure that's where the confusion lies, though I'm not convinced of where the problem lies. What are the controllers and models actually called? What version of rails, rspec, etc? > > Thanks in advance! > > Best, PJ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 26 10:08:28 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 26 Jun 2009 09:08:28 -0500 Subject: [rspec-users] Expected output matches rendered output but still getting error in view spec In-Reply-To: <4A3FF978.6000504@dirtyalpaca.com> References: <4A3FF978.6000504@dirtyalpaca.com> Message-ID: <57c63afe0906260708g23dd1f15o91a5e83128f79d5a@mail.gmail.com> On Mon, Jun 22, 2009 at 4:36 PM, Anthony Burns wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hello all, > > I've just gotten started using BDD with RSpec/Cucumber/Webrat and > Rails and I've run into some frustration trying to get my view spec to > pass. > > First of all, I am running Ruby 1.9.1p129 with Rails 2.3.2, RSpec and > RSpec-Rails 1.2.6, Cucumber 0.3.11, and Webrat 0.4.4. > > Here is the code relevant to my question > > config/routes.rb: > > ? ?map.b_posts ? ? ? ? ? ? ? ? ?'backend/posts', > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?:controller => 'backend/ > posts', > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?:action => 'backend_index', > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? :conditions => { :method > => :get } > > ? ?map.connect ? ? ? ? ? ? ? ? ?'backend/posts', > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?:controller => 'backend/ > posts', > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? :action => 'create', > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? :conditions => { :method > => :post } > > views/backend/posts/create.html.erb: > > ? ?<% form_tag do %> > ? ?<% end %> > > *spec/views/backend/posts/create.html.erb_spec.rb:* > > ? ?describe "backend/posts/create.html.erb" do > ? ? ?it "should render a form to create a post" do > ? ? ? ?render "backend/posts/create.html.erb" > ? ? ? ?response.should have_selector("form", :method => > 'post', :action => b_posts_path) do |form| > ? ? ? ? ?# Nothing here yet. > ? ? ? ?end > ? ? ?end > ? ?end > > Here is the relevant part of the output when I run script/spec: > > 'backend/posts/create.html.erb should render a form to create a post' > FAILED > expected following output to contain a
tag: > www.w3.org/TR/REC-html40/loose.dtd"> > >
> > It would appear to me that what have_selector is looking for is > exactly what the template generates, yet the example still fails. I am > very much looking forward to seeing my error (because I have a feeling > it is my error). Any help is much appreciated! That failure message is coming from webrat, and I'm not sure what's really going wrong there. I'd recommend posting to the webrat group: http://groups.google.com/group/webrat/ Cheers, David From dchelimsky at gmail.com Fri Jun 26 10:44:31 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 26 Jun 2009 09:44:31 -0500 Subject: [rspec-users] mock object in array is getting size called on it In-Reply-To: <50873a360906260736i15008cc1v4702fdf8d1f32d66@mail.gmail.com> References: <50873a360906260513v5c927db0m60960ff197475fb1@mail.gmail.com> <57c63afe0906260537y4f31747ejbb33b944e1859466@mail.gmail.com> <50873a360906260615r55c307ddob7078feb778b392f@mail.gmail.com> <57c63afe0906260624j28981a47ldd559ad24bdaf153@mail.gmail.com> <50873a360906260630s17231e77s1df86e68daaf35e9@mail.gmail.com> <57c63afe0906260634h13934ddet4d75f8e57d891a03@mail.gmail.com> <50873a360906260736i15008cc1v4702fdf8d1f32d66@mail.gmail.com> Message-ID: <57c63afe0906260744t480049a1jcc53cede71e5c315@mail.gmail.com> On Fri, Jun 26, 2009 at 9:36 AM, doug livesey wrote: > That'll be: > > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/message_expectation.rb:171:in > `call' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/message_expectation.rb:171:in > `invoke_return_block' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/message_expectation.rb:122:in > `invoke' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/proxy.rb:99:in > `message_received' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/proxy.rb:142:in > `size' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/message_expectation.rb:162:in > `invoke_consecutive_return_block' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/message_expectation.rb:120:in > `invoke' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/proxy.rb:101:in > `message_received' > /home/doug/work/rails/neville/vendor/gems/rspec-1.2.7/lib/spec/mocks/proxy.rb:142:in > `new' > /home/doug/work/rails/neville/app/models/property.rb:20:in > `bulk_create_from_holly' This last line is where you should look, if you haven't already. > Sorry for the delays -- keep getting called away into other things! > & thanks, > ?? Doug. From lists at ruby-forum.com Sat Jun 27 10:55:18 2009 From: lists at ruby-forum.com (Zhenning Guan) Date: Sat, 27 Jun 2009 16:55:18 +0200 Subject: [rspec-users] what does :save => true mean in mock_model ? Message-ID: <82ec49075a42f7798cd179abb24e6e36@ruby-forum.com> @weather = mock_model(Weather, :id => "1") @forecast = mock_model(Forecast, :weather => @weather, :save => true) what's the different between with :save => true or without it? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Jun 27 11:02:52 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 27 Jun 2009 10:02:52 -0500 Subject: [rspec-users] what does :save => true mean in mock_model ? In-Reply-To: <82ec49075a42f7798cd179abb24e6e36@ruby-forum.com> References: <82ec49075a42f7798cd179abb24e6e36@ruby-forum.com> Message-ID: <57c63afe0906270802n584f8943v1e16625ee47ed7f6@mail.gmail.com> On Sat, Jun 27, 2009 at 9:55 AM, Zhenning Guan wrote: > @weather ?= mock_model(Weather, :id => "1") > @forecast = mock_model(Forecast, :weather => @weather, :save => true) > > what's the different between with :save => true or without it? The hash submitted to mock_model sets up method stubs: @weather.save => MockExpectationError "received unexpected message 'save'" @forecast.save => true HTH, David > -- > 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 Sat Jun 27 11:21:15 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 27 Jun 2009 10:21:15 -0500 Subject: [rspec-users] RSpec not failing when requesting missing method/view In-Reply-To: <24233965.post@talk.nabble.com> References: <24233965.post@talk.nabble.com> Message-ID: <57c63afe0906270821x5e7d36c1s539316265ddc458e@mail.gmail.com> On Sat, Jun 27, 2009 at 10:14 AM, mBread wrote: > I've got this test: > > describe LoginController do > describe "GET index" do > it "should be successful" do > get 'index' > response.should be_success > end > end > end > > which passes, but a cucumber test fails on trying to get the index for > LoginController, with the message: > > No action responded to index. Actions: > > This error happens in cucumber & on a manual test (with a 404 status in the > headers) because the LoginController is empty & there is no index view for > it, but I want a failing rspec test before I correct it, but it insists that > it's getting a 200 status. > > Any ideas? Thanks That is by design. RSpec is about spec'ing things in isolation, whereas cucumber is about spec'ing things end to end. RSpec controller specs are about *controllers*, not views, so the presence and/or validity of a view should not impact the controller spec. If you want to use controller specs to fail when your views are missing, you can use the integrate_views directive: describe LoginController do describe "GET index" do integrate_views it "should be successful" do get 'index' response.should be_success end end end That is available, but is not the rspec way. HTH, David From lists at ruby-forum.com Sat Jun 27 11:52:53 2009 From: lists at ruby-forum.com (Zhenning Guan) Date: Sat, 27 Jun 2009 17:52:53 +0200 Subject: [rspec-users] what does :save => true mean in mock_model ? In-Reply-To: <57c63afe0906270802n584f8943v1e16625ee47ed7f6@mail.gmail.com> References: <82ec49075a42f7798cd179abb24e6e36@ruby-forum.com> <57c63afe0906270802n584f8943v1e16625ee47ed7f6@mail.gmail.com> Message-ID: David Chelimsky wrote: clear, thank you David -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sat Jun 27 11:55:43 2009 From: lists at ruby-forum.com (Zhenning Guan) Date: Sat, 27 Jun 2009 17:55:43 +0200 Subject: [rspec-users] what does :save => true mean in mock_model ? In-Reply-To: References: <82ec49075a42f7798cd179abb24e6e36@ruby-forum.com> <57c63afe0906270802n584f8943v1e16625ee47ed7f6@mail.gmail.com> Message-ID: one more question. Forecast.stub!(:new).and_return(@forecast) Forecast.should_receive(:new).with(anything()).and_return(@forecast) what's the different between stub! and should_receive ? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Jun 27 12:15:52 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 27 Jun 2009 11:15:52 -0500 Subject: [rspec-users] what does :save => true mean in mock_model ? In-Reply-To: References: <82ec49075a42f7798cd179abb24e6e36@ruby-forum.com> <57c63afe0906270802n584f8943v1e16625ee47ed7f6@mail.gmail.com> Message-ID: <57c63afe0906270915j28443c06oe621d25fa46ea0cd@mail.gmail.com> On Sat, Jun 27, 2009 at 10:55 AM, Zhenning Guan wrote: > one more question. > Forecast.stub!(:new).and_return(@forecast) > Forecast.should_receive(:new).with(anything()).and_return(@forecast) > > what's the different between stub! and should_receive ? Read this: http://rspec.info/documentation/mocks/ and then feel free to ask questions about anything you don't understand. Cheers, David From mbread at m-bread.com Sat Jun 27 12:20:25 2009 From: mbread at m-bread.com (mBread) Date: Sat, 27 Jun 2009 09:20:25 -0700 (PDT) Subject: [rspec-users] RSpec not failing when requesting missing method/view In-Reply-To: <57c63afe0906270821x5e7d36c1s539316265ddc458e@mail.gmail.com> References: <24233965.post@talk.nabble.com> <57c63afe0906270821x5e7d36c1s539316265ddc458e@mail.gmail.com> Message-ID: <24234411.post@talk.nabble.com> David Chelimsky-2 wrote: > > That is by design. RSpec is about spec'ing things in isolation, > whereas cucumber is about spec'ing things end to end. RSpec controller > specs are about *controllers*, not views, so the presence and/or > validity of a view should not impact the controller spec. > It was the 'no action responded to...' error, which I believe is to do with methods existing in the controller, not the 'template is missing' error regarding a missing view (I wasn't aware of the second one when I made the first post). I didn't realise that error would disappear when a view exists but no methods, so I see now that it is an integration issue, not a unit issue. Thanks -- View this message in context: http://www.nabble.com/RSpec-not-failing-when-requesting-missing-method-view-tp24233965p24234411.html Sent from the rspec-users mailing list archive at Nabble.com. From orengolan at gmail.com Sat Jun 27 18:00:58 2009 From: orengolan at gmail.com (oren) Date: Sat, 27 Jun 2009 15:00:58 -0700 (PDT) Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <4A33CC56.9090406@benmabey.com> References: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> <4A3267F0.5080809@benmabey.com> <1fb4df0906120941p6943b879nff94e8a6c07322b9@mail.gmail.com> <4A33CC56.9090406@benmabey.com> Message-ID: <8d675deb-cd93-419b-ae10-3a7287671ebe@f19g2000yqo.googlegroups.com> Thank you so much Stephen. I am ruby and rails beginner (created a simple site so far) that decided to dive into rspec and I feel the pains you described. I decided to start new rails app and do it with rspec (and to only test my models). Is there a github project with rspec code that test the models? it will be great to look at the examples before jumping to theory. also, I just bought the book and it looks amazing. Is it possible to only read the rspec parts and ignore the cucumber parts? Thanks again for the detailed post. it really helps me understand what I am getting into. From orengolan at gmail.com Sat Jun 27 18:05:45 2009 From: orengolan at gmail.com (oren) Date: Sat, 27 Jun 2009 15:05:45 -0700 (PDT) Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <1fb4df0906120941p6943b879nff94e8a6c07322b9@mail.gmail.com> References: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> <4A3267F0.5080809@benmabey.com> <1fb4df0906120941p6943b879nff94e8a6c07322b9@mail.gmail.com> Message-ID: <806df576-6c4c-41ff-800f-c217d11185e8@l12g2000yqo.googlegroups.com> test On Jun 12, 9:41?am, Stephen Eley wrote: > Ben and Rick, > > Thanks very much to both of you for the encouraging responses. ?Your > reply, Ben, came just in time as I was starting to wonder if I had > made a complete and irrevocable ass of myself. > > On Fri, Jun 12, 2009 at 10:36 AM, Ben Mabey wrote: > > In general though I don't know if I > > really see all of this as a problem specific to RSpec. ?The problem is that > > many people coming to RSpec are not just RSpec novices but are in fact TDD > > novices (and Rails, and Ruby novices too boot at times as well!). > > FWIW, I agree totally. ?In fact I re-read my message last night, and I > want to retract one of my statements for sure: the statement that > RSpec makes "some easy things easy, but other easy things very > complicated." > > On deeper thought, I don't believe this is true. ?RSpec doesn't make > anything harder than it already is. ?There's nothing _wrong_ with > RSpec in this sense. ?I think a more incisive statement would be that > with RSpec, some complicated things _feel like they should be easier._ > ?If only because other things feel so easy. ?And newbies tend to > confront those problem areas at a point in the growth curve where the > complexity can be misinterpreted as them Just Not Getting It. ?Some > are driven off as a result. > > You're right about practice. ?You're right that bringing together too > many learning curves at once creates interference patterns that > shouldn't be blamed on RSpec. ?And Rick's reference to Martin Fowler's > spiked learning curve -- "this is scary, this is nifty, WHOOPS I > overdid it, this is okay in its place" -- is an excellent point. > > But I don't think it's totally out-of-bounds to frame it as an "RSpec > problem," even if it isn't RSpec's fault. ?The thing is... ?Well... > There are *opportunities* here. ?If RSpec -- along with its tools and > resources and culture -- was a little better at some of this stuff, > how much easier would it be to learn *everything else?* > > How many of us learned BDD at the same time we learned programming? > ...Show of hands? ?Anyone? ?The only developers who could make that > claim would have to be pretty fresh out of the pond. ?If that does > apply to anyone reading this, please speak up -- I'd like to hear your > thoughts on how you're doing. > > How many of us used TDD or BDD out of the gate when we learned Rails > or Ruby? ?This is plausible, but I get the sense it's uncommon. ?Most > of us don't even think to work on good testing practices until we > believe we're getting the rest of the stuff down. ?I know I didn't. > > Formal education in programming doesn't help. ?Not by any evidence to > my eyes. ?I've recently started seeing someone who's majoring in CS at > a well-known university, and he said the first class he took on > software design was in C. ?Frickin' *C*. ?_Then_ they did C++, and > then Java, but there was nothing significant about testing. ?I told > him about Cucumber and it made his heart go pitter-patter. > > The teaching resources for Rails and Ruby don't help. ?Just about > every book makes a *nod* toward testing -- there's always a chapter, > they always say "do this constantly" -- but the chapter's inevitably > somewhere near the back, after everything else has been introduced. > Rails culture is passionate about testing, but most of us don't start > to tap into that culture until we're at 'Competent' or above. > > What if the world were different? ?What if teaching were different? > What if the predominant lessons people used to get started with Rails > *did not* start with "Type 'rails', make a scaffold, watch it fly!" > but instead started with, "What's the most important single piece of > information in your app? ?Okay, great. ?Write a spec like this. ?Now > open up this file in /app/models.. ?[...] ?Your spec passed, you're > cooking! ?Now let's spec a view so we can see that information... ?Now > let's spec a controller to bring them together..." > > (Even better would be to start with Cucumber, which would take up very > little extra overhead in that type of tutorial.) > > You get the gist. ?What if learning Rails was *all about* learning > BDD? ?Would it make the Rails stuff easier to understand and develop > competence faster? ?I hypothesize that it would. > > Some things need to be easier in BDD before we can get there. ?To me > that means things need to be easier in RSpec. ?I believe my tutorial > above would be easy enough to do today on the model side, but it's > just too cumbersome to write a view or controller spec. ?You lose that > "holy crap look how *fast* this is coming!" vibe which is so > invigorating when you're doing something new. ?We could make that > tutorial happen when writing a controller spec takes about as long as > writing the controller *code.* ?There are some mitigators for this -- > the Shoulda macros may be great for this now that they work with RSpec > -- but even so I think it's probably a little bit of wading into the > swamp. > > I would like to see that world. ?I'd like to help *make* it. ?That > college guy I'm dating has asked me about learning Rails -- but I'm > planning to talk his ass off about Cucumber and RSpec before I agree > to help him with code. ?I'm hoping he'll be my experiment to test my > hypothesis, and I'll get a better sense of just how easy or hard it is > to learn agile Web development if BDD happens at the ground floor. > > Given time, I think the patterns facilitated by RSpec could > *completely* revolutionize the way software happens everywhere, *if* > the next generation of developers come to learn it first and not as an > "add-on." ?And that's why I'm picking on RSpec. ?I can't think of any > other technology in a better position to make this happen, with only > some moderate shifts of emphasis in both the tools and the culture. > > Does anyone else think that'd be pretty cool? > > -- > Have Fun, > ? ?Steve Eley (sfe... at gmail.com) > ? ?ESCAPE POD - The Science Fiction Podcast Magazine > ? ?http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From orengolan at gmail.com Sat Jun 27 18:01:17 2009 From: orengolan at gmail.com (oren) Date: Sat, 27 Jun 2009 15:01:17 -0700 (PDT) Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <4A33CC56.9090406@benmabey.com> References: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> <4A3267F0.5080809@benmabey.com> <1fb4df0906120941p6943b879nff94e8a6c07322b9@mail.gmail.com> <4A33CC56.9090406@benmabey.com> Message-ID: <4bc8c2d5-3a0d-49cb-aa54-519618bfb734@h2g2000yqg.googlegroups.com> Thank you so much Stephen. I am ruby and rails beginner (created a simple site so far) that decided to dive into rspec and I feel the pains you described. I decided to start new rails app and do it with rspec (and to only test my models). Is there a github project with rspec code that test the models? it will be great to look at the examples before jumping to theory. also, I just bought the book and it looks amazing. Is it possible to only read the rspec parts and ignore the cucumber parts? Thanks again for the detailed post. it really helps me understand what I am getting into. From orengolan at gmail.com Sat Jun 27 18:29:48 2009 From: orengolan at gmail.com (oren) Date: Sat, 27 Jun 2009 15:29:48 -0700 (PDT) Subject: [rspec-users] The problem with learning RSpec In-Reply-To: <1fb4df0906120941p6943b879nff94e8a6c07322b9@mail.gmail.com> References: <1fb4df0906111148h5967b00cy4a8ab47403c71797@mail.gmail.com> <4A3267F0.5080809@benmabey.com> <1fb4df0906120941p6943b879nff94e8a6c07322b9@mail.gmail.com> Message-ID: <39a49d9a-2993-4ae2-ab2c-50a25d5aa813@r33g2000yqn.googlegroups.com> Thank you so much Stephen. I am ruby and rails beginner (created a simple site so far) that decided to dive into rspec and I feel the pains you described. I decided to start new rails app and do it with rspec (and to only test my models). is there a github project with rspec code that test the models? it will be great to look at the examples before jumping to theory. Also, I just bought 'the rspec book'. Can I only read the rspec parts and skip the cucumber parts or it doesn't fit into the books structure and I must read it from start to finish? Thanks again for the detailed post. it really helps me understand what I am getting into. From orengolan at gmail.com Sat Jun 27 23:51:48 2009 From: orengolan at gmail.com (oren) Date: Sat, 27 Jun 2009 20:51:48 -0700 (PDT) Subject: [rspec-users] Testing with activerecord at ThoughtWorks (Stubbing vs real DB) Message-ID: <6b3d89e1-ce80-4e7d-b14b-2596d628f42d@b14g2000yqd.googlegroups.com> I am reading the post by Fowler, 'Ruby at ThoughtWorks'. http://martinfowler.com/articl/rubyAtThoughtWorks.html#WasRubyTheRightChoice He talks about testing with activerecord: "Right at the beginning of our use of Ruby, there was a debate on how best to organize testing in the presence of the Active Record database layer in Rails. The basic problem is that most of the time, performance of enterprise applications is dominated by database access. We've found that by using a Test Double we can greatly speed up our tests. Having fast tests is crucial to our test-intensive development process. Kent Beck recommends a basic commit build of under ten minutes. Most of our projects manage this these days, and using a database double is a vital part of achieving it. The problem with Active Record is that by combining database access code with business logic, it's rather harder to create a database double. The Mingle team's reaction to this was to accept that Rails binds the database tightly and thus run all the commit tests against a real database. The contrary view was advocated most firmly by the Atlanta and Jersey teams. Ruby has a powerful feature that allows you to redefine methods at run-time. You can use this to take an active record class, and redefine the the database access methods in that class as stubs. The team started the gem unitrecord to help with this. In the three years, we've not seen a generally accepted victor in this debate. The Mingle team run a couple of thousand tests against a real postgres database in around 8 minutes. (They parallelize the tests to make use of multiple cores.) The Atlanta and Jersey teams consider it valuable that their commit test runs in 2 minutes with stubs versus 8 minutes without. The trade-off is the simplicity of the direct database tests versus the faster commit build of the stubbed tests. While both teams are broadly happy with their positions in this debate, the use of stubbing has led to another issue for the Atlanta/ Jersey teams. As the teams became familiar with using method stubbing, they used it more and more - falling into the inevitable over-usage where unit tests would stub out every method other than the one being tested. The problem here, as often with using doubles, is brittle tests. As you change the behavior of the application, you also have to change lots of doubles that are mimicking the old behavior. This over- usage has led both teams to move away from stubbed unit tests and to use more rails-style functional tests with direct database access." What do you think of the two tactics? Also, What does it mean and where can I see examples of "running all the commit tests against a real database" ? Can I find it in "the rspec book" ? Thanks! From ben at benmabey.com Sun Jun 28 02:34:26 2009 From: ben at benmabey.com (Ben Mabey) Date: Sun, 28 Jun 2009 00:34:26 -0600 Subject: [rspec-users] Testing with activerecord at ThoughtWorks (Stubbing vs real DB) In-Reply-To: <6b3d89e1-ce80-4e7d-b14b-2596d628f42d@b14g2000yqd.googlegroups.com> References: <6b3d89e1-ce80-4e7d-b14b-2596d628f42d@b14g2000yqd.googlegroups.com> Message-ID: <4A470EF2.8070006@benmabey.com> oren wrote: > I am reading the post by Fowler, 'Ruby at ThoughtWorks'. > http://martinfowler.com/articl/rubyAtThoughtWorks.html#WasRubyTheRightChoice > > He talks about testing with activerecord: > > "Right at the beginning of our use of Ruby, there was a debate on how > best to organize testing in the presence of the Active Record database > layer in Rails. The basic problem is that most of the time, > performance of enterprise applications is dominated by database > access. We've found that by using a Test Double we can greatly speed > up our tests. Having fast tests is crucial to our test-intensive > development process. Kent Beck recommends a basic commit build of > under ten minutes. Most of our projects manage this these days, and > using a database double is a vital part of achieving it. > > The problem with Active Record is that by combining database access > code with business logic, it's rather harder to create a database > double. The Mingle team's reaction to this was to accept that Rails > binds the database tightly and thus run all the commit tests against a > real database. > > The contrary view was advocated most firmly by the Atlanta and Jersey > teams. Ruby has a powerful feature that allows you to redefine methods > at run-time. You can use this to take an active record class, and > redefine the the database access methods in that class as stubs. The > team started the gem unitrecord to help with this. > > In the three years, we've not seen a generally accepted victor in this > debate. The Mingle team run a couple of thousand tests against a real > postgres database in around 8 minutes. (They parallelize the tests to > make use of multiple cores.) The Atlanta and Jersey teams consider it > valuable that their commit test runs in 2 minutes with stubs versus 8 > minutes without. The trade-off is the simplicity of the direct > database tests versus the faster commit build of the stubbed tests. > > While both teams are broadly happy with their positions in this > debate, the use of stubbing has led to another issue for the Atlanta/ > Jersey teams. As the teams became familiar with using method stubbing, > they used it more and more - falling into the inevitable over-usage > where unit tests would stub out every method other than the one being > tested. The problem here, as often with using doubles, is brittle > tests. As you change the behavior of the application, you also have to > change lots of doubles that are mimicking the old behavior. This over- > usage has led both teams to move away from stubbed unit tests and to > use more rails-style functional tests with direct database access." > > What do you think of the two tactics? > I have done both on past projects. I did not use any of the TW gems to do it. I used Avdi Grimm's nice NullDB plugin to do it. IMO it is a much better and cleaner approach than the ones talked about in the article. I gave a lightning talk about the tradeoffs of both approaches and how I used NullDB in my project. Here are the slides for the talk: http://www.slideshare.net/bmabey/disconnecting-the-database-with-activerecord The slides go through the benefits and tradeoffs of both approaches. Let me know if you want me to elaborate on anything else. I should point out that another, but less extreme, solution to stubbing out the DB is to use an in-memory DB (like sqllite) to get a speed boost. With this approach you may still need to switch to your real DB adapter for DB specific SQL but it all the basic AR stuff with work just fine. > Also, What does it mean and where can I see examples of "running all > the commit tests against a real database" ? > Sounds like they have configured there project to to allow you to hot swap which strategy to use. So, for development you can use the stubbing approach and get faster feedback and then swap in the real database on the CI server to make sure there aren't any surprises when it is actually executed against the DB. This is a good approach and can be done quite easily with NullDB. > Can I find it in "the rspec book" ? > I don't think so. To be honest, I don't think it is done that much. I think most teams just let there model tests hit the DB. (And thus are not "real" unit tests by some people's definition....) -Ben From win at wincent.com Sun Jun 28 08:07:28 2009 From: win at wincent.com (Wincent Colaiuta) Date: Sun, 28 Jun 2009 14:07:28 +0200 Subject: [rspec-users] Test doubles: expect "x" and don't care about anything else Message-ID: <8CCEC67D-0EFD-418C-95F5-E55DA95209FA@wincent.com> I've had one of my recurring doubts about test doubles come up again. The full post is here but I'll abbreviate the content in this message in any case: https://wincent.com/blog/thinking-about-switching-to-rr Basically, in one of my controller specs I wanted to verify that the following line was being called and doing the right thing: @comment = Comment.find params[:id] I had a mock for this set up, but it broke when unrelated code in the model was modified (a complex callback which itself called Comment.find). The problems were as follows: - A mock was more than I really needed, as I didn't want to go through the complication of returning a substitute object. - The expectation set on the mock was too strict, because the other message send to Comment.find, the one I didn't care about, was triggering a failure. - A proxy would suffice, because all I really wanted to confirm was that the "find" message was sent, without actually interfering with the returned object. - I basically wanted to set an expectation "that this class will receive this message with these params", but the frameworks didn't allow me to do that because in reality you can only assert "that this class will receive this message with these params _and not receive that message with any other params at any time_" In my blog post I detailed the possible options for avoiding the problem, and the easiest ended up being: forget mocks and proxies entirely and instead test the side-effect (that the expected object ends up getting assigned to the "@comment" instance variable). So the workaround worked, but RSpec's own mock framework, and from what I can tell, the alternatives such as Mocha, RR et al, wouldn't really let me make the kind of assertion that I wanted to make: ie. "confirm this message gets sent at some point, but don't modify the behaviour at all, and don't interfere with or worry about any other messages that get sent to the object, including messages sent to the method that I'm setting the expectation on". In my ideal test-double framework, I'd like to really assert two things about the line of code in question: 1. That Comment.find gets called with a specific param at some point in time. 2. That the @comment instance variable gets the expected value assigned to it. I literally don't care about what other messages get sent to Comment, nor about other places in the code where Comment.find might get called with other parameters, and in any case I don't want to actually modify the behaviour or substitute my own return values. But it seems I can't do this with existing test double frameworks, and it makes it hard to write minimal specs with one expectation and as few test doubles as possible (ideally zero or one) per "it" block. Ideally I'd want to write something like: it 'should find the comment' do proxy(Comment).find(@comment.id.to_s) do_put end it 'should assign to the @comment instance variable' do assigns[:comment].should == @comment do_put end Note that with the "proxy" syntax above I'm trying to say: - I expect this message and these params to be sent at some point - I don't care if other messages are sent - I don't even care if the "find" method is also called with different params - I don't care about the order of the messages - I don't want to interfere with or substitute the return value I don't know whether the syntax is adequate, or whether some keyword other than "proxy" would be required. Another alternative I thought of was: it 'should find the comment' do spy(Comment) do_put Comment.should have_received.find(@comment.id.to_s) end Or similar... Basically saying that I want the double framework to spy (proxy _and_ record) all messages to the specified receiver, and that afterwards I'm going to retrospectively check that among the recorded messages is the one I'm looking for. What do other people think? - is what I'm wanting to do a reasonable approach? - are there any test double frameworks out there which would allow me to work in this way? Cheers, Wincent From lists at ruby-forum.com Sun Jun 28 10:32:57 2009 From: lists at ruby-forum.com (Jesse Crockett) Date: Sun, 28 Jun 2009 16:32:57 +0200 Subject: [rspec-users] Integrate or isolate views? Message-ID: Hello, I've been trying for two years to pick up BDD. I'm making progress, have just read through the chapters in The RSpec Book on spec'ing views and controllers. What is the difference between using integrate_views and doing what seems to be a lot of extra work to test the views in isolation? When I use integrate_views, can I write view spec in what would otherwise be isolated controller spec? I read that I'm "encouraged" to do these in isolation, but IMHO the chapter on spec'ing views is not very convincing in its own right, it tells me that it's good, but doesn't show me as much, compared to the examples and descriptions of circumstance that make several other chapters very convincing. Please help. thanks Jesse -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Sun Jun 28 13:27:15 2009 From: ben at benmabey.com (Ben Mabey) Date: Sun, 28 Jun 2009 11:27:15 -0600 Subject: [rspec-users] Integrate or isolate views? In-Reply-To: References: Message-ID: <03369D62-AD08-4922-8D43-8289506E9AAC@benmabey.com> On Jun 28, 2009, at 8:32 AM, Jesse Crockett wrote: > Hello, > > I've been trying for two years to pick up BDD. I'm making progress, > have just read through the chapters in The RSpec Book on spec'ing > views > and controllers. > > What is the difference between using integrate_views and doing what > seems to be a lot of extra work to test the views in isolation? > > When I use integrate_views, can I write view spec in what would > otherwise be isolated controller spec? Correct, by default RSpec's controller specs will not render the view. This allows you to test the controller and view in complete isolation. By turning on integrate_views you can specify what the rendered view should contain at the same time. If you were to do outside-in dev starting from the view you would start out by writing an isolated view spec. That spec would say that such and such would be displayed. This would in turn prompt you to assign something to that view for it to be rendered. That is then your signal that the controller needs to assign that object. So, you go up a level and make sure that the controller action is assigning the needed object for the view. That object will most likely have to answer to some methods used in the view so that prompts you to start writing examples on the model level. Isolation has it's benefits, however an integration test (i.e. Cucumber scenario) is really needed to make sure these parts are all working together as expected. > > > I read that I'm "encouraged" to do these in isolation, but IMHO the > chapter on spec'ing views is not very convincing in its own right, it > tells me that it's good, but doesn't show me as much, compared to the > examples and descriptions of circumstance that make several other > chapters very convincing. FWIW Jesse, you are not alone on this list in thinking that view specs are not that valuable. A lot of people share your opinion, and I think Cucumber is generally used to specify the views the majority of the time. This enables you to specify your controllers in isolation since your Cucumber features are cutting through the entire stack. I personally think view specs are a very nice tool to have available, but I would only use them on complex views. By complex I don't mean riddled with logic, but a view that has a lot of stuff going on which is hard to set up all in one integration test (or Cucumber scenario). Since the majority of views are very simple then verifying them just in Cucumber is good enough, IMO. -Ben From magic6435 at gmail.com Sun Jun 28 06:41:23 2009 From: magic6435 at gmail.com (Michael) Date: Sun, 28 Jun 2009 03:41:23 -0700 (PDT) Subject: [rspec-users] Testing a Create action to make sure the User is assigned to a new Model Message-ID: <6cbd49ce-57dd-40c9-8fc5-588d1f9333d0@a7g2000yqk.googlegroups.com> I'm trying to figure out how to test that the current_user does end up being attached to a new model that is being created which happens to be an Album. Here is the Controller code. def create @album = current_user.albums.new params[:album] if @album.save flash[:notice] = "The album was saved successfully." redirect_to @album else render :action => :new end end and here is a quick overview of how i have been testing so far. before(:each) do @album = mock_model(Album, :save => nil) Album.stub(:new).and_return(@album) end describe "authenticated user" do before(:each) do activate_authlogic UserSession.create Factory.build(:valid_user) end it "should build new album" do Album.should_receive(:new).with("title" => "album title", "description" => "album description").and_return(@album) post :create, :album => {"title" => "album title", "description" => "album description"} end it "should save the album" do @album.should_receive(:save) post :create end end How would i test to make sure that on the save "user_id" is present and matches the logged in user? Thanks for any help. -mike From magic6435 at gmail.com Sun Jun 28 06:33:06 2009 From: magic6435 at gmail.com (Michael) Date: Sun, 28 Jun 2009 03:33:06 -0700 (PDT) Subject: [rspec-users] Testing a Create action to make sure the User is assigned to a new Model Message-ID: I'm trying to figure out how to test that the current_user does end up being attached to a new model that is being created which happens to be an Album. Here is the Controller code. def create @album = current_user.albums.new params[:album] if @album.save flash[:notice] = "The album was saved successfully." redirect_to @album else render :action => :new end end and here is a quick overview of how i have been testing so far. before(:each) do @album = mock_model(Album, :save => nil) Album.stub(:new).and_return(@album) end describe "authenticated user" do before(:each) do activate_authlogic UserSession.create Factory.build(:valid_user) end it "should build new album" do Album.should_receive(:new).with("title" => "album title", "description" => "album description").and_return(@album) post :create, :album => {"title" => "album title", "description" => "album description"} end it "should save the album" do @album.should_receive(:save) post :create end end How would i test to make sure that on the save "user_id" is present and matches the logged in user? Thanks for any help. -mike From sarah at ultrasaurus.com Sun Jun 28 14:56:18 2009 From: sarah at ultrasaurus.com (Sarah Allen) Date: Sun, 28 Jun 2009 11:56:18 -0700 Subject: [rspec-users] Integrate or isolate views? In-Reply-To: <03369D62-AD08-4922-8D43-8289506E9AAC@benmabey.com> References: <03369D62-AD08-4922-8D43-8289506E9AAC@benmabey.com> Message-ID: <2F96CC14-B30F-48A4-9899-E75E14DB114C@ultrasaurus.com> I find that testing views independently is useful just to catch HTML errors that can sometime creep in during a re-factor. These check important details that would be more tedious using cucumber. The controller specs establish the post-condition for the controller independent of the view. In the project I'm working on (which has mobile clients as well as a website), we have end-to-end integrations tests using cucumber that are primarily around our XML APIs (which are from my perspective, just a different kind of view) -- these also serve as developer docs. My $.02 Sarah On Jun 28, 2009, at 10:27 AM, Ben Mabey wrote: > > On Jun 28, 2009, at 8:32 AM, Jesse Crockett wrote: > >> Hello, >> >> I've been trying for two years to pick up BDD. I'm making progress, >> have just read through the chapters in The RSpec Book on spec'ing >> views >> and controllers. >> >> What is the difference between using integrate_views and doing what >> seems to be a lot of extra work to test the views in isolation? >> >> When I use integrate_views, can I write view spec in what would >> otherwise be isolated controller spec? > > Correct, by default RSpec's controller specs will not render the > view. This allows you to test the controller and view in complete > isolation. By turning on integrate_views you can specify what the > rendered view should contain at the same time. If you were to do > outside-in dev starting from the view you would start out by writing > an isolated view spec. That spec would say that such and such would > be displayed. This would in turn prompt you to assign something to > that view for it to be rendered. That is then your signal that the > controller needs to assign that object. So, you go up a level and > make sure that the controller action is assigning the needed object > for the view. That object will most likely have to answer to some > methods used in the view so that prompts you to start writing > examples on the model level. Isolation has it's benefits, however > an integration test (i.e. Cucumber scenario) is really needed to > make sure these parts are all working together as expected. > >> >> >> I read that I'm "encouraged" to do these in isolation, but IMHO the >> chapter on spec'ing views is not very convincing in its own right, it >> tells me that it's good, but doesn't show me as much, compared to the >> examples and descriptions of circumstance that make several other >> chapters very convincing. > > FWIW Jesse, you are not alone on this list in thinking that view > specs are not that valuable. A lot of people share your opinion, > and I think Cucumber is generally used to specify the views the > majority of the time. This enables you to specify your controllers > in isolation since your Cucumber features are cutting through the > entire stack. I personally think view specs are a very nice tool > to have available, but I would only use them on complex views. By > complex I don't mean riddled with logic, but a view that has a lot > of stuff going on which is hard to set up all in one integration > test (or Cucumber scenario). Since the majority of views are very > simple then verifying them just in Cucumber is good enough, IMO. > > -Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users http://www.ultrasaurus.com From lists at ruby-forum.com Sun Jun 28 15:13:23 2009 From: lists at ruby-forum.com (Jesse Crockett) Date: Sun, 28 Jun 2009 21:13:23 +0200 Subject: [rspec-users] Integrate or isolate views? In-Reply-To: <03369D62-AD08-4922-8D43-8289506E9AAC@benmabey.com> References: <03369D62-AD08-4922-8D43-8289506E9AAC@benmabey.com> Message-ID: <6343e04079b65aeea9bdb4ac8724e626@ruby-forum.com> Ben Mabey wrote: > On Jun 28, 2009, at 8:32 AM, Jesse Crockett wrote: > >> When I use integrate_views, can I write view spec in what would >> otherwise be isolated controller spec? > > Correct, by default RSpec's controller specs will not render the > view. This allows you to test the controller and view in complete > isolation. By turning on integrate_views you can specify what the > rendered view should contain at the same time. If you were to do > outside-in dev starting from the view you would start out by writing > an isolated view spec. That spec would say that such and such would > be displayed. This would in turn prompt you to assign something to > that view for it to be rendered. That is then your signal that the > controller needs to assign that object. So, you go up a level and > make sure that the controller action is assigning the needed object > for the view. That object will most likely have to answer to some > methods used in the view so that prompts you to start writing examples > on the model level. Isolation has it's benefits, however an > integration test (i.e. Cucumber scenario) is really needed to make > sure these parts are all working together as expected. > >> >> >> I read that I'm "encouraged" to do these in isolation, but IMHO the >> chapter on spec'ing views is not very convincing in its own right, it >> tells me that it's good, but doesn't show me as much, compared to the >> examples and descriptions of circumstance that make several other >> chapters very convincing. > > FWIW Jesse, you are not alone on this list in thinking that view specs > are not that valuable. A lot of people share your opinion, and I > think Cucumber is generally used to specify the views the majority of > the time. This enables you to specify your controllers in isolation > since your Cucumber features are cutting through the entire stack. I gather that you are saying a balance of cucumber scenarios in tandem with spec'ing controllers and models in isolation is a reasonable conclusion and equally reasonable path to move forward? > I personally think view specs are a very nice tool to have available, > but I would only use them on complex views. By complex I don't mean > riddled with logic, but a view that has a lot of stuff going on which > is hard to set up all in one integration test (or Cucumber scenario). > Since the majority of views are very simple then verifying them just > in Cucumber is good enough, IMO. > > -Ben I gather that you are affirming that adequate testing of controllers and models in isolation as presscribed the the Rspec Book can be accomplished without spec'ing the views in the same isolation, but instead by using 'integrate_views' with adequate cucumber scenarios? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Jun 28 15:16:48 2009 From: lists at ruby-forum.com (Jesse Crockett) Date: Sun, 28 Jun 2009 21:16:48 +0200 Subject: [rspec-users] Integrate or isolate views? In-Reply-To: <2F96CC14-B30F-48A4-9899-E75E14DB114C@ultrasaurus.com> References: <03369D62-AD08-4922-8D43-8289506E9AAC@benmabey.com> <2F96CC14-B30F-48A4-9899-E75E14DB114C@ultrasaurus.com> Message-ID: <557cce2c2790af8aadbc90b257516df8@ruby-forum.com> Sarah Allen wrote: > I find that testing views independently is useful just to catch HTML > errors that can sometime creep in during a re-factor. These check > important details that would be more tedious using cucumber. The > controller specs establish the post-condition for the controller > independent of the view. In the project I'm working on (which has > mobile clients as well as a website), we have end-to-end integrations > tests using cucumber that are primarily around our XML APIs (which are > from my perspective, just a different kind of view) -- these also > serve as developer docs. > > My $.02 > > Sarah IMO, this is what the RSpec Book needs (at this point in beta), real-world conclusions based on experience, rather than "take it on faith that you will 'revel' in the rewards." Thanks, Sarah -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Sun Jun 28 16:33:45 2009 From: ben at benmabey.com (Ben Mabey) Date: Sun, 28 Jun 2009 14:33:45 -0600 Subject: [rspec-users] Integrate or isolate views? In-Reply-To: <6343e04079b65aeea9bdb4ac8724e626@ruby-forum.com> References: <03369D62-AD08-4922-8D43-8289506E9AAC@benmabey.com> <6343e04079b65aeea9bdb4ac8724e626@ruby-forum.com> Message-ID: <4A47D3A9.2000105@benmabey.com> Jesse Crockett wrote: > Ben Mabey wrote: > >> On Jun 28, 2009, at 8:32 AM, Jesse Crockett wrote: >> >> >>> When I use integrate_views, can I write view spec in what would >>> otherwise be isolated controller spec? >>> >> Correct, by default RSpec's controller specs will not render the >> view. This allows you to test the controller and view in complete >> isolation. By turning on integrate_views you can specify what the >> rendered view should contain at the same time. If you were to do >> outside-in dev starting from the view you would start out by writing >> an isolated view spec. That spec would say that such and such would >> be displayed. This would in turn prompt you to assign something to >> that view for it to be rendered. That is then your signal that the >> controller needs to assign that object. So, you go up a level and >> make sure that the controller action is assigning the needed object >> for the view. That object will most likely have to answer to some >> methods used in the view so that prompts you to start writing examples >> on the model level. Isolation has it's benefits, however an >> integration test (i.e. Cucumber scenario) is really needed to make >> sure these parts are all working together as expected. >> >> >>> I read that I'm "encouraged" to do these in isolation, but IMHO the >>> chapter on spec'ing views is not very convincing in its own right, it >>> tells me that it's good, but doesn't show me as much, compared to the >>> examples and descriptions of circumstance that make several other >>> chapters very convincing. >>> >> FWIW Jesse, you are not alone on this list in thinking that view specs >> are not that valuable. A lot of people share your opinion, and I >> think Cucumber is generally used to specify the views the majority of >> the time. This enables you to specify your controllers in isolation >> since your Cucumber features are cutting through the entire stack. >> > > I gather that you are saying a balance of cucumber scenarios in tandem > with spec'ing controllers and models in isolation is a reasonable > conclusion and equally reasonable path to move forward? > Yes, IME this has worked well. > >> I personally think view specs are a very nice tool to have available, >> but I would only use them on complex views. By complex I don't mean >> riddled with logic, but a view that has a lot of stuff going on which >> is hard to set up all in one integration test (or Cucumber scenario). >> Since the majority of views are very simple then verifying them just >> in Cucumber is good enough, IMO. >> >> -Ben >> > > > I gather that you are affirming that adequate testing of controllers and > models in isolation as presscribed the the Rspec Book can be > accomplished without spec'ing the views in the same isolation, but > instead by using 'integrate_views' with adequate cucumber scenarios? > The last part of your sentence is confusing me: "but instead by using 'integrate_views' with adequate cucumber scenarios?". There is no "integrate_views" option in Cucumber as views are always rendered. When I am using Cucumber I don't see the need to be using 'integrate_views' in my controller specs either. Keep in mind that I'm not affirming anything as a hard rule, but rather stating a guideline that I have gravitated towards in my past projects that were webapps. You, like Sarah, may see enough value provided by view specs to warrant them. I would encourage you to try them and then judge for yourself and the specific project you are working on. If you don't get any value out of them then you can stop but you will at least know how to do it when a situation arises that seems better fit for them. HTH, Ben From orengolan at gmail.com Sun Jun 28 16:58:39 2009 From: orengolan at gmail.com (oren) Date: Sun, 28 Jun 2009 13:58:39 -0700 (PDT) Subject: [rspec-users] Testing with activerecord at ThoughtWorks (Stubbing vs real DB) In-Reply-To: <4A470EF2.8070006@benmabey.com> References: <6b3d89e1-ce80-4e7d-b14b-2596d628f42d@b14g2000yqd.googlegroups.com> <4A470EF2.8070006@benmabey.com> Message-ID: <78c84226-c31e-4c72-8bb3-c0e6770e0f97@t21g2000yqi.googlegroups.com> Awesome presentation, thanks for clarifying it Ben. From matt at mattwynne.net Sun Jun 28 17:04:39 2009 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 28 Jun 2009 22:04:39 +0100 Subject: [rspec-users] Test doubles: expect "x" and don't care about anything else In-Reply-To: <8CCEC67D-0EFD-418C-95F5-E55DA95209FA@wincent.com> References: <8CCEC67D-0EFD-418C-95F5-E55DA95209FA@wincent.com> Message-ID: <2CFD89CC-79AF-4F9E-9B56-C8C4EE7B90E5@mattwynne.net> On 28 Jun 2009, at 13:07, Wincent Colaiuta wrote: > I've had one of my recurring doubts about test doubles come up again. > > The full post is here but I'll abbreviate the content in this > message in any case: > > https://wincent.com/blog/thinking-about-switching-to-rr > > Basically, in one of my controller specs I wanted to verify that the > following line was being called and doing the right thing: > @comment = Comment.find params[:id] > I had a mock for this set up, but it broke when unrelated code in > the model was modified (a complex callback which itself called > Comment.find). I'd like to know more about how this happened. How did the model object's behaviour leak into the controller spec? > The problems were as follows: > > - A mock was more than I really needed, as I didn't want to go > through the complication of returning a substitute object. > > - The expectation set on the mock was too strict, because the other > message send to Comment.find, the one I didn't care about, was > triggering a failure. > > - A proxy would suffice, because all I really wanted to confirm was > that the "find" message was sent, without actually interfering with > the returned object. > > - I basically wanted to set an expectation "that this class will > receive this message with these params", but the frameworks didn't > allow me to do that because in reality you can only assert "that > this class will receive this message with these params _and not > receive that message with any other params at any time_" > > In my blog post I detailed the possible options for avoiding the > problem, and the easiest ended up being: forget mocks and proxies > entirely and instead test the side-effect (that the expected object > ends up getting assigned to the "@comment" instance variable). > > So the workaround worked, but RSpec's own mock framework, and from > what I can tell, the alternatives such as Mocha, RR et al, wouldn't > really let me make the kind of assertion that I wanted to make: ie. > "confirm this message gets sent at some point, but don't modify the > behaviour at all, and don't interfere with or worry about any other > messages that get sent to the object, including messages sent to the > method that I'm setting the expectation on". > > In my ideal test-double framework, I'd like to really assert two > things about the line of code in question: > > 1. That Comment.find gets called with a specific param at some > point in time. > 2. That the @comment instance variable gets the expected value > assigned to it. So why not use Comment.stub!(:find).with(123).and_return(mock(Comment)) > I literally don't care about what other messages get sent to > Comment, nor about other places in the code where Comment.find might > get called with other parameters, and in any case I don't want to > actually modify the behaviour or substitute my own return values. > But it seems I can't do this with existing test double frameworks, > and it makes it hard to write minimal specs with one expectation and > as few test doubles as possible (ideally zero or one) per "it" block. > > Ideally I'd want to write something like: > > it 'should find the comment' do > proxy(Comment).find(@comment.id.to_s) > do_put > end > > it 'should assign to the @comment instance variable' do > assigns[:comment].should == @comment > do_put > end > > Note that with the "proxy" syntax above I'm trying to say: > > - I expect this message and these params to be sent at some point > > - I don't care if other messages are sent > > - I don't even care if the "find" method is also called with > different params > > - I don't care about the order of the messages > > - I don't want to interfere with or substitute the return value > > I don't know whether the syntax is adequate, or whether some keyword > other than "proxy" would be required. Another alternative I thought > of was: > > it 'should find the comment' do > spy(Comment) > do_put > Comment.should have_received.find(@comment.id.to_s) > end > > Or similar... Basically saying that I want the double framework to > spy (proxy _and_ record) all messages to the specified receiver, and > that afterwards I'm going to retrospectively check that among the > recorded messages is the one I'm looking for. > > What do other people think? > > - is what I'm wanting to do a reasonable approach? > > - are there any test double frameworks out there which would allow > me to work in this way? > > Cheers, > Wincent cheers, Matt Wynne http://mattwynne.net +447974 430184 From matt at mattwynne.net Sun Jun 28 17:11:17 2009 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 28 Jun 2009 22:11:17 +0100 Subject: [rspec-users] Testing a Create action to make sure the User is assigned to a new Model In-Reply-To: References: Message-ID: <92E21B72-A3ED-4F74-989B-3F7D5B405D0B@mattwynne.net> On 28 Jun 2009, at 11:33, Michael wrote: > I'm trying to figure out how to test that the current_user does end up > being attached to a new model that is being created which happens to > be an Album. > > Here is the Controller code. > > def create > @album = current_user.albums.new params[:album] > if @album.save > flash[:notice] = "The album was saved successfully." > redirect_to @album > else > render :action => :new > end > end > > and here is a quick overview of how i have been testing so far. > > before(:each) do > @album = mock_model(Album, :save => nil) > Album.stub(:new).and_return(@album) > end > > describe "authenticated user" do > > before(:each) do > activate_authlogic > UserSession.create Factory.build(:valid_user) > end > > it "should build new album" do > Album.should_receive(:new).with("title" => "album title", > "description" => "album description").and_return(@album) > post :create, :album => {"title" => "album title", "description" > => "album description"} > end > > it "should save the album" do > @album.should_receive(:save) > post :create > end > > end > > How would i test to make sure that on the save "user_id" is present > and matches the logged in user? From the code you've shown us, it looks as though you need to spec the view, since I presume that's where the params[:album] which may or may not contain this user_id is built. The controller is just passing these params directly to the model's constructor, so it doesn't really seem to have much of a part to play as regards this specific field. This might be a case where you'll get more value from a full-stack Cucumber acceptance test. cheers, Matt Wynne http://mattwynne.net +447974 430184 From win at wincent.com Sun Jun 28 18:02:51 2009 From: win at wincent.com (Wincent Colaiuta) Date: Mon, 29 Jun 2009 00:02:51 +0200 Subject: [rspec-users] Test doubles: expect "x" and don't care about anything else In-Reply-To: <2CFD89CC-79AF-4F9E-9B56-C8C4EE7B90E5@mattwynne.net> References: <8CCEC67D-0EFD-418C-95F5-E55DA95209FA@wincent.com> <2CFD89CC-79AF-4F9E-9B56-C8C4EE7B90E5@mattwynne.net> Message-ID: <7CF4F3D7-4CCE-42AC-BC2D-58C4442ECCE6@wincent.com> El 28/6/2009, a las 23:04, Matt Wynne escribi?: > On 28 Jun 2009, at 13:07, Wincent Colaiuta wrote: > >> I've had one of my recurring doubts about test doubles come up again. >> >> The full post is here but I'll abbreviate the content in this >> message in any case: >> >> https://wincent.com/blog/thinking-about-switching-to-rr >> >> Basically, in one of my controller specs I wanted to verify that >> the following line was being called and doing the right thing: >> @comment = Comment.find params[:id] >> I had a mock for this set up, but it broke when unrelated code in >> the model was modified (a complex callback which itself called >> Comment.find). > > I'd like to know more about how this happened. How did the model > object's behaviour leak into the controller spec? This was a spec for the controller's "update" action, which does a "save" on the record. At one point a change was made to the model to do some complex updates in the after_save callback, and these involved doing another Comment.find call, but with different parameters. >> In my ideal test-double framework, I'd like to really assert two >> things about the line of code in question: >> >> 1. That Comment.find gets called with a specific param at some >> point in time. >> 2. That the @comment instance variable gets the expected value >> assigned to it. > > So why not use > > Comment.stub!(:find).with(123).and_return(mock(Comment)) Because there are actually two "find" calls here: - the one I actually care about - the other one in the after_save callback which is irrelevant to the controller I original used "should_receive", not "stub", so RSpec complained about getting "find" with the unexpected parameters. If I change to "stub" then I'm losing my assertion (no longer checking that the message gets sent), injecting a different return value (adding complexity), for no visible benefit (may as well just throw away the expectation). Cheers, Wincent From matt at mattwynne.net Mon Jun 29 03:33:48 2009 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 29 Jun 2009 08:33:48 +0100 Subject: [rspec-users] Test doubles: expect "x" and don't care about anything else In-Reply-To: <7CF4F3D7-4CCE-42AC-BC2D-58C4442ECCE6@wincent.com> References: <8CCEC67D-0EFD-418C-95F5-E55DA95209FA@wincent.com> <2CFD89CC-79AF-4F9E-9B56-C8C4EE7B90E5@mattwynne.net> <7CF4F3D7-4CCE-42AC-BC2D-58C4442ECCE6@wincent.com> Message-ID: <0740D1A8-44AB-43A5-8E7C-0FD27BB6E3F2@mattwynne.net> On 28 Jun 2009, at 23:02, Wincent Colaiuta wrote: > El 28/6/2009, a las 23:04, Matt Wynne escribi?: > >> On 28 Jun 2009, at 13:07, Wincent Colaiuta wrote: >> >>> I've had one of my recurring doubts about test doubles come up >>> again. >>> >>> The full post is here but I'll abbreviate the content in this >>> message in any case: >>> >>> https://wincent.com/blog/thinking-about-switching-to-rr >>> >>> Basically, in one of my controller specs I wanted to verify that >>> the following line was being called and doing the right thing: >>> @comment = Comment.find params[:id] >>> I had a mock for this set up, but it broke when unrelated code in >>> the model was modified (a complex callback which itself called >>> Comment.find). >> >> I'd like to know more about how this happened. How did the model >> object's behaviour leak into the controller spec? > > This was a spec for the controller's "update" action, which does a > "save" on the record. At one point a change was made to the model to > do some complex updates in the after_save callback, and these > involved doing another Comment.find call, but with different > parameters. If I understand this correctly, there was only one call from Controller -> Comment that you wanted to test; the other one was a call from Comment -> Comment that happened as a side-effect. So I'm wondering: if you'd returned a fake (mock, stub, whatever) comment from your stubbed Comment.find, would that have solved the problem? > > >>> In my ideal test-double framework, I'd like to really assert two >>> things about the line of code in question: >>> >>> 1. That Comment.find gets called with a specific param at some >>> point in time. >>> 2. That the @comment instance variable gets the expected value >>> assigned to it. >> >> So why not use >> >> Comment.stub!(:find).with(123).and_return(mock(Comment)) > > Because there are actually two "find" calls here: > > - the one I actually care about > - the other one in the after_save callback which is irrelevant to > the controller > > I original used "should_receive", not "stub", so RSpec complained > about getting "find" with the unexpected parameters. If I change to > "stub" then I'm losing my assertion (no longer checking that the > message gets sent), injecting a different return value (adding > complexity), for no visible benefit (may as well just throw away the > expectation). What I often do is put a stub in first, which will work in all the examples, then put a should_receive in one of the examples if (as seems to be the case here) it's important to me to test the collaboration between the objects. So it would look like this: describe "#update" do before(:each) @comment = mock(Comment) Comment.stub!(:find).and_return(@comment) end it "should call the model to try and find the comment" Comment.should_receive(:find).with(123).and_return(@comment) do_request end it "should assign the comment to the view" do_request assigns[:comment].should == @comment end So the stub works in the background, then when you want to actually assert for the collaboration, you can override it with a should_receive. I find this pattern works really well for me. cheers, Matt Wynne http://mattwynne.net +447974 430184 From win at wincent.com Mon Jun 29 04:57:06 2009 From: win at wincent.com (Wincent Colaiuta) Date: Mon, 29 Jun 2009 10:57:06 +0200 Subject: [rspec-users] Test doubles: expect "x" and don't care about anything else In-Reply-To: <0740D1A8-44AB-43A5-8E7C-0FD27BB6E3F2@mattwynne.net> References: <8CCEC67D-0EFD-418C-95F5-E55DA95209FA@wincent.com> <2CFD89CC-79AF-4F9E-9B56-C8C4EE7B90E5@mattwynne.net> <7CF4F3D7-4CCE-42AC-BC2D-58C4442ECCE6@wincent.com> <0740D1A8-44AB-43A5-8E7C-0FD27BB6E3F2@mattwynne.net> Message-ID: <146B01EB-3718-4136-B463-37793B1E1EED@wincent.com> El 29/6/2009, a las 9:33, Matt Wynne escribi?: > On 28 Jun 2009, at 23:02, Wincent Colaiuta wrote: > >> El 28/6/2009, a las 23:04, Matt Wynne escribi?: >> >>> On 28 Jun 2009, at 13:07, Wincent Colaiuta wrote: >>> >>>> I've had one of my recurring doubts about test doubles come up >>>> again. >>>> >>>> The full post is here but I'll abbreviate the content in this >>>> message in any case: >>>> >>>> https://wincent.com/blog/thinking-about-switching-to-rr >>>> >>>> Basically, in one of my controller specs I wanted to verify that >>>> the following line was being called and doing the right thing: >>>> @comment = Comment.find params[:id] >>>> I had a mock for this set up, but it broke when unrelated code in >>>> the model was modified (a complex callback which itself called >>>> Comment.find). >>> >>> I'd like to know more about how this happened. How did the model >>> object's behaviour leak into the controller spec? >> >> This was a spec for the controller's "update" action, which does a >> "save" on the record. At one point a change was made to the model >> to do some complex updates in the after_save callback, and these >> involved doing another Comment.find call, but with different >> parameters. > > If I understand this correctly, there was only one call from > Controller -> Comment that you wanted to test; the other one was a > call from Comment -> Comment that happened as a side-effect. Exactly. > So I'm wondering: if you'd returned a fake (mock, stub, whatever) > comment from your stubbed Comment.find, would that have solved the > problem? Yes, but there's something about that that felt somehow harder than it should be. I mean, I had a working, dead-simple controller spec. I made an unrelated change in the model, and the controller spec broke. Returning a fake would certainly fix the breakage, but the spec would no longer be dead-simple and it somehow feels like one step foward, two steps back, that due to innocuous model changes I have to increase the complexity of my controller tests. So what I'm really pining for is the ability to say "expect this message, but don't return fakes -- just proxy the message through and return the real return value -- and don't worry about any other messages". Cheers, Wincent From ben at benmabey.com Mon Jun 29 10:26:10 2009 From: ben at benmabey.com (Ben Mabey) Date: Mon, 29 Jun 2009 08:26:10 -0600 Subject: [rspec-users] Test doubles: expect "x" and don't care about anything else In-Reply-To: <0740D1A8-44AB-43A5-8E7C-0FD27BB6E3F2@mattwynne.net> References: <8CCEC67D-0EFD-418C-95F5-E55DA95209FA@wincent.com> <2CFD89CC-79AF-4F9E-9B56-C8C4EE7B90E5@mattwynne.net> <7CF4F3D7-4CCE-42AC-BC2D-58C4442ECCE6@wincent.com> <0740D1A8-44AB-43A5-8E7C-0FD27BB6E3F2@mattwynne.net> Message-ID: <4A48CF02.7070200@benmabey.com> Matt Wynne wrote: > > On 28 Jun 2009, at 23:02, Wincent Colaiuta wrote: > >> El 28/6/2009, a las 23:04, Matt Wynne escribi?: >> >>> On 28 Jun 2009, at 13:07, Wincent Colaiuta wrote: >>> >>>> I've had one of my recurring doubts about test doubles come up again. >>>> >>>> The full post is here but I'll abbreviate the content in this >>>> message in any case: >>>> >>>> https://wincent.com/blog/thinking-about-switching-to-rr >>>> >>>> Basically, in one of my controller specs I wanted to verify that >>>> the following line was being called and doing the right thing: >>>> @comment = Comment.find params[:id] >>>> I had a mock for this set up, but it broke when unrelated code in >>>> the model was modified (a complex callback which itself called >>>> Comment.find). >>> >>> I'd like to know more about how this happened. How did the model >>> object's behaviour leak into the controller spec? >> >> This was a spec for the controller's "update" action, which does a >> "save" on the record. At one point a change was made to the model to >> do some complex updates in the after_save callback, and these >> involved doing another Comment.find call, but with different parameters. > > If I understand this correctly, there was only one call from > Controller -> Comment that you wanted to test; the other one was a > call from Comment -> Comment that happened as a side-effect. > > So I'm wondering: if you'd returned a fake (mock, stub, whatever) > comment from your stubbed Comment.find, would that have solved the > problem? > >> >> >>>> In my ideal test-double framework, I'd like to really assert two >>>> things about the line of code in question: >>>> >>>> 1. That Comment.find gets called with a specific param at some >>>> point in time. >>>> 2. That the @comment instance variable gets the expected value >>>> assigned to it. >>> >>> So why not use >>> >>> Comment.stub!(:find).with(123).and_return(mock(Comment)) >> >> Because there are actually two "find" calls here: >> >> - the one I actually care about >> - the other one in the after_save callback which is irrelevant to the >> controller >> >> I original used "should_receive", not "stub", so RSpec complained >> about getting "find" with the unexpected parameters. If I change to >> "stub" then I'm losing my assertion (no longer checking that the >> message gets sent), injecting a different return value (adding >> complexity), for no visible benefit (may as well just throw away the >> expectation). > > What I often do is put a stub in first, which will work in all the > examples, then put a should_receive in one of the examples if (as > seems to be the case here) it's important to me to test the > collaboration between the objects. So it would look like this: > > describe "#update" do > before(:each) > @comment = mock(Comment) > Comment.stub!(:find).and_return(@comment) > end > > it "should call the model to try and find the comment" > Comment.should_receive(:find).with(123).and_return(@comment) > do_request > end You probably know this, but for the benefit of others... Pat made a change a while back that makes it so the stubbed return value will still be returned even if an expectation is added. Meaning, assuming the stub is in the before block, you can change the expectation to: Comment.should_receive(:find).with(123) # this will still return @comment -Ben From win at wincent.com Mon Jun 29 11:15:37 2009 From: win at wincent.com (Wincent Colaiuta) Date: Mon, 29 Jun 2009 17:15:37 +0200 Subject: [rspec-users] Test doubles: expect "x" and don't care about anything else In-Reply-To: <4A48CF02.7070200@benmabey.com> References: <8CCEC67D-0EFD-418C-95F5-E55DA95209FA@wincent.com> <2CFD89CC-79AF-4F9E-9B56-C8C4EE7B90E5@mattwynne.net> <7CF4F3D7-4CCE-42AC-BC2D-58C4442ECCE6@wincent.com> <0740D1A8-44AB-43A5-8E7C-0FD27BB6E3F2@mattwynne.net> <4A48CF02.7070200@benmabey.com> Message-ID: <5086D76C-D50F-4530-AC4F-4B44FD5F4E2B@wincent.com> El 29/6/2009, a las 16:26, Ben Mabey escribi?: > You probably know this, but for the benefit of others... Pat made a > change a while back that makes it so the stubbed return value will > still be returned even if an expectation is added. Meaning, > assuming the stub is in the before block, you can change the > expectation to: > Comment.should_receive(:find).with(123) # this will still return > @comment I didn't know that, but it's pretty awesome. Basically means that RSpec mocks can double as proxies now. That's pretty neat. Cheers, Wincent From win at wincent.com Mon Jun 29 11:24:39 2009 From: win at wincent.com (Wincent Colaiuta) Date: Mon, 29 Jun 2009 17:24:39 +0200 Subject: [rspec-users] Test doubles: expect "x" and don't care about anything else In-Reply-To: <5086D76C-D50F-4530-AC4F-4B44FD5F4E2B@wincent.com> References: <8CCEC67D-0EFD-418C-95F5-E55DA95209FA@wincent.com> <2CFD89CC-79AF-4F9E-9B56-C8C4EE7B90E5@mattwynne.net> <7CF4F3D7-4CCE-42AC-BC2D-58C4442ECCE6@wincent.com> <0740D1A8-44AB-43A5-8E7C-0FD27BB6E3F2@mattwynne.net> <4A48CF02.7070200@benmabey.com> <5086D76C-D50F-4530-AC4F-4B44FD5F4E2B@wincent.com> Message-ID: El 29/6/2009, a las 17:15, Wincent Colaiuta escribi?: > El 29/6/2009, a las 16:26, Ben Mabey escribi?: > >> You probably know this, but for the benefit of others... Pat made a >> change a while back that makes it so the stubbed return value will >> still be returned even if an expectation is added. Meaning, >> assuming the stub is in the before block, you can change the >> expectation to: >> Comment.should_receive(:find).with(123) # this will still return >> @comment > > I didn't know that, but it's pretty awesome. Basically means that > RSpec mocks can double as proxies now. That's pretty neat. Er, I stand corrected. I went back looking for the change and found it (commit 72facc08), and then I re-read your description. Forget what I said about proxying. Cheers, Wincent From lists at ruby-forum.com Tue Jun 30 08:11:41 2009 From: lists at ruby-forum.com (Ninad Pol) Date: Tue, 30 Jun 2009 14:11:41 +0200 Subject: [rspec-users] Problem while generating rspec model in Rails Project In-Reply-To: <57c63afe0906150618o7feb45e1pa359303de19dcf6@mail.gmail.com> References: <6b6d18e516aac6bebcaa83dbf3222173@ruby-forum.com> <57c63afe0906120713s668371a5ta0fde3035282b4aa@mail.gmail.com> <57c63afe0906150534j6f7341a4n7436ff426fdc2687@mail.gmail.com> <9899a026050777dbe6b12120a7abbddd@ruby-forum.com> <57c63afe0906150618o7feb45e1pa359303de19dcf6@mail.gmail.com> Message-ID: <823764c95661937020a0850f5e8cc61f@ruby-forum.com> David Chelimsky wrote: > On Mon, Jun 15, 2009 at 8:04 AM, Ninad Pol wrote: >> I think this problem is not related any plugin (that define a client) >> simply because if i try it with any other ruby file(other than >> Client.rb) also i am facing same problem. > > So if you do this: > > rails widgets > cd widgets > script\generate model widget > script\generate rspec > script\generate rspec_model widget > > The last command tells you that Widget is already defined? > >> And what do you mean by some extension in the lib directory? > > I mean that you have a file in the lib directory in your Rails project > that defines a client. I believe that loading the rails env (which > happens when you run script\generate) loads the lib directory, so if > you have a file in there that defines Client, then you'd run into this > problem. I am so sorry for not being replying for so long.I was busy working with some other things and kept aside RSPEC. Above command does not gave me any problem for "widgets" and model with name "widget" was created. But in my project i am still getting the same problem as mentioned earlier. -- Posted via http://www.ruby-forum.com/. From zach.lists at gmail.com Tue Jun 30 13:00:39 2009 From: zach.lists at gmail.com (Zach Moazeni) Date: Tue, 30 Jun 2009 13:00:39 -0400 Subject: [rspec-users] Integrate or isolate views? In-Reply-To: <557cce2c2790af8aadbc90b257516df8@ruby-forum.com> References: <03369D62-AD08-4922-8D43-8289506E9AAC@benmabey.com> <2F96CC14-B30F-48A4-9899-E75E14DB114C@ultrasaurus.com> <557cce2c2790af8aadbc90b257516df8@ruby-forum.com> Message-ID: Jesse, I wrote a post that reflected on the pros/cons of testing views on a project of ours. http://simplechatter.com/2008/02/ascribe-a-case-study-on-view-specs/ I don't expect this to persuade anyone, but it was an attempt at an objective perspective. On Jun 28, 2009, at 3:16 PM, Jesse Crockett wrote: > IMO, this is what the RSpec Book needs (at this point in beta), > real-world conclusions based on experience, rather than "take it on > faith that you will 'revel' in the rewards." Thanks, Sarah -- Zach Moazeni http://simplechatter.com