From lists at ruby-forum.com Thu Nov 1 06:18:51 2007 From: lists at ruby-forum.com (Jamal Soueidan) Date: Thu, 1 Nov 2007 11:18:51 +0100 Subject: [rspec-users] autotest debugger? Message-ID: <443fc7e966293b678edc6ba2ef9c7423@ruby-forum.com> Hi, I keep facing problems with autotest, and I don't know what's happening in the background, is there anyway to know what's happening while testing? Example: @user = User.new @user.email = "testcom" @user.errors.on(:email).should_not be_empty ...throws error failure - 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.empty? ...but when I type this in ./script/console >> @user = User.new => # >> @user.valid? => false >> @user.email = "asd@" >> @user.errors.on 'email' => "is invalid" So how do you guys test things out and see what's happening behind? I'm lost :( Thanks in advance :) -- Posted via http://www.ruby-forum.com/. From pangel.neu at gmail.com Thu Nov 1 06:26:45 2007 From: pangel.neu at gmail.com (pangel) Date: Thu, 1 Nov 2007 03:26:45 -0700 (PDT) Subject: [rspec-users] Can't use #exactly when #and_return influences it. Message-ID: <13526196.post@talk.nabble.com> I want my class Reader to loop on the content of its Stack until false is returned. I also want an optional argument to exist that limits how many times the stack will be read, even if some elements are left. I was trying to spec this last bit but ended up on a false positive. Hope the example will be clear enough: #spec_reader.rb describe Reader do it "should stop reading items when called with a limit" do @stack = mock(Stack) Stack.should_receive(:new).and_return(@stack) @stack.should_receive(:read).exactly(3).times.and_return(2,4,1,5,3,1,false) @reader = Reader.new @reader.read_stack(3) end end # reader.rb class Reader def initialize @stack = Stack.new end def read_stack(limit = 0) #0 = read until false is returned while val = @stack.read # Not implemented on purpose! # return if limit == 0 # limit -= limit ... end end So the test should fail, because the use of the limit argument has not been implemented yet and #read gets called 7 times. But the test actually passes. I looked into it a bit and it seems that number of arguments in #and_return overrides the arguments of #exactly. Did I misunderstand the point of #exactly or should I build my code differently so that the value returned by #and_return does not influence how many times #read is called? -- View this message in context: http://www.nabble.com/Can%27t-use--exactly-when--and_return-influences-it.-tf4730412.html#a13526196 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Thu Nov 1 06:54:58 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Nov 2007 05:54:58 -0500 Subject: [rspec-users] Can't use #exactly when #and_return influences it. In-Reply-To: <13526196.post@talk.nabble.com> References: <13526196.post@talk.nabble.com> Message-ID: <57c63afe0711010354h233ba7fej77a35d9c1d8553b2@mail.gmail.com> On Nov 1, 2007 5:26 AM, pangel wrote: > > I want my class Reader to loop on the content of its Stack until false is > returned. I also want an optional argument to exist that limits how many > times the stack will be read, even if some elements are left. I was trying > to spec this last bit but ended up on a false positive. > > > Hope the example will be clear enough: > > #spec_reader.rb > describe Reader do > it "should stop reading items when called with a limit" do > @stack = mock(Stack) > Stack.should_receive(:new).and_return(@stack) > > @stack.should_receive(:read).exactly(3).times.and_return(2,4,1,5,3,1,false) This should probably not be allowed. > > @reader = Reader.new > @reader.read_stack(3) > end > end > > # reader.rb > class Reader > def initialize > @stack = Stack.new > end > > def read_stack(limit = 0) #0 = read until false is returned > while val = @stack.read > # Not implemented on purpose! > # return if limit == 0 > # limit -= limit > ... > end > end > > So the test should fail, because the use of the limit argument has not been > implemented yet and #read gets called 7 times. But the test actually passes. > I looked into it a bit and it seems that number of arguments in #and_return > overrides the arguments of #exactly. > > Did I misunderstand the point of #exactly or should I build my code > differently so that the value returned by #and_return does not influence how > many times #read is called? I think this is a bug, but the question is - what is the bug? I think the mock should complain when you set exactly(n).times and then give it a different number of return values. WDYT? From tom at experthuman.com Thu Nov 1 08:33:11 2007 From: tom at experthuman.com (Tom Stuart) Date: Thu, 1 Nov 2007 12:33:11 +0000 Subject: [rspec-users] Specifying mixins Message-ID: <9B6A2746-39BB-4716-9D0B-E56DEE6A1E99@experthuman.com> Hi folks, Can anyone share some accumulated wisdom about the best way to spec mixins in general, and (Jamis Buck-style) ActiveRecord "concerns" in particular? The standard situation here is that there's a bunch of functionality, related by concept if not by implementation, that one wants to inherit in many different classes (e.g. ActiveRecord models) without having to actually use subclassing -- straightforward enough. But since BDD best practice encourages one expectation per example and no mocking in the behaviour setup, the specification for this shared functionality is often spread across many behaviours, each of which may need to do its own setup and teardown. So, how best to mix the mixin spec in with the spec for each class that uses the mixin (IYSWIM)? I've tried several permutations of helpers, spec mixins, shared-shared behaviours and so on, but can't find anything which is persuasively neat and DRY while still working reliably. One point of contention is that the mixin's behaviours might need to do things like instantiate the target class with specific arguments in before :each (or call some other class method, if the mixin provides some) so it's not really good enough for the target spec to just squirrel away a prebuilt object in an instance variable. Any advice, please? Cheers, -Tom From pangel.neu at gmail.com Thu Nov 1 08:54:45 2007 From: pangel.neu at gmail.com (pangel) Date: Thu, 1 Nov 2007 05:54:45 -0700 (PDT) Subject: [rspec-users] Can't use #exactly when #and_return influences it. In-Reply-To: <57c63afe0711010354h233ba7fej77a35d9c1d8553b2@mail.gmail.com> References: <13526196.post@talk.nabble.com> <57c63afe0711010354h233ba7fej77a35d9c1d8553b2@mail.gmail.com> Message-ID: <13528094.post@talk.nabble.com> Yes this would make sense, or the mock could just stop sending the values as soon as it does not receive messages anymore. Obviously I prefer this second behaviour because it would, I think, make my specs work correctly. But from a logical point of view as well, this works for me. If the mock complains when there's more return values than expected calls, it would reduce the amount of errors, but it's usually a one-liner so the risk is not that great. On the other hand the second possibility (just stop sending values) would introduce a flexibility that might be handy in some situations. I'm quite a beginner in both ruby and TDD/BDD concepts so I feel like there's a lot I just don't have a full grasp on anyway. Regarding my specs do you think I should structure the whole thing differently? David Chelimsky-2 wrote: > > On Nov 1, 2007 5:26 AM, pangel wrote: >> >> I want my class Reader to loop on the content of its Stack until false is >> returned. I also want an optional argument to exist that limits how many >> times the stack will be read, even if some elements are left. I was >> trying >> to spec this last bit but ended up on a false positive. >> >> >> Hope the example will be clear enough: >> >> #spec_reader.rb >> describe Reader do >> it "should stop reading items when called with a limit" do >> @stack = mock(Stack) >> Stack.should_receive(:new).and_return(@stack) >> >> @stack.should_receive(:read).exactly(3).times.and_return(2,4,1,5,3,1,false) > > This should probably not be allowed. > >> >> @reader = Reader.new >> @reader.read_stack(3) >> end >> end >> >> # reader.rb >> class Reader >> def initialize >> @stack = Stack.new >> end >> >> def read_stack(limit = 0) #0 = read until false is returned >> while val = @stack.read >> # Not implemented on purpose! >> # return if limit == 0 >> # limit -= limit >> ... >> end >> end >> >> So the test should fail, because the use of the limit argument has not >> been >> implemented yet and #read gets called 7 times. But the test actually >> passes. >> I looked into it a bit and it seems that number of arguments in >> #and_return >> overrides the arguments of #exactly. >> >> Did I misunderstand the point of #exactly or should I build my code >> differently so that the value returned by #and_return does not influence >> how >> many times #read is called? > > I think this is a bug, but the question is - what is the bug? I think > the mock should complain when you set exactly(n).times and then give > it a different number of return values. > > WDYT? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- View this message in context: http://www.nabble.com/Can%27t-use--exactly-when--and_return-influences-it.-tf4730412.html#a13528094 Sent from the rspec-users mailing list archive at Nabble.com. From mailing_lists at railsnewbie.com Thu Nov 1 12:53:56 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 1 Nov 2007 12:53:56 -0400 Subject: [rspec-users] autotest debugger? In-Reply-To: <443fc7e966293b678edc6ba2ef9c7423@ruby-forum.com> References: <443fc7e966293b678edc6ba2ef9c7423@ruby-forum.com> Message-ID: <50915205-C638-4FB5-9458-A76EF8600708@railsnewbie.com> On Nov 1, 2007, at 6:18 AM, Jamal Soueidan wrote: > Hi, > > I keep facing problems with autotest, and I don't know what's > happening > in the background, is there anyway to know what's happening while > testing? > > Example: > @user = User.new > @user.email = "testcom" > @user.errors.on(:email).should_not be_empty > > ...throws error failure > This is not an autotest problem, this is a test problem. Usually I start adding extra tests: it "should not raise an error with a new user (exploratory test)" do lambda { User.new }.should_not raise_error end If that one fails...then it's a problem with my setup (before (:each))...and so on. If I really have no idea what's going on, I'll insert the following snippet to the top of the spec: require 'rubygems'; require 'ruby-debug'; debugger; (I use textmate, and have a snippet setup so that I can type "debug" tab, and the full line gets inserted) The next time autotest runs, it will drop me into the debugger (make sure you have the ruby-debug gem installed). Hope that helps, Scott > - 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.empty? > > ...but when I type this in ./script/console > >>> @user = User.new > => # logged_at: > nil, created_at: nil> >>> @user.valid? > => false >>> @user.email = "asd@" >>> @user.errors.on 'email' > => "is invalid" > > So how do you guys test things out and see what's happening behind? > I'm > lost :( > > Thanks in advance :) > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From work at ashleymoran.me.uk Thu Nov 1 15:09:34 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 1 Nov 2007 19:09:34 +0000 Subject: [rspec-users] Rspec Release Plan (was Am I missing something with Heckle?) In-Reply-To: References: <57c63afe0710310953g5ed40c26v5aecb111a227c84d@mail.gmail.com> Message-ID: <5D656B8F-505D-41BB-B277-B31DABEBB1D0@ashleymoran.me.uk> On Oct 31, 2007, at 7:33 pm, Jim Deville wrote: > Can I get that! That sounds nice... (probably simpler than i think) Sure, this is all there is to it: 2> ~/Documents/Development/bdd % cat update-rspec-gem.sh #!/usr/bin/env bash cd ~/Documents/Development/bdd/rspec-trunk svn update cd rspec rake clobber rake package sudo gem install pkg/*.gem svn update "~/Library/Application Support/TextMate/Pristine Copy/ Bundles/RSpec.tmbundle" Note it assumes your RSpec.tmbundle is checked out of trunk, and not either the MacroMates repository or the CURRENT tag, or something else. Ashley -- blog @ http://aviewfromafar.net/ linked-in @ http://www.linkedin.com/in/ashleymoran currently @ home From work at ashleymoran.me.uk Thu Nov 1 15:14:29 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 1 Nov 2007 19:14:29 +0000 Subject: [rspec-users] Rspec Release Plan (was Am I missing something with Heckle?) In-Reply-To: <57c63afe0710311246m456d13eblf9ee137ea640f6da@mail.gmail.com> References: <57c63afe0710310953g5ed40c26v5aecb111a227c84d@mail.gmail.com> <57c63afe0710311246m456d13eblf9ee137ea640f6da@mail.gmail.com> Message-ID: On Oct 31, 2007, at 7:46 pm, David Chelimsky wrote: > Interestingly enough, there is another thread today expressing > dissatisfaction with 1.x and trunk. Can't please everybody :) You could always do what Rails does and offer a beta gem repository, so you can install with --source ? That way you keep the numbering uninterrupted and still offer a pre-built latest version. Ashley -- blog @ http://aviewfromafar.net/ linked-in @ http://www.linkedin.com/in/ashleymoran currently @ home From hans at degraaff.org Thu Nov 1 15:50:41 2007 From: hans at degraaff.org (Hans de Graaff) Date: Thu, 01 Nov 2007 20:50:41 +0100 Subject: [rspec-users] Writing controller specs Message-ID: <1193402662.12714.1.camel@ip6-localhost> One thing that is bothering me about my controller specs is that sometimes I end up with a number of examples that are the same except for the example name. The reason that this happens is that I've expressed all the expected behavior with should_receive. While this does more or less work as intended it doesn't feel right. As an example, let's say I'm writing code to post a comment and record the IP address. First, let's handle the comment posting: describe 'post comment' do before do @data = {'text' => 'A comment that is posted'} @comment = mock_model(Comment) end it 'should be successful when proper input has been given' do Comment.should_receive(:new).with(@data).once.and_return(@comment) @comment.should_receive(:save).and_return(true) post :create, {:comment => @data} response.should be_success end end So far so good, although checking the response doesn't feel exactly right. Then again, the two expectations already cover the example, so checking the response could just as well be left out. Now, on to adding the recording of the IP address: it 'should record the IP address of the poster' do @comment.should_receive(:ip_address=).with('0.0.0.0') post :create, {:comment => @data} end Obviously this won't work because the @comment object has not been set up correctly. So, we should also add in that code: it 'should record the IP address of the poster' do Comment.should_receive(:new).with(@data).once.and_return(@comment) @comment.should_receive(:save).and_return(true) @comment.should_receive(:ip_address=).with('0.0.0.0') post :create, {:comment => @data} end But now the initial example won't work anymore because the mock model doesn't deal with the ip_address= method. Let's fix that as well: it 'should be successful when proper input has been given' do Comment.should_receive(:new).with(@data).once.and_return(@comment) @comment.should_receive(:save).and_return(true) @comment.should_receive(:ip_address=).with('0.0.0.0') post :create, {:comment => @data} response.should be_success end So now both methods look the same (minus the gratuitous response check) and it feels like something went wrong somewhere. It even becomes tempting to move the should_receive lines into the before-do block, but then the examples become essentially empty. Any comments on insight into this would be appreciated. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20071101/8b479d27/attachment.bin From hans at degraaff.org Thu Nov 1 16:25:02 2007 From: hans at degraaff.org (Hans de Graaff) Date: Thu, 01 Nov 2007 21:25:02 +0100 Subject: [rspec-users] rake spec:rcov failing In-Reply-To: References: Message-ID: <1193948702.32373.14.camel@ip6-localhost> On Sat, 2007-10-27 at 13:10 -0400, Scott Taylor wrote: > Running rails 1.2.3, rcov (0.8.0.2), rspec trunk (2865) - > > When running rake spec:rcov, I'm getting the following: > > Finished in 245.717813 seconds > > 856 examples, 0 failures, 48 pending > /usr/local/lib/ruby/1.8/rexml/text.rb:292:in `normalize': private > method `gsub' called for 0:Fixnum (NoMethodError) I guess you are using a really new version of ruby? The latest patch levels seem to include a version of rexml that isn't compatible with rcov. The rcov code thinks it can pass Fixnum's as the value of an attribute while building the HTML summary page, but apparently the latest version of rexml no longer allows this. I haven't had time to figure out if this change in rexml is intentional or not, and thus whether rexml or rcov needs fixing. Kind regards, Hans de Graaff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20071101/b6679549/attachment.bin From jeremy.stephens at vanderbilt.edu Thu Nov 1 17:08:39 2007 From: jeremy.stephens at vanderbilt.edu (Jeremy Stephens) Date: Thu, 1 Nov 2007 16:08:39 -0500 Subject: [rspec-users] no speed up with spec_server Message-ID: <200711011608.39357.jeremy.stephens@vanderbilt.edu> Hey guys, I'm running spec_server and using --drb with my specs in Rails, and I'm seeing virtually no speed up. I'm using rspec/rspec_on_rails trunk. Is there something I'm doing wrong? TIA, Jeremy -- Jeremy Stephens Computer Systems Analyst I School of Medicine Department of Biostatistics Vanderbilt University From lists at ruby-forum.com Thu Nov 1 17:24:46 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Thu, 1 Nov 2007 22:24:46 +0100 Subject: [rspec-users] Can't delete app/helpers Message-ID: <6a81e9ca41ab7dcea40355ab01652756@ruby-forum.com> I would like to remove some unused helpers from the app/helpers dir, but when I do so my specs fail. Why is this? I don't see where those helpers are referenced within the tests. Is there a way to delete these unused files? Thanks -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Thu Nov 1 19:27:10 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 2 Nov 2007 00:27:10 +0100 Subject: [rspec-users] no speed up with spec_server In-Reply-To: <200711011608.39357.jeremy.stephens@vanderbilt.edu> References: <200711011608.39357.jeremy.stephens@vanderbilt.edu> Message-ID: <8d961d900711011627n18dae788n9ec50ef83603946a@mail.gmail.com> On 11/1/07, Jeremy Stephens wrote: > Hey guys, > > I'm running spec_server and using --drb with my specs in Rails, and > I'm seeing virtually no speed up. I'm using rspec/rspec_on_rails > trunk. Is there something I'm doing wrong? > It's a regression I'm planning to fix this weekend Aslak > TIA, > Jeremy > -- > Jeremy Stephens Computer Systems Analyst I School of Medicine > Department of Biostatistics Vanderbilt University > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Thu Nov 1 19:27:50 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 2 Nov 2007 00:27:50 +0100 Subject: [rspec-users] Can't delete app/helpers In-Reply-To: <6a81e9ca41ab7dcea40355ab01652756@ruby-forum.com> References: <6a81e9ca41ab7dcea40355ab01652756@ruby-forum.com> Message-ID: <8d961d900711011627g721b9335re0de9e5a360b39ef@mail.gmail.com> A stacktrace would help On 11/1/07, Chris Olsen wrote: > I would like to remove some unused helpers from the app/helpers dir, but > when I do so my specs fail. > > Why is this? I don't see where those helpers are referenced within the > tests. Is there a way to delete these unused files? > > Thanks > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Thu Nov 1 19:30:02 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 2 Nov 2007 00:30:02 +0100 Subject: [rspec-users] Specifying mixins In-Reply-To: <9B6A2746-39BB-4716-9D0B-E56DEE6A1E99@experthuman.com> References: <9B6A2746-39BB-4716-9D0B-E56DEE6A1E99@experthuman.com> Message-ID: <8d961d900711011630i7fc4e2aerfbaf157308e666be@mail.gmail.com> just a short advice: describe MyModule do it "should do something" do # The module is automatically mixed into your spec end end Aslak On 11/1/07, Tom Stuart wrote: > Hi folks, > > Can anyone share some accumulated wisdom about the best way to spec > mixins in general, and (Jamis Buck-style) ActiveRecord "concerns" in > particular? > > The standard situation here is that there's a bunch of functionality, > related by concept if not by implementation, that one wants to inherit > in many different classes (e.g. ActiveRecord models) without having to > actually use subclassing -- straightforward enough. But since BDD best > practice encourages one expectation per example and no mocking in the > behaviour setup, the specification for this shared functionality is > often spread across many behaviours, each of which may need to do its > own setup and teardown. > > So, how best to mix the mixin spec in with the spec for each class > that uses the mixin (IYSWIM)? I've tried several permutations of > helpers, spec mixins, shared-shared behaviours and so on, but can't > find anything which is persuasively neat and DRY while still working > reliably. One point of contention is that the mixin's behaviours might > need to do things like instantiate the target class with specific > arguments in before :each (or call some other class method, if the > mixin provides some) so it's not really good enough for the target > spec to just squirrel away a prebuilt object in an instance variable. > > Any advice, please? > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Nov 1 19:39:57 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Fri, 2 Nov 2007 00:39:57 +0100 Subject: [rspec-users] Can't delete app/helpers In-Reply-To: <8d961d900711011627g721b9335re0de9e5a360b39ef@mail.gmail.com> References: <6a81e9ca41ab7dcea40355ab01652756@ruby-forum.com> <8d961d900711011627g721b9335re0de9e5a360b39ef@mail.gmail.com> Message-ID: > A stacktrace would help /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S script/spec -O spec/spec.opts spec/views/addresses/show.rhtml_spec.rb spec/helpers/addresses_helper_spec.rb spec/views/addresses/index.rhtml_spec.rb spec/views/addresses/edit.rhtml_spec.rb spec/views/addresses/new.rhtml_spec.rb /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:249:in `load_missing_constant': Expected /Users/chris/Documents/Projects/Rails/MyProject/trunk/config/../app/helpers/addresses_helper.rb to define AddressesHelper (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:452:in `const_missing' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:464:in `const_missing' from ./spec/views/addresses/show.rhtml_spec.rb:4 from /Users/chris/Documents/Projects/Rails/MyProject/trunk/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:54:in `class_eval' from /Users/chris/Documents/Projects/Rails/MyProject/trunk/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:54:in `eval_behaviour' from /Users/chris/Documents/Projects/Rails/MyProject/trunk/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:31:in `initialize' from /Users/chris/Documents/Projects/Rails/MyProject/trunk/vendor/plugins/rspec/lib/spec/dsl/behaviour_factory.rb:36:in `new' from /Users/chris/Documents/Projects/Rails/MyProject/trunk/vendor/plugins/rspec/lib/spec/dsl/behaviour_factory.rb:36:in `create' ... 21 levels... from /Users/chris/Documents/Projects/Rails/MyProject/trunk/vendor/plugins/rspec/lib/spec/runner/option_parser.rb:155:in `parse' from /Users/chris/Documents/Projects/Rails/MyProject/trunk/vendor/plugins/rspec/lib/spec/runner/option_parser.rb:88:in `create_behaviour_runner' from /Users/chris/Documents/Projects/Rails/MyProject/trunk/vendor/plugins/rspec/lib/spec/runner/command_line.rb:14:in `run' from script/spec:4 -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Thu Nov 1 21:15:13 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 1 Nov 2007 21:15:13 -0400 Subject: [rspec-users] no speed up with spec_server In-Reply-To: <200711011608.39357.jeremy.stephens@vanderbilt.edu> References: <200711011608.39357.jeremy.stephens@vanderbilt.edu> Message-ID: On Nov 1, 2007, at 5:08 PM, Jeremy Stephens wrote: > Hey guys, > > I'm running spec_server and using --drb with my specs in Rails, and > I'm seeing virtually no speed up. I'm using rspec/rspec_on_rails > trunk. Is there something I'm doing wrong? > Same here. AFAIK, all the drb server does is load up the rails environment. This should save you a good 2-3 seconds every time you run your tests, but there are other speed hits - - The test database needs to be recreated - The classes in app + lib need to be re-loaded And so on... The most obvious speed hit is actually loading data into the database, as well as reading it out, and at least for me, the 2-3 seconds for loading the environment isn't noticeable either way if I'm actually hitting the database in a model spec. Maybe that would be your case as well? Scott From mailing_lists at railsnewbie.com Thu Nov 1 21:16:21 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 1 Nov 2007 21:16:21 -0400 Subject: [rspec-users] no speed up with spec_server In-Reply-To: <8d961d900711011627n18dae788n9ec50ef83603946a@mail.gmail.com> References: <200711011608.39357.jeremy.stephens@vanderbilt.edu> <8d961d900711011627n18dae788n9ec50ef83603946a@mail.gmail.com> Message-ID: <211672AC-7C34-4D40-AD83-86C7D8D26283@railsnewbie.com> On Nov 1, 2007, at 7:27 PM, aslak hellesoy wrote: > On 11/1/07, Jeremy Stephens wrote: >> Hey guys, >> >> I'm running spec_server and using --drb with my specs in Rails, and >> I'm seeing virtually no speed up. I'm using rspec/rspec_on_rails >> trunk. Is there something I'm doing wrong? >> > > It's a regression I'm planning to fix this weekend > > Aslak Ah - didn't see your post. Scott From mailing_lists at railsnewbie.com Thu Nov 1 21:18:18 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 1 Nov 2007 21:18:18 -0400 Subject: [rspec-users] Specifying mixins In-Reply-To: <8d961d900711011630i7fc4e2aerfbaf157308e666be@mail.gmail.com> References: <9B6A2746-39BB-4716-9D0B-E56DEE6A1E99@experthuman.com> <8d961d900711011630i7fc4e2aerfbaf157308e666be@mail.gmail.com> Message-ID: On Nov 1, 2007, at 7:30 PM, aslak hellesoy wrote: > just a short advice: > > describe MyModule do > it "should do something" do > # The module is automatically mixed into your spec > end > end > > Aslak I suppose it really depends on how static/dynamic the module is. This seems to work well for a relatively static case, but how you spec out a module like Enumerable in this manner (in which a series of methods is added to class if a method is implemented in the class - in the case, #each)? Scott From hans at degraaff.org Fri Nov 2 02:31:51 2007 From: hans at degraaff.org (Hans de Graaff) Date: Fri, 02 Nov 2007 07:31:51 +0100 Subject: [rspec-users] Can't delete app/helpers In-Reply-To: References: <6a81e9ca41ab7dcea40355ab01652756@ruby-forum.com> <8d961d900711011627g721b9335re0de9e5a360b39ef@mail.gmail.com> Message-ID: <1193985111.5400.0.camel@ip6-localhost> On Fri, 2007-11-02 at 00:39 +0100, Chris Olsen wrote: > > A stacktrace would help > > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S > script/spec -O spec/spec.opts spec/views/addresses/show.rhtml_spec.rb > spec/helpers/addresses_helper_spec.rb Looks like you still have a (possibly generated?) spec for this helper. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20071102/2f55c50a/attachment.bin From lists at ruby-forum.com Fri Nov 2 04:48:52 2007 From: lists at ruby-forum.com (Jamal Soueidan) Date: Fri, 2 Nov 2007 09:48:52 +0100 Subject: [rspec-users] autotest debugger? In-Reply-To: <50915205-C638-4FB5-9458-A76EF8600708@railsnewbie.com> References: <443fc7e966293b678edc6ba2ef9c7423@ruby-forum.com> <50915205-C638-4FB5-9458-A76EF8600708@railsnewbie.com> Message-ID: Scott Taylor wrote: > On Nov 1, 2007, at 6:18 AM, Jamal Soueidan wrote: > >> @user.errors.on(:email).should_not be_empty >> >> ...throws error failure >> > > This is not an autotest problem, this is a test problem. > > Usually I start adding extra tests: > > it "should not raise an error with a new user (exploratory test)" do > lambda { > User.new > }.should_not raise_error > end > > If that one fails...then it's a problem with my setup (before > (:each))...and so on. > > If I really have no idea what's going on, I'll insert the following > snippet to the top of the spec: > > require 'rubygems'; require 'ruby-debug'; debugger; > > (I use textmate, and have a snippet setup so that I can type "debug" > tab, and the full line gets inserted) > > The next time autotest runs, it will drop me into the debugger (make > sure you have the ruby-debug gem installed). > > Hope that helps, > > Scott I tried to insert the requiring files etc. and went into the debugger, but how do I use it ? $ autotest loading autotest/rails_rspec /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S script/spec -O spec/spec.opts spec/controllers/user_controller_spec.rb spec/models/user_spec.rb spec/helpers/user_helper_spec.rb spec/controllers/video_controller_spec.rb spec/helpers/video_helper_spec.rb ./spec/controllers/user_controller_spec.rb:5 require File.dirname(__FILE__) + '/../spec_helper' (rdb:1) user = User.new Adjusting would put us beyond the oldest (initial) frame. (rdb:1) user.email = "test" Adjusting would put us beyond the oldest (initial) frame. (rdb:1) user.should_not be_valid Adjusting would put us beyond the oldest (initial) frame. (rdb:1) -- Posted via http://www.ruby-forum.com/. From harm.aarts at innovationfactory.nl Fri Nov 2 08:27:04 2007 From: harm.aarts at innovationfactory.nl (Harm Aarts) Date: Fri, 2 Nov 2007 13:27:04 +0100 Subject: [rspec-users] RSpec, RESTful nested routes and :path_prefix Message-ID: <692D270E-F6B1-431B-933E-732B46B49010@innovationfactory.nl> Dear list, In the app we are making we have a rout something like this: map.resources :projects do |projects| projects.resources :pages, :controller =>"Wiki::Pages", :path_prefix => "/projects/:project_id/ wiki", :name_prefix => "project_wiki_" end But I can't get RSpec(I'm very new to it) to accept this. It keeps throwing errors: ActionController::RoutingError in 'Wiki::PagesController POST 'create' should be successful' No route matches {:action=>"create", :controller=>"wiki/ pages", :project_id=>1, :page => {}} I get why it throws these errors but not how to fix it. The relavant RSpec: it "GET 'create' should be successful" do post 'create', :project_id => 1, :page => {} response.should be_success end How do I modify the get request properly? Thanks in advance! From lists at ruby-forum.com Fri Nov 2 10:58:20 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Fri, 2 Nov 2007 15:58:20 +0100 Subject: [rspec-users] Can't delete app/helpers In-Reply-To: <1193985111.5400.0.camel@ip6-localhost> References: <6a81e9ca41ab7dcea40355ab01652756@ruby-forum.com> <8d961d900711011627g721b9335re0de9e5a360b39ef@mail.gmail.com> <1193985111.5400.0.camel@ip6-localhost> Message-ID: <9a4133c591f0374d105f14945bbfe4df@ruby-forum.com> Hans de Graaff wrote: > Looks like you still have a (possibly generated?) spec for this helper. > > Kind regards, > > Hans I do, but the issue is that it requires the app/helpers/addresses_helper.rb file, which is that one that I am trying to delete. `load_missing_constant': Expected /Users/chris/Documents/Projects/Rails/MyProject/trunk/config/../app/helpers/addresses_helper.rb to define AddressesHelper (LoadError) I seem to remember being able to delete helpers. I would think that these auto references that exist would check if the file exists before trying to include them. Is this not possible? Thanks for the help. -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Fri Nov 2 13:21:49 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 2 Nov 2007 13:21:49 -0400 Subject: [rspec-users] autotest debugger? In-Reply-To: References: <443fc7e966293b678edc6ba2ef9c7423@ruby-forum.com> <50915205-C638-4FB5-9458-A76EF8600708@railsnewbie.com> Message-ID: <7AC5E890-0E72-41FF-A95F-B3A2EF941BDA@railsnewbie.com> On Nov 2, 2007, at 4:48 AM, Jamal Soueidan wrote: > Scott Taylor wrote: >> On Nov 1, 2007, at 6:18 AM, Jamal Soueidan wrote: >> >>> @user.errors.on(:email).should_not be_empty >>> >>> ...throws error failure >>> >> >> This is not an autotest problem, this is a test problem. >> >> Usually I start adding extra tests: >> >> it "should not raise an error with a new user (exploratory test)" do >> lambda { >> User.new >> }.should_not raise_error >> end >> >> If that one fails...then it's a problem with my setup (before >> (:each))...and so on. >> >> If I really have no idea what's going on, I'll insert the following >> snippet to the top of the spec: >> >> require 'rubygems'; require 'ruby-debug'; debugger; >> >> (I use textmate, and have a snippet setup so that I can type "debug" >> tab, and the full line gets inserted) >> >> The next time autotest runs, it will drop me into the debugger (make >> sure you have the ruby-debug gem installed). >> >> Hope that helps, >> >> Scott > > I tried to insert the requiring files etc. and went into the debugger, > but how do I use it ? > > $ autotest > loading autotest/rails_rspec > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S > script/spec -O spec/spec.opts spec/controllers/ > user_controller_spec.rb > spec/models/user_spec.rb spec/helpers/user_helper_spec.rb > spec/controllers/video_controller_spec.rb > spec/helpers/video_helper_spec.rb > ./spec/controllers/user_controller_spec.rb:5 require > File.dirname(__FILE__) + '/../spec_helper' > (rdb:1) user = User.new > Adjusting would put us beyond the oldest (initial) frame. > (rdb:1) user.email = "test" > Adjusting would put us beyond the oldest (initial) frame. > (rdb:1) user.should_not be_valid > Adjusting would put us beyond the oldest (initial) frame. > (rdb:1) > -- > Posted via http://www.ruby-forum.com/. Google for the ruby-debugger. The most common commands are: h - help c - continue p - print (so p user = User.new) irb - drops you into irb b - breakpoint l - list where you are in the code And so on. I would advise looking up the tutorial, though. Scott From vertebrate at gmail.com Fri Nov 2 17:59:11 2007 From: vertebrate at gmail.com (Steve) Date: Fri, 2 Nov 2007 21:59:11 +0000 (UTC) Subject: [rspec-users] Test that controller includes helpers? Message-ID: Is there an easy way to spec that a controller should include helpers other than its own? I was thinking I could just spec responds_to for methods I'm interested in in the view, but that seems like crossing a separation boundary, that the controller maybe doesn't need to know about? Thanks, Steve From nola at rubygeek.com Fri Nov 2 19:59:56 2007 From: nola at rubygeek.com (Nola Stowe) Date: Fri, 2 Nov 2007 19:59:56 -0400 Subject: [rspec-users] RSpec, RESTful nested routes and :path_prefix In-Reply-To: <692D270E-F6B1-431B-933E-732B46B49010@innovationfactory.nl> References: <692D270E-F6B1-431B-933E-732B46B49010@innovationfactory.nl> Message-ID: <43e95380711021659n73321ca1m4a28504ea2ecc7a5@mail.gmail.com> I had a problem when I used: script/generate rspec_scaffold "admin/users" it created the specs with the controller name is "admin_user" instead of "admin/user" which I think should be correct. So I had to go through all the rspec generated files and change the _ to / I actually would like to investigate to see if this is a bug and see if maybe I can write a patch... I would like to contribute! I really like rspec. :) did you use rspec_scaffolding? I don't know if this is the same issue, I would have to see more of your spec file. On 11/2/07, Harm Aarts wrote: > Dear list, > > In the app we are making we have a rout something like this: > map.resources :projects do |projects| > projects.resources :pages, :controller > =>"Wiki::Pages", :path_prefix => "/projects/:project_id/ > wiki", :name_prefix => "project_wiki_" > end > > But I can't get RSpec(I'm very new to it) to accept this. It keeps > throwing errors: > ActionController::RoutingError in 'Wiki::PagesController POST > 'create' should be successful' > No route matches {:action=>"create", :controller=>"wiki/ > pages", :project_id=>1, :page => {}} > > I get why it throws these errors but not how to fix it. The relavant > RSpec: > it "GET 'create' should be successful" do > post 'create', :project_id => 1, :page => {} > response.should be_success > end > > How do I modify the get request properly? > Thanks in advance! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://rubygeek.com - my blog featuring: Ruby, PHP and Perl http://DevChix.com - boys can't have all the fun From peter at netsprout.com Fri Nov 2 20:32:22 2007 From: peter at netsprout.com (Peter) Date: Fri, 2 Nov 2007 17:32:22 -0700 Subject: [rspec-users] Specs for Helpers that call render Message-ID: <9132764E-8756-4B6C-81D5-5F2B8B43DAB7@netsprout.com> The helper spec I am writing tests a helper method that calls render. ## module HelperHelper def render_partial render :partial => 'partial' end end ## The helper spec. ## describe HelperHelper do it "should render partial" do render_partial.should_not == nil end end ## The output generated ## $ spec spec/helpers/home_helper_spec.rb .F 1) NoMethodError in 'HelperHelper should render partial' You have a nil object when you didn't expect it! The error occurred while evaluating nil.render app/helpers/helper_helper.rb:4:in `render_partial' ./spec/helpers/helper_helper_spec.rb:3: Finished in 0.00000 seconds 1 example, 1 failure ## I tried adding a before(:each) to setup response, controller, and template objects that render would be called on but the error was always the same. I am still uncertain I did this correctly although I did spend some time looking at the render definition in the rails source. Is there a standard way of setting up specs for helpers that call render? - Peter (I apologize if this has already been answered. We spent a good deal of time searching around the web for a solution but came up empty so far.) From mrnicksgirl at gmail.com Fri Nov 2 19:56:22 2007 From: mrnicksgirl at gmail.com (Nola Stowe) Date: Fri, 2 Nov 2007 19:56:22 -0400 Subject: [rspec-users] RSpec, RESTful nested routes and :path_prefix In-Reply-To: <692D270E-F6B1-431B-933E-732B46B49010@innovationfactory.nl> References: <692D270E-F6B1-431B-933E-732B46B49010@innovationfactory.nl> Message-ID: <43e95380711021656y4369ecb2wf3053d30b5556c51@mail.gmail.com> I had a problem when I used: script/generate rspec_scaffold "admin/users" it created the specs with the controller name is "admin_user" instead of "admin/user" which I think should be correct. So I had to go through all the rspec generated files and change the _ to / did you use rspec_scaffolding? I don't know if this is the same issue, I would have to see more of your spec file. On 11/2/07, Harm Aarts wrote: > Dear list, > > In the app we are making we have a rout something like this: > map.resources :projects do |projects| > projects.resources :pages, :controller > =>"Wiki::Pages", :path_prefix => "/projects/:project_id/ > wiki", :name_prefix => "project_wiki_" > end > > But I can't get RSpec(I'm very new to it) to accept this. It keeps > throwing errors: > ActionController::RoutingError in 'Wiki::PagesController POST > 'create' should be successful' > No route matches {:action=>"create", :controller=>"wiki/ > pages", :project_id=>1, :page => {}} > > I get why it throws these errors but not how to fix it. The relavant > RSpec: > it "GET 'create' should be successful" do > post 'create', :project_id => 1, :page => {} > response.should be_success > end > > How do I modify the get request properly? > Thanks in advance! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://rubygeek.com - my blog featuring: Ruby, PHP and Perl http://DevChix.com - boys can't have all the fun From shane.wolf at zvents.com Fri Nov 2 02:36:02 2007 From: shane.wolf at zvents.com (Shane Wolf) Date: Thu, 1 Nov 2007 23:36:02 -0700 Subject: [rspec-users] stub calls to an instance method before it is created? Message-ID: <57b8de400711012336w50574d0cr71e3324c02406b8d@mail.gmail.com> I am desperately in need of functionality such as Mocha offers with their any_instance method. I see that there is an open ticket for a similar feature in RSpec, but it does not look like anything have been done. Is there any other way around this? https://rubyforge.org/tracker/index.php?func=detail&aid=6791&group_id=797&atid=3152 Here is what I am doing, and why I feel I need this (maybe my design is inherently wrong) Given a model called Foo def Foo.create_from_form foo = Foo.new # Do all kinds of crazy stuff here foo.save end In my specs I want to stub the foo.save call to return true or false depending on the case, so that it doesn't actually try and save to the DB... is there any way around this since I do not actually know the instance of the class I am trying to stub? Shane -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071101/91a75ce4/attachment.html From dchelimsky at gmail.com Sat Nov 3 01:38:50 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 3 Nov 2007 01:38:50 -0400 Subject: [rspec-users] stub calls to an instance method before it is created? In-Reply-To: <57b8de400711012336w50574d0cr71e3324c02406b8d@mail.gmail.com> References: <57b8de400711012336w50574d0cr71e3324c02406b8d@mail.gmail.com> Message-ID: <57c63afe0711022238l8361d49q90063f8b5a380fc8@mail.gmail.com> On Nov 2, 2007 2:36 AM, Shane Wolf wrote: > I am desperately in need of functionality such as Mocha offers with their > any_instance method. I see that there is an open ticket for a similar > feature in RSpec, but it does not look like anything have been done. Is > there any other way around this? > > https://rubyforge.org/tracker/index.php?func=detail&aid=6791&group_id=797&atid=3152 > > Here is what I am doing, and why I feel I need this (maybe my design is > inherently wrong) > > Given a model called Foo > > def Foo.create_from_form > foo = Foo.new > # Do all kinds of crazy stuff here > foo.save > end > > In my specs I want to stub the foo.save call to return true or false > depending on the case, so that it doesn't actually try and save to the DB... > is there any way around this since I do not actually know the instance of > the class I am trying to stub? foo = mock("foo") Foo.stub!(:new).and_return(foo) foo.should_receive(:all_kinds_of_crazy_stuff) Foo.create_from_form(arg, arg, arg).should equal(foo) From dchelimsky at gmail.com Sat Nov 3 01:46:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 3 Nov 2007 01:46:38 -0400 Subject: [rspec-users] Specs for Helpers that call render In-Reply-To: <9132764E-8756-4B6C-81D5-5F2B8B43DAB7@netsprout.com> References: <9132764E-8756-4B6C-81D5-5F2B8B43DAB7@netsprout.com> Message-ID: <57c63afe0711022246q566c3ed0p1607ff22589a3bd3@mail.gmail.com> On Nov 2, 2007 8:32 PM, Peter wrote: > The helper spec I am writing tests a helper method that calls render. > > ## > module HelperHelper > def render_partial > render :partial => 'partial' > end > end > ## > > The helper spec. > > ## > describe HelperHelper do > it "should render partial" do > render_partial.should_not == nil > end > end > ## > > The output generated > > ## > $ spec spec/helpers/home_helper_spec.rb > .F > > 1) > NoMethodError in 'HelperHelper should render partial' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.render > app/helpers/helper_helper.rb:4:in `render_partial' > ./spec/helpers/helper_helper_spec.rb:3: > > Finished in 0.00000 seconds > > 1 example, 1 failure > ## > > I tried adding a before(:each) to setup response, controller, and > template objects that render would be called on but the error was > always the same. I am still uncertain I did this correctly although > I did spend some time looking at the render definition in the rails > source. > > Is there a standard way of setting up specs for helpers that call > render? Helper specs create an object to run in and include a standard set of helpers and the helper you are spec'ing. There is no access to services that come from the controllers or views the helper gets mixed into when the app is running. I would just set a message expectation on self, like this: describe HelperHelper do it "should render partial" do self.should_receive(:render).with(:partial => 'partial') render_partial end end HTH, David From dchelimsky at gmail.com Sat Nov 3 02:00:56 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 3 Nov 2007 02:00:56 -0400 Subject: [rspec-users] Test that controller includes helpers? In-Reply-To: References: Message-ID: <57c63afe0711022300r8ecf4c1o30b5501764b438b2@mail.gmail.com> On Nov 2, 2007 5:59 PM, Steve wrote: > Is there an easy way to spec that a controller should include helpers > other than its own? I was thinking I could just spec responds_to for > methods I'm interested in in the view, but that seems like crossing a > separation boundary, that the controller maybe doesn't need to know about? FWIW, by asking you to declare helpers in controllers so that views can access their goodness, Rails is already forcing you to cross that boundary. So whatever you do here is a compromise and you just need to find the lesser of evils. I think the most pragmatic thing to do would be to use a controller spec with integrate_views and describe what the view should look like when it uses one of the included methods. Alternatively could load the file and expect the declaration (but that's somewhat controversial on this list). HTH, David From hans at degraaff.org Sat Nov 3 08:51:16 2007 From: hans at degraaff.org (Hans de Graaff) Date: Sat, 03 Nov 2007 13:51:16 +0100 Subject: [rspec-users] Can't delete app/helpers In-Reply-To: <9a4133c591f0374d105f14945bbfe4df@ruby-forum.com> References: <6a81e9ca41ab7dcea40355ab01652756@ruby-forum.com> <8d961d900711011627g721b9335re0de9e5a360b39ef@mail.gmail.com> <1193985111.5400.0.camel@ip6-localhost> <9a4133c591f0374d105f14945bbfe4df@ruby-forum.com> Message-ID: <1194094276.22355.3.camel@ip6-localhost> On Fri, 2007-11-02 at 15:58 +0100, Chris Olsen wrote: > Hans de Graaff wrote: > > Looks like you still have a (possibly generated?) spec for this helper. > > > > Kind regards, > > > > Hans > > I do, but the issue is that it requires the > app/helpers/addresses_helper.rb file, which is that one that I am trying > to delete. If there is still a spec file that references the helper then it can't be removed without causing spec failures. You should also remove the spec for the helper for the specs to run without problems. If that sounds obvious then you might be trying to do something more complicated in which case some more explanation of what you are trying to achieve would be helpful. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20071103/16c08807/attachment.bin From vertebrate at gmail.com Sat Nov 3 11:25:26 2007 From: vertebrate at gmail.com (Steve) Date: Sat, 3 Nov 2007 15:25:26 +0000 (UTC) Subject: [rspec-users] Test that controller includes helpers? References: <57c63afe0711022300r8ecf4c1o30b5501764b438b2@mail.gmail.com> Message-ID: On Sat, 03 Nov 2007 02:00:56 -0400, David Chelimsky wrote: > FWIW, by asking you to declare helpers in controllers so that views > can access their goodness, Rails is already forcing you to cross that > boundary. So whatever you do here is a compromise and you just need to > find the lesser of evils. > > I think the most pragmatic thing to do would be to use a controller > spec with integrate_views and describe what the view should look like > when it uses one of the included methods. Alternatively could load the > file and expect the declaration (but that's somewhat controversial on > this list). > > HTH, > David Yeah, I'm not terribly interested in the reloading of the file. That was too much of a pain last time with my models and I opted not to do it. I'd rather not integrate the view if I can avoid it. Is there a way to get at the controller instance that was called though? If I could do that, I could simply check for a responds_to at the very least, right? I understand what you mean by blurring the lines though. Steve From raasdnil at gmail.com Sun Nov 4 04:55:54 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Sun, 4 Nov 2007 20:55:54 +1100 Subject: [rspec-users] Specing raising error, handling, and then not raising error Message-ID: <57a815bf0711040155o1cbfd10dj907db6a7623eefa4@mail.gmail.com> Hey guys and gals, I have a snippet of code: Net::SMTP(@host, @port, @from_domain) do |smtp| @emails.each do |email| begin smtp.send_message email.encoded, email.from, email.destinations @emails_sent += 1 rescue Exception => e # blah end end end What I want to do is: Say there are 4 emails. First email is sent OK On the second email smtp raises a IOError error The third and fourth emails are sent OK I want to spec: That the second iteration raises an error. That the total emails sent count changed by 3 I can't seem to figure out how to stub/mock the smtp object to return an email on the 1, 3, and 4th iteration and raise an error on the 2nd iteration. I thought something like this, but it doesn't work: it "should only increase the sent emails counter if the email was sent" do @smtp = mock(Net::SMTP) @smtp.should_receive(:send_message).exactly(4).times.and_return(true, IOError, true, true) Net::SMTP.stub!(:start).and_yield(@smtp) @sender = Mailer::Sender.new(valid_args(:emails => @emails)) @sender.sent_emails.should == 3 end If anyone has any pointers, that would be great. I am using rSpec trunk - today's release. Mikel From harm.aarts at innovationfactory.nl Sun Nov 4 09:46:13 2007 From: harm.aarts at innovationfactory.nl (Harm Aarts) Date: Sun, 4 Nov 2007 15:46:13 +0100 Subject: [rspec-users] RSpec, RESTful nested routes and :path_prefix In-Reply-To: References: Message-ID: I do not believe that is the case here. I used 'script/genereate rspec_controller wiki::pages' and that generated spec files in 'spec/ controllers/wiki/pages_controller_spec.rb'. So that seemed to be in order. Excerpt: require File.dirname(__FILE__) + '/../../spec_helper' describe Wiki::PagesController do fixtures :projects #Delete these examples and add some real ones it "should use Wiki::PagesController" do controller.should be_an_instance_of(Wiki::PagesController) end it "GET 'index' should be successful" do get 'index', :project_id => 1 response.should be_success end end Seems OK right? Does RSpec not support nested routes with :path_prefix? Harm > ------------------------------ > > Message: 11 > Date: Fri, 2 Nov 2007 19:56:22 -0400 > From: "Nola Stowe" > Subject: Re: [rspec-users] RSpec, RESTful nested routes and > :path_prefix > To: rspec-users > Message-ID: > <43e95380711021656y4369ecb2wf3053d30b5556c51 at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > I had a problem when I used: > > script/generate rspec_scaffold "admin/users" > > it created the specs with the controller name is "admin_user" instead > of "admin/user" which I think should be correct. So I had to go > through all the rspec generated files and change the _ to / > > did you use rspec_scaffolding? > > I don't know if this is the same issue, I would have to see more of > your spec file. > > > > On 11/2/07, Harm Aarts wrote: >> Dear list, >> >> In the app we are making we have a rout something like this: >> map.resources :projects do |projects| >> projects.resources :pages, :controller >> =>"Wiki::Pages", :path_prefix => "/projects/:project_id/ >> wiki", :name_prefix => "project_wiki_" >> end >> >> But I can't get RSpec(I'm very new to it) to accept this. It keeps >> throwing errors: >> ActionController::RoutingError in 'Wiki::PagesController POST >> 'create' should be successful' >> No route matches {:action=>"create", :controller=>"wiki/ >> pages", :project_id=>1, :page => {}} >> >> I get why it throws these errors but not how to fix it. The relavant >> RSpec: >> it "GET 'create' should be successful" do >> post 'create', :project_id => 1, :page => {} >> response.should be_success >> end >> >> How do I modify the get request properly? >> Thanks in advance! >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > -- > http://rubygeek.com - my blog featuring: Ruby, PHP and Perl > http://DevChix.com - boys can't have all the fun > > > ------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > End of rspec-users Digest, Vol 17, Issue 3 > ****************************************** From work at ashleymoran.me.uk Sun Nov 4 10:20:15 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Sun, 4 Nov 2007 15:20:15 +0000 Subject: [rspec-users] Specing raising error, handling, and then not raising error In-Reply-To: <57a815bf0711040155o1cbfd10dj907db6a7623eefa4@mail.gmail.com> References: <57a815bf0711040155o1cbfd10dj907db6a7623eefa4@mail.gmail.com> Message-ID: On Nov 04, 2007, at 9:55 am, Mikel Lindsaar wrote: > it "should only increase the sent emails counter if the email was > sent" do > @smtp = mock(Net::SMTP) > > @smtp > .should_receive(:send_message).exactly(4).times.and_return(true, > IOError, true, true) > Net::SMTP.stub!(:start).and_yield(@smtp) > @sender = Mailer::Sender.new(valid_args(:emails => @emails)) > @sender.sent_emails.should == 3 > end Mikel, It looks like you are doing too much here. You are specifying sending with the SMTP object in the same block you are specifying the algorithm for counting the sent emails. Also, the way it interrogates the email object to extract data looks fragile. I would prefer to make the Email object responsible for sending itself, although I will await the approval of an expert before I tell you my solution is better! I had a go at this, and my solution is MUCH longer, but it breaks the behaviour down to a finer level. (As you didn't show the code for Mailer::Sender, I wrote a quick implementation myself, possibly similar to yours.) Also, I'm never quite sure how best to use "before" blocks, so don't take mine as a canonical example. Anyway here is what I came up with: class Email def initialize(encoded_message, from, destination) @encoded_message, @from, @destination = encoded_message, from, destination end def send_via(smtp) begin smtp.send_message(@encoded_message, @from, @destination) rescue IOError => e 0 else 1 end end end describe Email, :shared => true do before(:each) do @smtp = mock("Net::SMTP") @email = Email.new("message", "from at mydomain", "to at destination") end it "send_via: should send :send_message to the SMTP object with the email details" do @smtp.should_receive(:send_message). with("message", "from at mydomain", "to at destination") @email.send_via(@smtp) end end describe Email, "sent via a working SMTP" do it_should_behave_like "Email" before(:each) do @smtp.stub!(:send_message) end it "send_via: should return 1 if the email sent successfully" do @email.send_via(@smtp).should == 1 end end describe Email, "sent via a faulty SMTP" do it_should_behave_like "Email" before(:each) do @smtp.stub!(:send_message).and_raise(IOError.new) end it "send_via: should return 1 if the email sent successfully" do @email.send_via(@smtp).should == 0 end end class Spammer def initialize(smtp) @smtp = smtp end def send(emails) emails.inject(0) { |success_count, email| success_count + email.send_via(@smtp) } end end describe Spammer, "created with an SMTP" do before(:each) do @email_successful_1 = mock(Email) @email_successful_1.stub!(:send_via).and_return(1) @email_successful_2 = mock(Email) @email_successful_2.stub!(:send_via).and_return(1) @email_unsuccessful_1 = mock(Email) @email_unsuccessful_1.stub!(:send_via).and_return(0) @emails = [ @email_successful_1, @email_successful_2, @email_unsuccessful_1] @spammer = Spammer.new(:smtp) end it "send: should send each email in turn with the SMTP and return the successful count" do @email_successful_1.should_receive(:send_via).with(:smtp).and_return(1) @email_successful_2.should_receive(:send_via).with(:smtp).and_return(1) @email_unsuccessful_1 .should_receive(:send_via).with(:smtp).and_return(2) @spammer.send(@emails) end it "send: should return the count of successful emails" do @spammer.send(@emails).should == 2 end end Let me know if this is helpful Regards Ashley -- blog @ http://aviewfromafar.net/ linked-in @ http://www.linkedin.com/in/ashleymoran currently @ home From nola at rubygeek.com Sun Nov 4 10:53:34 2007 From: nola at rubygeek.com (Nola Stowe) Date: Sun, 4 Nov 2007 10:53:34 -0500 Subject: [rspec-users] RSpec, RESTful nested routes and :path_prefix In-Reply-To: References: Message-ID: <43e95380711040753x32f3cebev85c46118e5eff3c9@mail.gmail.com> Hmm.. I do do have a controller with path_prefix that works. I wrote about a problem I am having in this thread, http://rubyforge.org/pipermail/rspec-users/2007-October/004202.html They do work, but for some reason I can get one of the named routes to work. If you want, email me the full page_controller_spec .. and paste On 11/4/07, Harm Aarts wrote: > I do not believe that is the case here. I used 'script/genereate > rspec_controller wiki::pages' and that generated spec files in 'spec/ > controllers/wiki/pages_controller_spec.rb'. So that seemed to be in > order. Excerpt: > > require File.dirname(__FILE__) + '/../../spec_helper' > > describe Wiki::PagesController do > fixtures :projects > > #Delete these examples and add some real ones > it "should use Wiki::PagesController" do > controller.should be_an_instance_of(Wiki::PagesController) > end > > it "GET 'index' should be successful" do > get 'index', :project_id => 1 > response.should be_success > end > end > > Seems OK right? Does RSpec not support nested routes with :path_prefix? > > Harm > > > ------------------------------ > > > > Message: 11 > > Date: Fri, 2 Nov 2007 19:56:22 -0400 > > From: "Nola Stowe" > > Subject: Re: [rspec-users] RSpec, RESTful nested routes and > > :path_prefix > > To: rspec-users > > Message-ID: > > <43e95380711021656y4369ecb2wf3053d30b5556c51 at mail.gmail.com> > > Content-Type: text/plain; charset=ISO-8859-1 > > > > I had a problem when I used: > > > > script/generate rspec_scaffold "admin/users" > > > > it created the specs with the controller name is "admin_user" instead > > of "admin/user" which I think should be correct. So I had to go > > through all the rspec generated files and change the _ to / > > > > did you use rspec_scaffolding? > > > > I don't know if this is the same issue, I would have to see more of > > your spec file. > > > > > > > > On 11/2/07, Harm Aarts wrote: > >> Dear list, > >> > >> In the app we are making we have a rout something like this: > >> map.resources :projects do |projects| > >> projects.resources :pages, :controller > >> =>"Wiki::Pages", :path_prefix => "/projects/:project_id/ > >> wiki", :name_prefix => "project_wiki_" > >> end > >> > >> But I can't get RSpec(I'm very new to it) to accept this. It keeps > >> throwing errors: > >> ActionController::RoutingError in 'Wiki::PagesController POST > >> 'create' should be successful' > >> No route matches {:action=>"create", :controller=>"wiki/ > >> pages", :project_id=>1, :page => {}} > >> > >> I get why it throws these errors but not how to fix it. The relavant > >> RSpec: > >> it "GET 'create' should be successful" do > >> post 'create', :project_id => 1, :page => {} > >> response.should be_success > >> end > >> > >> How do I modify the get request properly? > >> Thanks in advance! > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > > > > -- > > http://rubygeek.com - my blog featuring: Ruby, PHP and Perl > > http://DevChix.com - boys can't have all the fun > > > > > > ------------------------------ > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > End of rspec-users Digest, Vol 17, Issue 3 > > ****************************************** > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://rubygeek.com - my blog featuring: Ruby, PHP and Perl http://DevChix.com - boys can't have all the fun From lists at ruby-forum.com Sun Nov 4 17:51:22 2007 From: lists at ruby-forum.com (Hugh Watkins) Date: Sun, 4 Nov 2007 23:51:22 +0100 Subject: [rspec-users] RSpec Texmate Bundle errors In-Reply-To: <8A058D5F-7407-4FB5-9DB0-966727F52AFD@railsnewbie.com> References: <43B902A0-D43C-4330-AFA6-7191EFCC7C42@bolloretelecom.eu> <57c63afe0710300936m1eb514cbj20d64a55bf87cc6f@mail.gmail.com> <8A058D5F-7407-4FB5-9DB0-966727F52AFD@railsnewbie.com> Message-ID: <8220d51602c2e4074d5ab58e5a72aa96@ruby-forum.com> This worked for me #From my rails project rm -rf vendor/plugins/rspec rm -rf vendor/plugins/rspec_on_rails ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails ruby script/generate rspec #I installed the bundle in the global directory cd /Library/Application\ Support /TextMate/Bundles sudo svn co svn://rubyforge.org/var/svn/rspec/trunk/RSpec.tmbundle #I had ended up with 2 ruby directories after the leopard install (so 2 gem directories) /usr/bin/ruby -v ruby 1.8.6 (2007-06-07 patchlevel 36) [universal-darwin9.0] /usr/bin/gem -v 0.9.4 /opt/local/bin/ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.10.3] /opt/local/bin/gem -v 0.9.4 #I just went ahead nd installed the latest rspec gem in both, at so point I need to delete the /opt/local installation bt not right now cd ~ svn checkout svn://rubyforge.org/var/svn/rspec/trunk rspec_trunk cd rspec_trunk/rspec rake gem sudo /usr/bin/gem install pkg/rspec*.gem sudo /opt/local/bin/gem install pkg/rspec*.gem -- Posted via http://www.ruby-forum.com/. From raasdnil at gmail.com Sun Nov 4 18:51:54 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Mon, 5 Nov 2007 10:51:54 +1100 Subject: [rspec-users] Specing raising error, handling, and then not raising error In-Reply-To: References: <57a815bf0711040155o1cbfd10dj907db6a7623eefa4@mail.gmail.com> Message-ID: <57a815bf0711041551j1d0dc158jdceb4ff4b426b405@mail.gmail.com> On 11/5/07, Ashley Moran wrote: > Mikel, > > It looks like you are doing too much here. You are specifying sending > with the SMTP object in the same block you are specifying the > algorithm for counting the sent emails. Also, the way it interrogates > the email object to extract data looks fragile. I would prefer to > make the Email object responsible for sending itself, although I will > await the approval of an expert before I tell you my solution is better! HOLYCOMPLETESOLUTIONBATMAN! :) Definately helpful... especially the bit on "trying to do too much". The problem I was trying to solve with the mass sender is I only want to open one connection to the SMTP server, not multiple. But your code definatley gave me some good ideas. All this to get some email from one computer on the internet to another that is not :) Anyway, speak soon, thanks again! Mikel From rsl at swimcommunity.org Mon Nov 5 08:33:05 2007 From: rsl at swimcommunity.org (Russell Norris) Date: Mon, 5 Nov 2007 08:33:05 -0500 Subject: [rspec-users] Writing controller specs In-Reply-To: <1193402662.12714.1.camel@ip6-localhost> References: <1193402662.12714.1.camel@ip6-localhost> Message-ID: <1d2f8d6f0711050533lecd5277rfec5559999ab67e7@mail.gmail.com> Howdy. I've been handling this by simply stubbing out the methods as needed in the before(:each) block and then stating should_receive(:foo) when i'm actually writing spec for their behavior. RSL On 11/1/07, Hans de Graaff wrote: > One thing that is bothering me about my controller specs is that > sometimes I end up with a number of examples that are the same except > for the example name. > > The reason that this happens is that I've expressed all the expected > behavior with should_receive. While this does more or less work as > intended it doesn't feel right. > > As an example, let's say I'm writing code to post a comment and record > the IP address. First, let's handle the comment posting: > > > describe 'post comment' do > > before do > @data = {'text' => 'A comment that is posted'} > @comment = mock_model(Comment) > end > > it 'should be successful when proper input has been given' do > Comment.should_receive(:new).with(@data).once.and_return(@comment) > @comment.should_receive(:save).and_return(true) > > post :create, {:comment => @data} > response.should be_success > end > end > > > So far so good, although checking the response doesn't feel exactly > right. > Then again, the two expectations already cover the example, so checking > the > response could just as well be left out. > > Now, on to adding the recording of the IP address: > > it 'should record the IP address of the poster' do > @comment.should_receive(:ip_address=).with('0.0.0.0') > > post :create, {:comment => @data} > end > > Obviously this won't work because the @comment object has not been set > up correctly. So, we should also add in that code: > > it 'should record the IP address of the poster' do > Comment.should_receive(:new).with(@data).once.and_return(@comment) > @comment.should_receive(:save).and_return(true) > @comment.should_receive(:ip_address=).with('0.0.0.0') > > post :create, {:comment => @data} > end > > But now the initial example won't work anymore because the mock model > doesn't deal with the ip_address= method. Let's fix that as well: > > it 'should be successful when proper input has been given' do > Comment.should_receive(:new).with(@data).once.and_return(@comment) > @comment.should_receive(:save).and_return(true) > @comment.should_receive(:ip_address=).with('0.0.0.0') > > post :create, {:comment => @data} > response.should be_success > end > > So now both methods look the same (minus the gratuitous response > check) and it feels like something went wrong somewhere. It even > becomes tempting to move the should_receive lines into the before-do > block, but then the examples become essentially empty. > > Any comments on insight into this would be appreciated. > > Kind regards, > > Hans > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > From pergesu at gmail.com Mon Nov 5 10:14:36 2007 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 5 Nov 2007 10:14:36 -0500 Subject: [rspec-users] Writing controller specs In-Reply-To: <1193402662.12714.1.camel@ip6-localhost> References: <1193402662.12714.1.camel@ip6-localhost> Message-ID: <810a540e0711050714k2ccdedfdl5034fed76e255470@mail.gmail.com> Take a look at before(:each) - http://rspec.rubyforge.org/documentation/index.html Pat From work at ashleymoran.me.uk Mon Nov 5 10:53:22 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Mon, 5 Nov 2007 15:53:22 +0000 Subject: [rspec-users] Specing raising error, handling, and then not raising error In-Reply-To: <57a815bf0711041551j1d0dc158jdceb4ff4b426b405@mail.gmail.com> References: <57a815bf0711040155o1cbfd10dj907db6a7623eefa4@mail.gmail.com> <57a815bf0711041551j1d0dc158jdceb4ff4b426b405@mail.gmail.com> Message-ID: On 4 Nov 2007, at 23:51, Mikel Lindsaar wrote: > The problem I was trying to solve with the mass sender is I only want > to open one connection to the SMTP server, not multiple. I thought I covered that. I didn't mock out the bit that wrapped your existing code: Net::SMTP(@host, @port, @from_domain) do |smtp| # ... previous implementation end So at some point you still need that one connection that gets passed through the rest of the code. Class Spammer holds onto the SMTP but it's a transient object really - I pictured it being made in the Net::SMTP block and discarded, eg: Net::SMTP(@host, @port, @from_domain) do |smtp| Spammer.new(smtp).send(@emails) end Does this help? Ashley -- blog @ http://aviewfromafar.net/ linked-in @ http://www.linkedin.com/in/ashleymoran currently @ work From jimlindley at gmail.com Mon Nov 5 21:00:51 2007 From: jimlindley at gmail.com (Jim Lindley) Date: Mon, 5 Nov 2007 21:00:51 -0500 Subject: [rspec-users] Specifying mixins In-Reply-To: References: <9B6A2746-39BB-4716-9D0B-E56DEE6A1E99@experthuman.com> <8d961d900711011630i7fc4e2aerfbaf157308e666be@mail.gmail.com> Message-ID: <1b165db00711051800g5141228drfedcdac793d93aa3@mail.gmail.com> > > just a short advice: > > > > describe MyModule do > > it "should do something" do > > # The module is automatically mixed into your spec > > end > > end > > > > Aslak > > I suppose it really depends on how static/dynamic the module is. Add an additional describe block for the class that you're including the module into, and then setup a genericly named object in the before block and then include the shared behaviours from the module's spec module. Like this: # page_spec.rb describe Page, "should include publishing features" do include PublishableSpec before(:each) do @model = Page.new(:title => "title", :content => "content", :published => false) end it_should_behave_like "Publishable" # include the shared tests end # post_spec.rb describe Post, "should include publishing features" do include PublishableSpec before(:each) do @model = Post.new(:title => "title", :content => "content", :published => false) end it_should_behave_like "Publishable" # include the shared spec end # publishable_spec.rb module PublishableSpec describe "Publishable", :shared => true do it "should have a published marker" do @model.save! @model.should_not be_published end it "should be publishable" do @model.save.publish! @model.should be_published end end end I can post more if that's unclear (showing the actual AR classes and mixin), but it seems to work well and eliminates duplication. I hope the formatting on this comes through... Jim Lindley http://jimlindley.com From lists at ruby-forum.com Tue Nov 6 03:51:47 2007 From: lists at ruby-forum.com (Karni Karni) Date: Tue, 6 Nov 2007 09:51:47 +0100 Subject: [rspec-users] Test case for file import Message-ID: Hi Friends, I need to write the testcase for fileimport. Pls give me any idea -- Posted via http://www.ruby-forum.com/. From jimlindley at gmail.com Tue Nov 6 07:51:55 2007 From: jimlindley at gmail.com (Jim Lindley) Date: Tue, 6 Nov 2007 07:51:55 -0500 Subject: [rspec-users] Test case for file import In-Reply-To: References: Message-ID: <1b165db00711060451s6d7fdc44he2fffb12c1f74bd7@mail.gmail.com> > > I need to write the testcase for fileimport. > Can you show some of your code that needs to be tested? From dchelimsky at gmail.com Tue Nov 6 08:02:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 Nov 2007 07:02:33 -0600 Subject: [rspec-users] Test case for file import In-Reply-To: <1b165db00711060451s6d7fdc44he2fffb12c1f74bd7@mail.gmail.com> References: <1b165db00711060451s6d7fdc44he2fffb12c1f74bd7@mail.gmail.com> Message-ID: <57c63afe0711060502m6c92ccdaye78ce6846175fe3f@mail.gmail.com> On Nov 6, 2007 6:51 AM, Jim Lindley wrote: > > > > I need to write the testcase for fileimport. > > > > Can you show some of your code that needs to be tested? Actually, we'd hope that the code doesn't exist yet. This is Behaviour DRIVEN Development, after all. Can you tell us what fileimport is supposed to do? From jimlindley at gmail.com Tue Nov 6 08:54:14 2007 From: jimlindley at gmail.com (Jim Lindley) Date: Tue, 6 Nov 2007 08:54:14 -0500 Subject: [rspec-users] Test case for file import In-Reply-To: <57c63afe0711060502m6c92ccdaye78ce6846175fe3f@mail.gmail.com> References: <1b165db00711060451s6d7fdc44he2fffb12c1f74bd7@mail.gmail.com> <57c63afe0711060502m6c92ccdaye78ce6846175fe3f@mail.gmail.com> Message-ID: <1b165db00711060554m6afc3418q34703319b5e5e8c4@mail.gmail.com> > > Can you show some of your code that needs to be tested? > > Actually, we'd hope that the code doesn't exist yet. This is Behaviour > DRIVEN Development, after all. >  Old habits, my apologies. From tom at experthuman.com Tue Nov 6 09:11:00 2007 From: tom at experthuman.com (Tom Stuart) Date: Tue, 6 Nov 2007 14:11:00 +0000 Subject: [rspec-users] Specifying mixins In-Reply-To: <1b165db00711051800g5141228drfedcdac793d93aa3@mail.gmail.com> References: <9B6A2746-39BB-4716-9D0B-E56DEE6A1E99@experthuman.com> <8d961d900711011630i7fc4e2aerfbaf157308e666be@mail.gmail.com> <1b165db00711051800g5141228drfedcdac793d93aa3@mail.gmail.com> Message-ID: On 6 Nov 2007, at 02:00, Jim Lindley wrote: > Add an additional describe block for the class that you're including > the module into, and then setup a genericly named object in the before > block [...] > > # page_spec.rb > describe Page, "should include publishing features" do > include PublishableSpec > > before(:each) do > @model = Page.new(:title => "title", :content => "content", > :published => false) > end Yeah, this is fine for a simple mixin with only one shared behaviour, but the problem is that a real chunk of mixed-in functionality will probably need many behaviours that correspond to different initial states (provided you're behaving yourself and not doing too much state setup within the individual examples). So, firstly, perhaps I'll have ten shared behaviours to specify my mixin -- do I have ten calls to it_should_behave_like in the spec for each target class? And secondly, perhaps each of those shared behaviours is talking about an object with different initial state, e.g. constructed with different arguments (a published thing, an unpublished thing, a published but deleted thing) -- how do I arrange for that to happen? Ten corresponding behaviours each containing the appropriate before(:each) and a call to it_should_behave_like? Or arrange for the shared behaviours to somehow do the initialisation themselves, e.g. by doing some kind of parameterized helper gymnastics where you pass in the child class object and the shared behaviour calls #new on it? None of this is impossible to do, it's just that it all feels very repetitious and difficult in contrast to the elegant solutions that people often post here. I'm hoping that this sort of "okay, you understand the basics, but NOW what?" issue is the kind of thing that the hotly-anticipated RSpec book will address, because any information about best practice in this area is really lacking, but I fear it might not be that kind of book! Cheers, -Tom From dchelimsky at gmail.com Tue Nov 6 09:39:19 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 Nov 2007 08:39:19 -0600 Subject: [rspec-users] Specifying mixins In-Reply-To: References: <9B6A2746-39BB-4716-9D0B-E56DEE6A1E99@experthuman.com> <8d961d900711011630i7fc4e2aerfbaf157308e666be@mail.gmail.com> <1b165db00711051800g5141228drfedcdac793d93aa3@mail.gmail.com> Message-ID: <57c63afe0711060639g3d642b59j96be1986cc286b4d@mail.gmail.com> On Nov 6, 2007 8:11 AM, Tom Stuart wrote: > On 6 Nov 2007, at 02:00, Jim Lindley wrote: > > Add an additional describe block for the class that you're including > > the module into, and then setup a genericly named object in the before > > block > [...] > > > > # page_spec.rb > > describe Page, "should include publishing features" do > > include PublishableSpec > > > > before(:each) do > > @model = Page.new(:title => "title", :content => "content", > > :published => false) > > end > > Yeah, this is fine for a simple mixin with only one shared behaviour, > but the problem is that a real chunk of mixed-in functionality will > probably need many behaviours that correspond to different initial > states (provided you're behaving yourself and not doing too much state > setup within the individual examples). > > So, firstly, perhaps I'll have ten shared behaviours to specify my > mixin -- do I have ten calls to it_should_behave_like in the spec for > each target class? > > And secondly, perhaps each of those shared behaviours is talking about > an object with different initial state, e.g. constructed with > different arguments (a published thing, an unpublished thing, a > published but deleted thing) -- how do I arrange for that to happen? > Ten corresponding behaviours each containing the appropriate > before(:each) and a call to it_should_behave_like? Or arrange for the > shared behaviours to somehow do the initialisation themselves, e.g. by > doing some kind of parameterized helper gymnastics where you pass in > the child class object and the shared behaviour calls #new on it? > > None of this is impossible to do, it's just that it all feels very > repetitious and difficult in contrast to the elegant solutions that > people often post here. There really isn't a great solution for this problem right now, but there are a few initiatives that will be helpful in getting us there. Nested specs, classes/methods (as an alternative to describe/it), turning examples into methods (so they can get overridden), etc, etc. > I'm hoping that this sort of "okay, you > understand the basics, but NOW what?" issue is the kind of thing that > the hotly-anticipated RSpec book will address, because any information > about best practice in this area is really lacking, but I fear it > might not be that kind of book! Well - there will be some of that, and we'll certainly consider including something about this issue. It's fairly common. Cheers, David > > Cheers, > -Tom > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jimlindley at gmail.com Tue Nov 6 09:40:19 2007 From: jimlindley at gmail.com (Jim Lindley) Date: Tue, 6 Nov 2007 09:40:19 -0500 Subject: [rspec-users] Specifying mixins In-Reply-To: References: <9B6A2746-39BB-4716-9D0B-E56DEE6A1E99@experthuman.com> <8d961d900711011630i7fc4e2aerfbaf157308e666be@mail.gmail.com> <1b165db00711051800g5141228drfedcdac793d93aa3@mail.gmail.com> Message-ID: <1b165db00711060640h51330b63kad626119ef02f71a@mail.gmail.com> > Yeah, this is fine for a simple mixin with only one shared behaviour, > but the problem is that a real chunk of mixed-in functionality will > probably need many behaviours that correspond to different initial > states (provided you're behaving yourself and not doing too much state > setup within the individual examples). > Tom, there is likely a better path then the one I'm going down, and I would love to hear it. I am no RSpec expert. How big are the modules you're including? For the modules I do this with it doesn't seem to get out of hand. The example I gave above was a simplifed version of a module spec, not the whole thing. The real one has many more behaviour blocks, and in the before block a couple hashes for use inside the module spec for creating other scenarios. I'm not doing much setup inside the module spec. If the module has a couple aspects to its behaviour I usually end up with just 2 or 3 describe blocks each with about 20 it blocks, and testing its inclusion into AR classes just needs a before block setting up a half dozen objects. If it's getting too complicated to spec out maybe the module is doing too much and should be split up? Jim From tom at experthuman.com Tue Nov 6 10:21:05 2007 From: tom at experthuman.com (Tom Stuart) Date: Tue, 6 Nov 2007 15:21:05 +0000 Subject: [rspec-users] Specifying mixins In-Reply-To: <57c63afe0711060639g3d642b59j96be1986cc286b4d@mail.gmail.com> References: <9B6A2746-39BB-4716-9D0B-E56DEE6A1E99@experthuman.com> <8d961d900711011630i7fc4e2aerfbaf157308e666be@mail.gmail.com> <1b165db00711051800g5141228drfedcdac793d93aa3@mail.gmail.com> <57c63afe0711060639g3d642b59j96be1986cc286b4d@mail.gmail.com> Message-ID: On 6 Nov 2007, at 14:39, David Chelimsky wrote: >> I'm hoping that this sort of "okay, you >> understand the basics, but NOW what?" issue is the kind of thing that >> the hotly-anticipated RSpec book will address, because any >> information >> about best practice in this area is really lacking > Well - there will be some of that, and we'll certainly consider > including something about this issue. It's fairly common. Great! My personal experience has been that the nuts and bolts of RSpec are pretty easy to pick up from the really rather good online documentation -- it's the details of how to actually apply this stuff to real projects that gets people confused about what "the right way" is. (Witness the many discussions about how to spec ActiveRecord validations, etc.) Obviously a lot of this stuff is a matter of opinion and design preference rather than cold mathematical fact, but someone putting a stake in the ground and proclaiming a few best practices (at the right level of abstraction, i.e. general enough to be applicable but concrete enough to be useful) would be incredibly welcome. Can't wait! Cheers, -Tom From tom at experthuman.com Tue Nov 6 10:30:46 2007 From: tom at experthuman.com (Tom Stuart) Date: Tue, 6 Nov 2007 15:30:46 +0000 Subject: [rspec-users] Specifying mixins In-Reply-To: <1b165db00711060640h51330b63kad626119ef02f71a@mail.gmail.com> References: <9B6A2746-39BB-4716-9D0B-E56DEE6A1E99@experthuman.com> <8d961d900711011630i7fc4e2aerfbaf157308e666be@mail.gmail.com> <1b165db00711051800g5141228drfedcdac793d93aa3@mail.gmail.com> <1b165db00711060640h51330b63kad626119ef02f71a@mail.gmail.com> Message-ID: <728976E2-6744-4A52-AE96-3B6E8E0AF2CE@experthuman.com> On 6 Nov 2007, at 14:40, Jim Lindley wrote: > Tom, there is likely a better path then the one I'm going down, and I > would love to hear it. I am no RSpec expert. Neither am I! From David's response it sounds as though there isn't a particularly tidy way to solve this problem at the moment, so I guess we just need to muddle along in whatever way works. > How big are the modules you're including? > For the modules I do this with it doesn't seem to get out of hand. > If it's getting too complicated to spec out maybe the module is doing > too much and should be split up? Possibly, but the proliferation of behaviours is mostly due to following Dave Astels' "one expectation per example" guideline (http://daveastels.com/2006/08/26/one-expectation-per-example-a-remake-of-one-assertion-per-test/ ), which actually works out really well for regular specs, making them easier to write and understand. It's just the impedance mismatch between this particular practice (i.e. split up big behaviours into lots of smaller ones) and RSpec's limited support for sharing behaviours (i.e. you can't group them together or supply parameters when referencing them) that causes the hassle, rather than (necessarily) a large or complicated mixin module. Cheers, -Tom From lists at ruby-forum.com Tue Nov 6 13:56:58 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Tue, 6 Nov 2007 19:56:58 +0100 Subject: [rspec-users] Why is this view spec failing? Message-ID: <4d6e9be9e8b5d88afc6f23de1a46e489@ruby-forum.com> I can't figure out why I am getting a failure. It renders out fine in the browser.

New member

<%= error_messages_for :member %> <% form_for(:member, :url => members_path) do |f| %>
Member Info

<%= f.text_field :first_name %>

<%= f.text_field :last_name %>

<%= submit_tag "Create" %>

<% end %> <%= link_to 'Back', members_path %> ************* ActionView::TemplateError in '/members/new.rhtml should render new form' Mock 'Member_1002' received unexpected message :first_name with (no args) On line #9 of app/views/members/new.rhtml 6: 7:
8: Member Info 9:

<%= f.text_field :first_name %>

10:

<%= f.text_field :last_name %>

11:
12: #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/error_generator.rb:52:in `__raise' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/error_generator.rb:16:in `raise_unexpected_message_error' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/proxy.rb:83:in `raise_unexpected_message_error' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/mock.rb:20:in `method_missing' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:356:in `send' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:356:in `value_before_type_cast' *************** This is using the auto-created test it "should render new form" do render "/members/new.rhtml" response.should have_tag("form[action=?][method=post]", members_path) do end end Thanks for the help -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Nov 6 14:24:16 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 Nov 2007 13:24:16 -0600 Subject: [rspec-users] Why is this view spec failing? In-Reply-To: <4d6e9be9e8b5d88afc6f23de1a46e489@ruby-forum.com> References: <4d6e9be9e8b5d88afc6f23de1a46e489@ruby-forum.com> Message-ID: <57c63afe0711061124y3b5000b8y82207d943a0a8a86@mail.gmail.com> On Nov 6, 2007 12:56 PM, Chris Olsen wrote: > I can't figure out why I am getting a failure. It renders out fine in > the browser. > >

New member

> > <%= error_messages_for :member %> > > <% form_for(:member, :url => members_path) do |f| %> > >
> Member Info >

<%= > f.text_field :first_name %>

>

<%= > f.text_field :last_name %>

>
> >

> <%= submit_tag "Create" %> >

> <% end %> > <%= link_to 'Back', members_path %> > > ************* > ActionView::TemplateError in '/members/new.rhtml should render new form' > Mock 'Member_1002' received unexpected message :first_name with (no > args) This error is telling you exactly why it's failing. The mock name "Member_1002" that I'm assuming gets created in the spec (please post before(:each) in the future for clarity) is being sent :first_name by the code invoked by t.text_field. Assuming (again) that it is called @member: @member.stub!(:first_name).and_return("Chris") should solve the problem. Cheers, David > On line #9 of app/views/members/new.rhtml > > 6: > 7:
> 8: Member Info > 9:

<%= > f.text_field :first_name %>

> 10:

<%= > f.text_field :last_name %>

> 11:
> 12: > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/error_generator.rb:52:in > `__raise' > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/error_generator.rb:16:in > `raise_unexpected_message_error' > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/proxy.rb:83:in > `raise_unexpected_message_error' > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/mocks/mock.rb:20:in > `method_missing' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:356:in > `send' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:356:in > `value_before_type_cast' > > *************** > This is using the auto-created test > > it "should render new form" do > render "/members/new.rhtml" > > response.should have_tag("form[action=?][method=post]", > members_path) do > end > end > > Thanks for the help > -- > 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 Nov 6 14:56:33 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Tue, 6 Nov 2007 20:56:33 +0100 Subject: [rspec-users] Why is this view spec failing? In-Reply-To: <57c63afe0711061124y3b5000b8y82207d943a0a8a86@mail.gmail.com> References: <4d6e9be9e8b5d88afc6f23de1a46e489@ruby-forum.com> <57c63afe0711061124y3b5000b8y82207d943a0a8a86@mail.gmail.com> Message-ID: <615be70b54cc9c37e6b5581fbbbd80ab@ruby-forum.com> Thanks for the help David. -- Posted via http://www.ruby-forum.com/. From sross at calicowebdev.com Tue Nov 6 17:18:23 2007 From: sross at calicowebdev.com (Steve Ross) Date: Tue, 6 Nov 2007 14:18:23 -0800 Subject: [rspec-users] Keeping Up with Trunk Message-ID: I have a project with rspec installed as a plugin using svn:externals. Here are my externals: rspec_on_rails svn://rubyforge.org/var/svn/rspec/trunk/ rspec_on_rails rspec svn://rubyforge.org/var/svn/rspec/trunk/ rspec I just did an svn up on both and now have a version mismatch: ######################################################################## #### Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 1.1.0 (r2804) RSpec on Rails : r2817 Make sure your RSpec on Rails plugin is compatible with your RSpec gem. See http://rspec.rubyforge.org/documentation/rails/install.html for details. ######################################################################## #### Any idea why this might be happening? From sross at calicowebdev.com Tue Nov 6 17:18:23 2007 From: sross at calicowebdev.com (Steve Ross) Date: Tue, 6 Nov 2007 14:18:23 -0800 Subject: [rspec-users] Keeping Up with Trunk Message-ID: I have a project with rspec installed as a plugin using svn:externals. Here are my externals: rspec_on_rails svn://rubyforge.org/var/svn/rspec/trunk/ rspec_on_rails rspec svn://rubyforge.org/var/svn/rspec/trunk/ rspec I just did an svn up on both and now have a version mismatch: ######################################################################## #### Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 1.1.0 (r2804) RSpec on Rails : r2817 Make sure your RSpec on Rails plugin is compatible with your RSpec gem. See http://rspec.rubyforge.org/documentation/rails/install.html for details. ######################################################################## #### Any idea why this might be happening? From dchelimsky at gmail.com Tue Nov 6 18:01:19 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 Nov 2007 17:01:19 -0600 Subject: [rspec-users] Keeping Up with Trunk In-Reply-To: References: Message-ID: <57c63afe0711061501i648dd58bv39679293c0865094@mail.gmail.com> On Nov 6, 2007 4:18 PM, Steve Ross wrote: > I have a project with rspec installed as a plugin using > svn:externals. Here are my externals: > > rspec_on_rails svn://rubyforge.org/var/svn/rspec/trunk/ > rspec_on_rails > rspec svn://rubyforge.org/var/svn/rspec/trunk/ > rspec > > I just did an svn up on both and now have a version mismatch: > > ######################################################################## > #### > Your RSpec on Rails plugin is incompatible with your installed RSpec. > > RSpec : 1.1.0 (r2804) > RSpec on Rails : r2817 > > Make sure your RSpec on Rails plugin is compatible with your RSpec gem. > See http://rspec.rubyforge.org/documentation/rails/install.html for > details. > ######################################################################## > #### > > Any idea why this might be happening? I get 2817 for both. Not sure why you're experiencing this. From cwdinfo at gmail.com Tue Nov 6 18:06:29 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 6 Nov 2007 15:06:29 -0800 Subject: [rspec-users] Keeping Up with Trunk In-Reply-To: <57c63afe0711061501i648dd58bv39679293c0865094@mail.gmail.com> References: <57c63afe0711061501i648dd58bv39679293c0865094@mail.gmail.com> Message-ID: <6248655C-284B-45AA-ADFB-42A001E890BB@gmail.com> I've been having good luck with this up to now, but then got a mismatch today. It seems the svn servers on Rubyforge have been a bit spotty -- or at least that's how it seems. They have been closing connections and maybe that's how I got out of sync. Thx On Nov 6, 2007, at 3:01 PM, David Chelimsky wrote: > On Nov 6, 2007 4:18 PM, Steve Ross wrote: >> I have a project with rspec installed as a plugin using >> svn:externals. Here are my externals: >> >> rspec_on_rails svn://rubyforge.org/var/svn/rspec/ >> trunk/ >> rspec_on_rails >> rspec svn://rubyforge.org/var/svn/rspec/ >> trunk/ >> rspec >> >> I just did an svn up on both and now have a version mismatch: >> >> ##################################################################### >> ### >> #### >> Your RSpec on Rails plugin is incompatible with your installed RSpec. >> >> RSpec : 1.1.0 (r2804) >> RSpec on Rails : r2817 >> >> Make sure your RSpec on Rails plugin is compatible with your RSpec >> gem. >> See http://rspec.rubyforge.org/documentation/rails/install.html for >> details. >> ##################################################################### >> ### >> #### >> >> Any idea why this might be happening? > > I get 2817 for both. Not sure why you're experiencing this. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Wed Nov 7 00:39:00 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Wed, 7 Nov 2007 06:39:00 +0100 Subject: [rspec-users] Unexplainable failure...at least for me Message-ID: <923c372bc0abecd7fd5365deaa687634@ruby-forum.com> I have an address model with country_id and province_id fields There is also a full_address method that returns an address that is in a format that the google maps api will be able to return a long-lat coords. Within the full_address method there is a call to obtain the province/state and country name. --------- def full_address ... full_address = [city, self.province.name, self.country.name].join(",").chomp(",") .. end When I run this in the console it works fine >> a = Address.new => #nil, "latitude"=>nil, "region_code"=>nil, "province_id"=>nil, "country_id"=>nil, "location_type"=>nil, "location_id"=>nil, "address_1"=>nil, "address_2"=>nil, "longitude"=>nil, "address_3"=>nil, "address_4"=>nil}> >> a.country_id = 1 => 1 >> a.country.name => "Canada" >> a.province_id = 1 => 1 >> a.full_address => ",,Alberta,Canada" but when the specs are run I get errors saying that the country and province object properties are null 11) NoMethodError in 'Address additional properties should ensure spacing between the st/ave on the address' You have a nil object when you didn't expect it! The error occurred while evaluating nil.name /Users/chris/Documents/Projects/Rails/MyProject/trunk/config/../app/models/address.rb:25:in `full_address' ./spec/models/address_spec.rb:66: script/spec:4: Here is one of the tests that fail: describe Address, "additional properties" do before(:each) do @address = Address.new(valid_params) end def valid_params { :country_id => 1, :province_id => 1, :region_code => "T5Z3J4", :address_1 => "13245-56 st", :address_2 => "NW", :city => "Edmonton" } end it "should return the full address format" do @address.country_id.should == 1 #this passes @address.province_id.should == 1 #this passes @address.province.name.should == "Alberta" #this fails @address.country.name.should == "Canada" #this fails @address.full_address.should == "13245-56 st NW,Edmonton,Alberta,Canada" #and this fails if you remove the ones above end class Address < ActiveRecord::Base belongs_to :province belongs_to :country class Country < ActiveRecord::Base has_one :address If I wasn't able to make it happen in the console, it would make more sense, but seeing as I can I am totally lost. Thanks for the help -- Posted via http://www.ruby-forum.com/. From hans at degraaff.org Wed Nov 7 01:49:17 2007 From: hans at degraaff.org (Hans de Graaff) Date: Wed, 07 Nov 2007 07:49:17 +0100 Subject: [rspec-users] Unexplainable failure...at least for me In-Reply-To: <923c372bc0abecd7fd5365deaa687634@ruby-forum.com> References: <923c372bc0abecd7fd5365deaa687634@ruby-forum.com> Message-ID: <1194418157.4461.5.camel@ip6-localhost> On Wed, 2007-11-07 at 06:39 +0100, Chris Olsen wrote: > but when the specs are run I get errors saying that the country and > province object properties are null > 11) > NoMethodError in 'Address additional properties should ensure spacing > between the st/ave on the address' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.name > /Users/chris/Documents/Projects/Rails/MyProject/trunk/config/../app/models/address.rb:25:in > `full_address' > ./spec/models/address_spec.rb:66: > script/spec:4: > > Here is one of the tests that fail: > describe Address, "additional properties" do > > before(:each) do > @address = Address.new(valid_params) > end > > def valid_params > { > :country_id => 1, > :province_id => 1, > :region_code => "T5Z3J4", > :address_1 => "13245-56 st", > :address_2 => "NW", > :city => "Edmonton" > } > end The question is where this country and province with id 1 are defined. I don't see anything in your spec to indicate that they are ever created. If you are using fixtures then you'll need to explicitly include them. Otherwise they may or may not still be loaded in the test database and at best you'll get a clear failure and at worst inconsistent results. describe Address do fixtures :provinces, countries before ... etc Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20071107/3f85bb78/attachment.bin From peter_marklund at fastmail.fm Wed Nov 7 04:33:58 2007 From: peter_marklund at fastmail.fm (Peter Marklund) Date: Wed, 7 Nov 2007 10:33:58 +0100 Subject: [rspec-users] Helper methods starting with should_ get picked up as examples? Message-ID: <952F1F72-0F69-4A30-AC10-724F66857C4C@fastmail.fm> Hi! I recently updated my rspec and rspec_on_rails plugins to the tip of the trunk and ran into an issue with helper methods with names starting with should_ in my describe blocks. Fictive example to show what I'm talking about: describe Order do it "Can be paid for" do ... should_have_paid(user) end def should_have_paid(user) end end I know in some places I should (ah, there is that word again...) be using custom matchers when I'm being lazy and instead just defining methods. Anyway, it seems RSpec picks up methods starting with should_ as examples. Here is some debug output that I generated for a method called should_have_emailed: #, @from="/Users/peter/src/gear/specialist/ vendor/plugins/rspec/lib/spec/dsl/example.rb:22:in `each'", @description="should_have_emailed", @options={}> Is this itentional behaviour by RSpec or some weird side effect? Cheers Peter ---------------------------- Peter Marklund Garvar Lundins Gr?nd 7 11220 Stockholm Sweden Mobile Phone: +46-(0)70-4164857 Home Phone: +46-(0)8-50091315 Skype: peter_marklund IM: AIM - petermarklund, MSN - peter_marklund at hotmail.com, Yahoo - peter_marklund2002 http://marklunds.com ---------------------------- From dchelimsky at gmail.com Wed Nov 7 09:35:46 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Nov 2007 08:35:46 -0600 Subject: [rspec-users] Helper methods starting with should_ get picked up as examples? In-Reply-To: <952F1F72-0F69-4A30-AC10-724F66857C4C@fastmail.fm> References: <952F1F72-0F69-4A30-AC10-724F66857C4C@fastmail.fm> Message-ID: <57c63afe0711070635m9af1bfegb71307154cc3d64f@mail.gmail.com> On Nov 7, 2007 3:33 AM, Peter Marklund wrote: > Hi! > I recently updated my rspec and rspec_on_rails plugins to the tip of > the trunk and ran into an issue with helper methods with names > starting with should_ in my describe blocks. Fictive example to show > what I'm talking about: > > describe Order do > it "Can be paid for" do > ... > should_have_paid(user) > end > > def should_have_paid(user) > > end > end > > I know in some places I should (ah, there is that word again...) be > using custom matchers when I'm being lazy and instead just defining > methods. Anyway, it seems RSpec picks up methods starting with > should_ as examples. Here is some debug output that I generated for a > method called should_have_emailed: > > # 0x003f0250@/Users/peter/src/gear/specialist/vendor/plugins/rspec/lib/ > spec/dsl/example.rb:27>, @from="/Users/peter/src/gear/specialist/ > vendor/plugins/rspec/lib/spec/dsl/example.rb:22:in `each'", > @description="should_have_emailed", @options={}> > > Is this itentional behaviour by RSpec or some weird side effect? That's actually by design. There are many projects that would like to move to rspec but don't because the transition cost is too high. There are also a number of people who have said the lack of a clear class/method structure keeps them away. Supporting methods that start with should_ is part of an effort to resolve these conflicts. As things stand in trunk today, you can more or less use your choices from the following class FooTest < Test::Unit::TestCase class FooExamples < Spec::ExampleGroup describe Foo do def test_should_bar def should_bar it "should bar" do assert_equal "baz", foo.bar foo.bar.should == "baz" Sorry about the trouble w/ existing helper methods, but we feel this is the best path forward. Cheers, David From lists at ruby-forum.com Wed Nov 7 09:49:12 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Wed, 7 Nov 2007 15:49:12 +0100 Subject: [rspec-users] Unexplainable failure...at least for me In-Reply-To: <1194418157.4461.5.camel@ip6-localhost> References: <923c372bc0abecd7fd5365deaa687634@ruby-forum.com> <1194418157.4461.5.camel@ip6-localhost> Message-ID: <993c0936bdf4e744ba105558327cd8de@ruby-forum.com> That is the problem, which is clear now that I tested it with the script/console in test mode rather than development. So now the question is, why does the data not exist in the test database. The country and province data inserts exist within the migration files, ex for countries: class CreateCountries < ActiveRecord::Migration def self.up create_table :countries do |t| t.column :country_id, :integer t.column :name2, :string, :limit => 2 t.column :name3, :string, :limit => 3 t.column :name, :string t.column :district_name, :string t.column :code_name, :string t.column :strength, :integer end country_data = [ [124, 'CA', 'CAN', 'Canada', 'Province', 'Postal Code', 100], [840, 'US', 'USA', 'United States', 'State', 'ZipCode', 50], #along with many other countries ].each do |c| insert_params = { :country_id => c[0], :name2 => c[1], :name3 => c[2], :name => c[3], :district_name => c[4], :code_name => c[5], :strength => c[6] } Country.create(insert_params) end end Thanks for the help. > The question is where this country and province with id 1 are defined. I > don't see anything in your spec to indicate that they are ever created. > If you are using fixtures then you'll need to explicitly include them. > Otherwise they may or may not still be loaded in the test database and > at best you'll get a clear failure and at worst inconsistent results. > > describe Address do > fixtures :provinces, countries > > before ... etc > > Kind regards, > > Hans -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Nov 7 09:54:23 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Wed, 7 Nov 2007 15:54:23 +0100 Subject: [rspec-users] Unexplainable failure...at least for me In-Reply-To: <993c0936bdf4e744ba105558327cd8de@ruby-forum.com> References: <923c372bc0abecd7fd5365deaa687634@ruby-forum.com> <1194418157.4461.5.camel@ip6-localhost> <993c0936bdf4e744ba105558327cd8de@ruby-forum.com> Message-ID: <5cc30e942a2f9b9c8aa5154043a7bc20@ruby-forum.com> Chris Olsen wrote: > That is the problem, which is clear now that I tested it with the > script/console in test mode rather than development. > > So now the question is, why does the data not exist in the test > database. The country and province data inserts exist within the > migration files, ex for countries: > > class CreateCountries < ActiveRecord::Migration > def self.up > create_table :countries do |t| > t.column :country_id, :integer > t.column :name2, :string, :limit => 2 > t.column :name3, :string, :limit => 3 > t.column :name, :string > t.column :district_name, :string > t.column :code_name, :string > t.column :strength, :integer > end > > country_data = [ > [124, 'CA', 'CAN', 'Canada', 'Province', 'Postal Code', 100], > [840, 'US', 'USA', 'United States', 'State', 'ZipCode', 50], > #along with many other countries > ].each do |c| > > insert_params = { > :country_id => c[0], > :name2 => c[1], > :name3 => c[2], > :name => c[3], > :district_name => c[4], > :code_name => c[5], > :strength => c[6] > } > > Country.create(insert_params) > end > end > > Thanks for the help. I should mention that the test database is cloned properly with the script: task :reset_databases do system "mysqladmin -u root drop MyDB_development" system "mysqladmin -u root drop MyDB_test" system "mysqladmin -u root create MyDB_development" system "mysqladmin -u root create MyDB_test" system "rake db:migrate" system "rake db:test:clone_structure" end script/console test >> Country.find(:all) => [] -- Posted via http://www.ruby-forum.com/. From tom at experthuman.com Wed Nov 7 09:54:36 2007 From: tom at experthuman.com (Tom Stuart) Date: Wed, 7 Nov 2007 14:54:36 +0000 Subject: [rspec-users] Unexplainable failure...at least for me In-Reply-To: <993c0936bdf4e744ba105558327cd8de@ruby-forum.com> References: <923c372bc0abecd7fd5365deaa687634@ruby-forum.com> <1194418157.4461.5.camel@ip6-localhost> <993c0936bdf4e744ba105558327cd8de@ruby-forum.com> Message-ID: <59386BD2-0B53-4B08-8348-DF536497B5C1@experthuman.com> On 7 Nov 2007, at 14:49, Chris Olsen wrote: > So now the question is, why does the data not exist in the test > database. The country and province data inserts exist within the > migration files, ex for countries: As someone who knows literally nothing about how this all works, I still feel confident enough to guess that RSpec doesn't actually run any migrations, but rather just clones the schema of the existing development database -- so you get something that looks the same but contains no data. As the previous poster mentioned, you need to put the data into fixtures and include them; see http://rspec.rubyforge.org/documentation/rails/writing/models.html for examples. Cheers, -Tom From lists at ruby-forum.com Wed Nov 7 10:00:04 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Wed, 7 Nov 2007 16:00:04 +0100 Subject: [rspec-users] Unexplainable failure...at least for me In-Reply-To: <59386BD2-0B53-4B08-8348-DF536497B5C1@experthuman.com> References: <923c372bc0abecd7fd5365deaa687634@ruby-forum.com> <1194418157.4461.5.camel@ip6-localhost> <993c0936bdf4e744ba105558327cd8de@ruby-forum.com> <59386BD2-0B53-4B08-8348-DF536497B5C1@experthuman.com> Message-ID: <945b9ee49d2df973702f9c1f5b6b88b2@ruby-forum.com> That would make sense. Thanks for the help. -- Posted via http://www.ruby-forum.com/. From harmaarts at gmail.com Wed Nov 7 11:25:02 2007 From: harmaarts at gmail.com (Harm Aarts) Date: Wed, 7 Nov 2007 17:25:02 +0100 Subject: [rspec-users] RSpec, RESTful nested routes and :path_prefix Message-ID: <8B60AB1F-449C-4AD8-BE95-4E6C4D60A477@gmail.com> I think I did not express myself clear enough. The problem is that in my spec I can not get the 'post' and 'get' methods to correctly contact(by lack of a better word) the corresponding actions. I believe this has to do with the fact that I use a :path_prefix. So I would like this: > it "GET 'index' should be successful" do > get 'index', :project_id => 1 > response.should be_success > end To become something like: > it "GET 'index' should be successful" do > get 'index', :project_id => , :path_prefix => '/wiki' > response.should be_success > end But that obviously does not work. More importantly I do not believe I should be repeating myself with these path_prefixes. I suspect that RSpec is ignoring the :path_prefix in my routes.rb file. With kind regards, Harm From ben at benmabey.com Wed Nov 7 12:31:45 2007 From: ben at benmabey.com (Ben Mabey) Date: Wed, 07 Nov 2007 10:31:45 -0700 Subject: [rspec-users] LoadError when upgraded to latest rspec trunk Message-ID: <4731F681.2010900@benmabey.com> I just moved my rspec and rspec_on_rails plugin from r2691 to r2822. After that I upgraded both of them I regenerated all things rspec with the rspec generator. I was running on rails r2691 but upgraded to the latest at r2822 when I was getting errors but that still didn't help things. I get the following when I try to run a spec with either rake spec or ./script/spec: /app/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in `load_missing_constant': Expected /app/trunk/vendor/plugins/rspec/lib/spec/test.rb to define Spec::Test (LoadError) from /app/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:453:in `const_missing' from /app/trunk/vendor/plugins/rspec_on_rails_old/lib/spec/rails/dsl/behaviour/rails_example.rb:6 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' from /app/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:496:in `require' from /app/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in' from /app/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:496:in `require' from /app/trunk/vendor/plugins/rspec_on_rails_old/lib/spec/rails/dsl/behaviour.rb:2 ... 24 levels... from /app/trunk/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:13:in `load_files' from /app/trunk/vendor/plugins/rspec/lib/spec/runner/options.rb:75:in `run_examples' from /app/trunk/vendor/plugins/rspec/lib/spec/runner/command_line.rb:21:in `run' from ./script/spec:4 Any ideas on what might be wrong? I looked at that file and all it seems to be doing is requiring other files. I'm going to start a project from scratch to see if I can reproduce the error and see if I can narrow it down to being app specidic.. But has anyone had similar problems? Thanks, Ben From dchelimsky at gmail.com Wed Nov 7 12:46:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Nov 2007 11:46:15 -0600 Subject: [rspec-users] LoadError when upgraded to latest rspec trunk In-Reply-To: <4731F681.2010900@benmabey.com> References: <4731F681.2010900@benmabey.com> Message-ID: <57c63afe0711070946i490dc52ewb54483ac0410eab1@mail.gmail.com> On Nov 7, 2007 11:31 AM, Ben Mabey wrote: > I just moved my rspec and rspec_on_rails plugin from r2691 to r2822. > After that I upgraded both of them I regenerated all things rspec with > the rspec generator. I was running on rails r2691 but upgraded to the > latest at r2822 when I was getting errors but that still didn't help things. I'm on rspec 2822 and rails 8111 and do not have this trouble. > > I get the following when I try to run a spec with either rake spec or > ./script/spec: > > /app/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in > `load_missing_constant': Expected > /app/trunk/vendor/plugins/rspec/lib/spec/test.rb to define Spec::Test > (LoadError) > from > /app/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:453:in > `const_missing' > from > /app/trunk/vendor/plugins/rspec_on_rails_old/lib/spec/rails/dsl/behaviour/rails_example.rb:6 > from > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require' > from > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' > from > /app/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:496:in > `require' > from > /app/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from > /app/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:496:in > `require' > from > /app/trunk/vendor/plugins/rspec_on_rails_old/lib/spec/rails/dsl/behaviour.rb:2 > ... 24 levels... > from > /app/trunk/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:13:in > `load_files' > from > /app/trunk/vendor/plugins/rspec/lib/spec/runner/options.rb:75:in > `run_examples' > from > /app/trunk/vendor/plugins/rspec/lib/spec/runner/command_line.rb:21:in `run' > from ./script/spec:4 > > > Any ideas on what might be wrong? I looked at that file and all it > seems to be doing is requiring other files. I'm going to start a > project from scratch to see if I can reproduce the error and see if I > can narrow it down to being app specidic.. But has anyone had similar > problems? > > Thanks, > Ben > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Wed Nov 7 14:21:19 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 7 Nov 2007 14:21:19 -0500 Subject: [rspec-users] Named routes raising nil.rewrite error Message-ID: <439456E7-AB76-434C-8052-34EFBC38C269@railsnewbie.com> Hi all. I'm having a little problem with named routes. I have the following named route: map.with_options :controller => 'snippets' do |map| map.snippets 'faq/', :action => 'index' map.new_snippet 'faq/ new', :action => 'new' map.snippet_text 'faq/ get/:id', :action => 'get_snippet_text' map.set_snippet 'faq/ set/:id', :action => 'set_snippet_text' map.snippet 'faq/:id', :action => 'show' map.snippet_version 'faq/:id/version/:version', :action => 'version' map.revert_snippet 'faq/:id/version/:version/revert', :action => 'revert' end When trying to write the following spec (a regression), I get the error: ======================================== describe SnippetsController, "routes" do it "should route the snippet_version_url to the version action" do snippet_version_url(:id => "1", :version => "41").should == "/foo" end end ======================================== escher: ./script/spec spec/controllers/regressions/ 2007_11_07_snippets_route_spec.rb F 1) NoMethodError in 'SnippetsController routes should route the snippet_version_url to the version action' You have a nil object when you didn't expect it! The error occurred while evaluating nil.rewrite (eval):19:in `snippet_version_url' ./spec/controllers/regressions/2007_11_07_snippets_route_spec.rb:277: ./script/spec:4: Finished in 0.029341 seconds 1 example, 1 failure ======================================== Should I be using route_for here? I've noticed that the following spec fails: ======================================== describe SnippetsController, "routes" do it "should not raise an error with the snippet_version_url route" do lambda { snippet_version_url }.should_not raise_error end end escher: ./script/spec spec/controllers/regressions/ 2007_11_07_snippets_route_spec.rb F 1) 'SnippetsController routes should not raise an error with the snippet_version_url route' FAILED expected no Exception, got # ./spec/controllers/regressions/2007_11_07_snippets_route_spec.rb:281: ./script/spec:4: Finished in 0.029503 seconds 1 example, 1 failure ======================================== Thanks for any help, Scott PS: Running on Rspec edge, rails 1.2.3 From ben at benmabey.com Wed Nov 7 18:21:30 2007 From: ben at benmabey.com (Ben Mabey) Date: Wed, 07 Nov 2007 16:21:30 -0700 Subject: [rspec-users] Plain Text Story example Message-ID: <4732487A.5060309@benmabey.com> Hey all, Does anyone have an example(s) of the plain text story runner for rails? I have read David's blog (http://blog.davidchelimsky.net/articles/2007/10/22/plain-text-stories-on-rails) about it but I would like to see some examples with all of the step matchers included... I couldn't find any more examples on google talking about the plain text stories and the example rails app in trunk seems to still be using the other format. Does anyone have any links or pasties for me? Thanks, Ben From ben at benmabey.com Wed Nov 7 23:18:55 2007 From: ben at benmabey.com (Ben Mabey) Date: Wed, 07 Nov 2007 21:18:55 -0700 Subject: [rspec-users] Plain Text Story example In-Reply-To: <4732487A.5060309@benmabey.com> References: <4732487A.5060309@benmabey.com> Message-ID: <47328E2F.1090103@benmabey.com> I just ran across this blog which helped me out a lot in answering some of my questions about the plain text story runner: http://www.kerrybuckley.com/2007/11/07/driving-selenium-from-the-rspec-story-runner-rbehave/ The Selenium integration is also an interesting idea that you might want to read about if you haven't seen this post. I'm still trying to decided if using Selenium is worth the extra effort (my main goal would be to test the JS during the acceptance tests) and if the regular rails integration testing is good enough. I'd be interested to hear what other user's on this list think in terms of Selenium or any other browser based framework and there experience with them. -Ben Ben Mabey wrote: > Hey all, > Does anyone have an example(s) of the plain text story runner for > rails? I have read David's blog > (http://blog.davidchelimsky.net/articles/2007/10/22/plain-text-stories-on-rails) > about it but I would like to see some examples with all of the step > matchers included... I couldn't find any more examples on google > talking about the plain text stories and the example rails app in trunk > seems to still be using the other format. Does anyone have any links or > pasties for me? Thanks, > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Nov 8 00:12:28 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Nov 2007 23:12:28 -0600 Subject: [rspec-users] Plain Text Story example In-Reply-To: <47328E2F.1090103@benmabey.com> References: <4732487A.5060309@benmabey.com> <47328E2F.1090103@benmabey.com> Message-ID: <57c63afe0711072112u285a13ecgb56fc416cc300bb7@mail.gmail.com> On Nov 7, 2007 10:18 PM, Ben Mabey wrote: > I just ran across this blog which helped me out a lot in answering some > of my questions about the plain text story runner: > http://www.kerrybuckley.com/2007/11/07/driving-selenium-from-the-rspec-story-runner-rbehave/ It's great to see this conversation advancing so quickly, however please keep in mind that this is all very young and just because someone blog's something (including ME) doesn't mean that it's "the way". While Kerry's example is very clean and obviously works well for him, it does go against the grain of the philosohy that Dan is espousing: expressing stories in the business domain rather than the UI domain (btw Dan, that was brilliantly put). In my own experience with tools like FitNesse, I've seen success and failure regardless of the level or focus of abstraction. In the end, what I think drives the success of tools in this (Acceptance Testing) space is the level of commitment and interaction that customers have with the tools and the stories they are expressing. These are called CUSTOMER Acceptance Tests, after all. And just as TDD is *for* developers, and you're probably doing TDD right if it keeps you product