Re: [rspec-users] ruby 1.8.6
On Aug 21, 2011, at 9:11 PM, David Chelimsky wrote: Hey all, It's growing increasingly difficult for RSpec to support Ruby 1.8.6 as other libraries that rspec's development environment relies on drop support. Noting that 1.8.7 was released over three years ago (6/1/2008), I'd like to drop support for Ruby 1.8.6 for future versions of RSpec, but I'd like to hear from you before I cut the cord. Please raise your objections now or forever hold your peace. All of my legacy projects and new projects are 1.9-only, so there is no objection from me. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Can you control $stdout when specs are running?
On Sep 30, 2010, at 10:06 AM, GregD wrote: Hi all, I'm testing java classed using rspec and jruby. The java super class is trapping an exception and sending a custom message to stdout along with the original exception meaasage. The original exception is a SAXParseException, if that really matters. Well, my test is to see if the child object class can handle a garbled XML message a certain way. The test passes, but I get the nasty java exception stuff that is being sent to stdout when the tests are running, yuk. I tried closing and opening stdout before and after that particular test and that did not work or I did it wrong. And I'm not sure this is desirable if the test fails. Any ideas on this other than to replace the java with ruby or have the java not to dump to stdout? ;-) Both of which, I can not do. But, I can live with the nastiness of this, if there is no possible way around it. I'd like to bump this message because I am facing a similar situation. What's a good technique for spec'ing code that prints to STDOUT yet keeps the spec output nice and clean? cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec-2.2 is released!
On Nov 29, 2010, at 9:27 AM, David Chelimsky wrote: On Nov 29, 2010, at 8:04 AM, Chuck Remes wrote: On Nov 28, 2010, at 4:35 PM, David Chelimsky wrote: ### rspec-core-2.2.0 * Performance improvments (see [Upgrade.markdown](https://github.com/rspec/rspec-core/blob/master/Upgrade.markdown)) Wow, the perf improvements are *much* appreciated! My test suite (MRI 1.9.2p0) with 3300 examples went from 7.4s under 2.1.0 to 3.2s with 2.2.1. Most excellent! Glad to hear it. My benchmarks were based on an essentially empty spec suite (so no overhead from the implementation code). Hearing that with a real app we're still getting 1k examples per second makes me very happy :) I'm assuming, however, this is not a Rails app, correct? Correct, this is not a rails app. I write straight-up ruby code. :) cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec-2.2 is released!
On Nov 28, 2010, at 4:35 PM, David Chelimsky wrote: ### rspec-core-2.2.0 * Performance improvments (see [Upgrade.markdown](https://github.com/rspec/rspec-core/blob/master/Upgrade.markdown)) Wow, the perf improvements are *much* appreciated! My test suite (MRI 1.9.2p0) with 3300 examples went from 7.4s under 2.1.0 to 3.2s with 2.2.1. Most excellent! cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec2 observations
On Oct 6, 2010, at 9:30 AM, David Chelimsky wrote: On Oct 6, 2010, at 9:09 AM, Chuck Remes wrote: Just a few observations now that I have completed the upgrade from RSpec-1 to RSpec-2. 1. In my project (2800 examples across about 40 files), MRI 1.9.2-p0 takes roughly 3 times longer to complete the spec run. Runtimes grew from 2.2s (rspec 1.3.0) to 6.1s (2.0.0.rc). Is this a Rails-3 project? Are you using the time that rspec displays, or measuring that yourself (including load times before the spec run starts)? Nope, no Rails. This is a work project which uses a few gems like ffi-rzmq, zmqmachine, sequel, mongo/bson, etc. It's a set of distributed applications for a trading system; no web stuff at all. I don't know if this is an issue with RSpec-2 or if Rubinius JRuby require an update. Or, perhaps the problem is elsewhere and this warning is a red herring. Guidance on this would be welcome; I am happy to open an issue with these other projects if the fault lays there. That warning would only happen if something was trying to reference the Spec module instead of RSpec. Feel free to open an issue for this so we can track it, but I'm pretty sure it's not anything RSpec can fix. Thanks for the feedback! I'll try to pinpoint the error a bit better before opening an issue. Thanks for a great tool like rspec! It gives me confidence in my code. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec-2.0.0.rc is released
On Oct 4, 2010, at 11:47 PM, David Chelimsky wrote: rspec-2.0.0.rc is released! See http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/ for links to all sorts of documentation on rspec-2. Plan is to release rspec-2.0.0 (final) within the next week, so please install, upgrade, etc, and report issues to: http://github.com/rspec/rspec-core/issues http://github.com/rspec/rspec-expectations/issues http://github.com/rspec/rspec-mocks/issues http://github.com/rspec/rspec-rails/issues Is there any coordination with the authors of jeweler, bones, etc. so that the Rake files those tools generate can be updated to rspec2 compatibility? Speaking of which, the Upgrade.markdown didn't include enough information to get my existing Rakefile (created by bones) working. I'm including the changes I had to make in this email so other folks searching the ML will find it. Original: require 'spec/rake/spectask' Spec::Rake::SpecTask.new do |t| t.spec_opts = ['--options', \spec/spec.opts\] t.spec_files = FileList['spec/**/*.rb'] end For rspec2 compatibility: require 'rspec/core/rake_task' RSpec::Core::RakeTask.new do |t| t.rspec_opts = [-c, -f progress, -r ./spec/spec_helper.rb] t.pattern = 'spec/**/*_spec.rb' end Also, as mentioned in the Upgrade.markdown file, I had to modify my spec_helper.rb to use Rspec.configure instead of the original Spec::Runner.configure syntax. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] set expectation using self in constructor?
On Jul 14, 2010, at 4:20 PM, Matt Wynne wrote: You can do this, by using a test spy to remember the value of foo passed into the stubbed constructor and then later comparing it: let(:foo) { Foo.new } it should allocate a helper class Foo do actual_foo = Bar.should_receive(:new) do |the_foo| the_foo end actual_foo.should == foo end Whether you want to do this though, is another question. I think it's a bit of an anti-pattern personally. I'd probably let acceptance tests catch mistakes in this kind of thing, and concentrate on speccing the interaction between Foo and Bar once you've got the instances spun up. This is an interesting technique. I didn't realize that using the block form of expectations/matchers returned a value. Thanks for the tip! cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] [Q] mock expectation with +self+
I am trying to spec out a method that is using the 'beam' gem to fire an event. When the method fires the event, it should pass the current +self+ as an argument. e.g. def foo Beam.fire :my_event, self end it should fire :my_event and pass self do Beam.should_receive(:fire).with(:my_event, ) foo end How can I set a mock expectation to work resolve self correctly? I suspect it isn't possible but I'd like confirmation before I waste too much time on this. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] [Q] mock expectation with +self+
On Sep 9, 2009, at 4:37 PM, Chuck Remes wrote: I am trying to spec out a method that is using the 'beam' gem to fire an event. When the method fires the event, it should pass the current +self+ as an argument. e.g. def foo Beam.fire :my_event, self end it should fire :my_event and pass self do Beam.should_receive(:fire).with(:my_event, ) foo end How can I set a mock expectation to work resolve self correctly? I suspect it isn't possible but I'd like confirmation before I waste too much time on this. Ugh, never mind. :-\ I should have thought a little harder before posting... sorry for the noise. cr class Bar def foo Beacon.fire :my_event, self end end it should fire :my_evnet and pass self do @klass = Bar.new Beacon.should_receive(:fire).with(:my_event, @klass) @klass.foo end ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] arbitrary handling of received messages in mocks
On Aug 25, 2009, at 5:13 PM, Tom Stuart wrote: On 25 Aug 2009, at 20:59, Chuck Remes wrote: The documentation says the expectation passes or fails based upon the return value of the block. I can't even force it to fail by returning false. The docs (http://rspec.info/documentation/mocks/message_expectations.html ) say: You can supply a block to a message expectation. When the message is received by the mock, the block is passed any arguments and evaluated. The result is the return value of the block. This means that the mocked method will return the value that is returned by the block; by returning false in your block, you're just arranging for the mocked method to return false. (So this is the same as @api.should_receive(:publish_to_bus).and_return(false).) If you want the message expectation to fail, you need to put a failing expectation inside the block. Setting an expectation within the block makes it work. I think the docs should be clearer that the expectations inside are necessary. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] [Q] testing WIN32OLE_EVENT callbacks
I'm trying to setup some specs (really just assertions) that verify some callbacks are executed in response to COM events. In the WIN32OLE_EVENT class you may subscribe to a COM event and have it delivered to you for processing. Syntax looks like: event_handler.on_event('StartEvent') do |*args| do_start_event args end The #do_start_event method is a member of the containing class. The only way I can confirm that it is being called is to set an expectation on the class under test. I've always noted that mocking/ stubbing the class under test is rather bad form. Regardless, I don't know how to mock the delivery of an event anyway so this may all be moot. I searched the list archives for 'win32ole' back to early 2007 and came up with 0 hits. Any suggestions on how to tackle this? cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] arbitrary handling of received messages in mocks
I am trying to process a message sent to a mock to verify it contains the correct keys. In my case I am sending a JSON string to the mock built from data passed in via the test. The object internally builds a hash and then constructs the JSON string from it. I can't get my mock to fail though. Here's an example similar to what I've got. describe Foo it should match the json string do # setup stubs mocks ... hsh = ... # keys and values used inside the method @api.should_receive(:publish_to_bus) do |message| false # should always fail end Foo.new(@api).decode hsh end end The documentation says the expectation passes or fails based upon the return value of the block. I can't even force it to fail by returning false. Once I figure this out, I plan to decode the JSON string in the mock block and compare the resulting collection with the data I originally passed in to the object. This behavior will likely become a helper method (if that matters). What am I doing wrong? rspec 1.2.8 ruby 1.8.6 patch 287, Windows Running under Netbeans 6.7.1 Thank you for your help. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] How to unit test code that connects to the external resources?
On Sep 8, 2008, at 12:12 PM, Yi Wen wrote: By external resources, I mean, the code start a http connection and GET xmls from the url specified. I will definitely not rely my unit test on an external url or anything like that. But how do I unit test the method? I mean, I can basically mock the Net::HTTP, but then the test will pretty much be like the method itself, except all the calls will be replaced by stub! or should_receive. I made this method as simple as possible. There is no if statements or loop in the method, should I just NOT test this one? Thanks for any ideas Show us the code so we can help. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] spec'ing the existence of #require
On Aug 31, 2008, at 12:42 PM, Scott Taylor wrote: On Aug 31, 2008, at 10:36 AM, Chuck Remes wrote: I looked through the mailing list archive but unfortunately my search terms are too generic (spec and require...). I am writing ruby code that runs under jruby in an embedded environment. Periodically I will install new code that passes all specs only to have it fail when it can't find a new class I defined (missing #require). My spec_helper.rb file does a wildcard search and loads all rb files in the tree, Why? Why don't you just have it load lib/your_project_name.rb, which requires everything else? I don't know. Is that the right way to do it? The way I am doing it now mimics how the rspec gem includes all of the rspec files for testing, so I took that as an accepted practice. I'll be happy to try your method if it doesn't have a hidden gotcha too. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] spec'ing the existence of #require
On Aug 31, 2008, at 2:58 PM, David Chelimsky wrote: On Sun, Aug 31, 2008 at 2:38 PM, Chuck Remes [EMAIL PROTECTED] wrote: On Aug 31, 2008, at 12:42 PM, Scott Taylor wrote: On Aug 31, 2008, at 10:36 AM, Chuck Remes wrote: I looked through the mailing list archive but unfortunately my search terms are too generic (spec and require...). I am writing ruby code that runs under jruby in an embedded environment. Periodically I will install new code that passes all specs only to have it fail when it can't find a new class I defined (missing #require). My spec_helper.rb file does a wildcard search and loads all rb files in the tree, Why? Why don't you just have it load lib/your_project_name.rb, which requires everything else? I don't know. Is that the right way to do it? The way I am doing it now mimics how the rspec gem includes all of the rspec files for testing, It does? What I see is that the spec files all include spec_helper.rb, which, in turn, adds lib to the path and then requires 'spec'. What are you thinking of when you say the gem includes all the files for testing? sigh You are right. That is *not* what rspec does. I know I copied this from some major gem that used rspec but now I can't find it. I retract what I said about rspec including everything (via the spec_helper.rb). I'll try creating a single file that #requires everything I need and see if that accomplishes all I need. Thanks for the tips. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] How much test data to use in specs
We'd recommend that you start sending our your resumé. :) cr On Aug 27, 2008, at 1:55 PM, Jonathan Linowes wrote: what if my office were at Route 102 Yahoo! Way, Suite #123 :) On Aug 27, 2008, at 2:03 PM, Nick Hoffman wrote: On 2008-08-27, at 12:57, Rahoul Baruah wrote: For this, trivial, example, I find that far too verbose. The specification says if it is less than 2 characters then invalid and if it is more than 128 characters then invalid . But you are actually running three checks - if less than 2, if greater than 2 but less than 128 and if greater than 2 and greater than 128. B Rahoul Baruah This is what I ended up with: Property addresses that are valid - can't be 129 characters - can't have a 1-letter street name - can't have an - can't have an ! - can't have a - can't have 2 letters after the street number - can't be missing a street number - can't have only 3 characters - can't be empty - can have 128 characters - can have 127 characters - can have only 5 characters - can have only 4 characters - can have a , - can have a - - can have a ' - can have 1 letter after the street number - can have multiple spaces ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] [bug] mock expectations fail when a subclass is instantiated
I took a look at the web site but did not see any issue/bug tracker, so I'm reporting this here. The mock framework fails to differentiate between messages sent to a parent class versus a subclass, so some of my expectations fail when I assert some expectation on a parent. Here's code to show it: cremes$ cat c.rb class A end class B A end class C def foo a = A.new b = B.new end end cremes$ cat c_spec.rb require 'rubygems' require 'spec' require 'c' describe C, mock do it should incorrectly pick up message sent to parent class as a subclass err do A.should_receive(:new).once c = C.new c.foo end end cremes$ spec c_spec.rb F 1) NoMethodError in 'C mock should incorrectly pick up message sent to parent class as a subclass err' undefined method `new' for B:Class ./c.rb:10:in `foo' ./c_spec.rb:9: Finished in 0.006664 seconds 1 example, 1 failure If I capture the exception thrown here, it is at lib/spec/mocks/ proxy.rb line 75. I'd provide a patch if I knew how to fix it! :) cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] help with test design
I'm having trouble figuring out how to drive the design of a class. I'm hoping I can get a hint or two from the more experienced BDDers on this list. I'm writing an adapter class that sits between a 3rd party library and my business logic. I would like to extract some information from objects available from the 3rd party lib and covert them into ruby objects. My desire is to insulate my ruby business logic from changes in the 3rd party library by putting all of this conversion code into a single adapter class (and some related event classes). Using BDD techniques I have created a pretty simple interface to the adapter class. So far the adapter class has two main public methods (plus a bunch of accessors to allow the dependency injection). #discover_instruments - this method calls into the 3rd party library and pulls out the 3rdPartyInstrument object and stores it off for further manipulation #save_components - this method permanently saves the 3rdPartyInstrument if it is a FUTURE, or if it is a COMBINATION it iterates through each sub-3rdPartyInstrument and saves it off Using mocks and ruby's brain-dead simple support for dependency injection I have been able to mock out and verify this behavior. Now I need to add another public method which I will call #generate_internal_instruments. What I would like this method to do is iterate through my #components and create two related objects. Object one will be my RubyInstrument class (called something else, but this will suffice) and a second is a RubyInstrumentCreationEvent. The intention is to pass the 3rdParty component to RubyInstrumentCreationEvent.new(component) where it will extract all salient details from the 3rdParty component (again, this is for insulating the business logic from knowing this 3rd Party lib). Then I will pass this RubyInstrumentCreationEvent to RubyInstrument.new (or RubyInstrument.build) where it will finish the construction of itself. Ideally, all of these steps would be private to the Adapter class and would expose a single public interface called #build. All of these public methods exist solely so I can test these specific behaviors. Any suggestions on how to accomplish my goals? Is my difficulty pointing at a code smell that I am not detecting? cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Given .. and .. - And requires capitalisation
On Mar 31, 2008, at 4:53 PM, Tim Haines wrote: Hi Guys, Just writing out a plain English story and was surprised to see one of my steps wasn't listed as pending. It turned out it was because I had started the line with and instead of And. Is there any reason why and shouldn't be an alias for And? Tim, I would get it is because 'and' (lower case) is a reserved word in Ruby. Note that all of these commands are uppercase. I don't think they can alias 'and' without potentially breaking lots of valid ruby code (not everyone uses '' for 'and' exclusively). cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] [Q] bug in mocks or user error?
I'm trying to use a mock to return a hash so that #each_pair can process it. I can't get it to work. Whatever I return to #each_pair is ignored and the block never gets executed. Here's an example illustrating the problem. require File.join(File.dirname(__FILE__), %w[spec_helper]) class MyExample attr_reader :result def example(data) data.each_pair do |key, value| @result = {key = value} end end end describe MyExample, mock#each_pair fails do it should return a hash after processing the mock using each_pair do sample_mock = mock(sample) real_hash = {:key = :value} sample_mock.should_receive(:each_pair).once.and_return(real_hash) obj = MyExample.new obj.example(sample_mock) obj.result.should == real_hash end end I tried returning different things in case the hash was the wrong intermediate. I tried: #and_return([:key, :value]) #and_return([[:key, :value]]) #and_return(:key, :value) None worked. Is this a bug or am I misusing mocks? cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] [Q] bug in mocks or user error?
On Mar 28, 2008, at 1:46 PM, David Chelimsky wrote: On Fri, Mar 28, 2008 at 1:38 PM, Chuck Remes [EMAIL PROTECTED] wrote: I'm trying to use a mock to return a hash so that #each_pair can process it. I can't get it to work. Whatever I return to #each_pair is ignored and the block never gets executed. Here's an example illustrating the problem. require File.join(File.dirname(__FILE__), %w[spec_helper]) class MyExample attr_reader :result def example(data) data.each_pair do |key, value| @result = {key = value} end end end describe MyExample, mock#each_pair fails do it should return a hash after processing the mock using each_pair do sample_mock = mock(sample) real_hash = {:key = :value} sample_mock.should_receive(:each_pair).once.and_return(real_hash) obj = MyExample.new obj.example(sample_mock) obj.result.should == real_hash end end each_pair does not return the hash, it yields it to a block. Try this: sample_mock.should_receive(:each_pair).once.and_yield(real_hash) Dave, thanks for the hint. That almost worked but I got this error: Spec::Mocks::MockExpectationError in 'MyExample mock#each_pair fails should return a hash after processing the mock using each_pair' Mock 'sample' yielded |{:key=:value}| to block with arity of 2 Changing it slightly allowed it to work correctly: describe MyExample, mock#each_pair fails do it should return a hash after processing the mock using each_pair do sample_mock = mock(sample) real_hash = {:key = :value} sample_mock .should_receive(:each_pair).once.and_yield(real_hash.keys.first, real_hash.values.first) obj = MyExample.new obj.example(sample_mock) obj.result.should == real_hash end end Thanks for your help. SrBaker has been enriched as a result. :-) cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Trouble with my first Story
On Mar 26, 2008, at 4:02 PM, Glenn Ford wrote: Hi all! I've been through the RSpec Stories PeepCode and some various other readings online, and now I'm trying to build a dummy application of the traditional style: log in, make posts, add comments. So I've run the scaffold for posts/comments and the script for RestfulAuthentication so I have the users and SessionController and all that set up in this project. Now I've written this story: http://pastie.caboo.se/pastes/171140 In it I'm trying to do a post to /session/create in order to log in. I figure I want to be able to call this from an Story so that I can reuse it for different scenarios when I want to test things requiring login. What am I doing wrong here? Glenn, please include a pastie that shows the error you are getting or the behavior that isn't working. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] [Q] how do I test the behavior of a Builder pattern object?
So I have a complex object that I need to construct. This complex object, at runtime, takes an object in its initializer. The initializer interrogates the object and creates several collaborative objects based upon values from that interrogation. The construction is complicated enough that it pretty much begs to be implemented via the Builder Pattern. My problem is that I don't know how to test this behavior regardless of whether the object handles its own construction or I create a separate Builder object to construct it for me. For example: class ComplexObjectBuilder def initialize @complex_object = ComplexObject.new end def create_foo(control, value) case control do when :a then @complex_object.foo = SpecialObject.new(value * 4) when :v then @complex_object.foo = OtherObject.new when :z then @complex_object.foo = YAObject.new end end def create_bar(control, value) # similar to above end def construct # some business rules to make sure the object is complete; use # defaults for fields that were not set via the interface return @complex_object end end @builder = ComplexObjectBuilder.new @builder.create_foo(params_object.accessor1, params_object.accessor2) @builder.create_bar(params_object.accessor3, params_object.accessor4) baz = @builder.construct How the heck do I test anything here? I do not see how I can validate the behavior of #create_foo or #create_bar without exposing @complex_object via a public interface. Those #create_* methods are purely for construction and do not return a value. Only #construct returns a value which should be the completed object Is there a transformation to consider to make this more testable? I'm hoping someone has tackled this before and can provide me some insight. Many thanks... cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] [Q] how do I test the behavior of a Builder pattern object?
On Mar 24, 2008, at 8:50 PM, Chuck Remes wrote: [snip code] How the heck do I test anything here? I do not see how I can validate the behavior of #create_foo or #create_bar without exposing @complex_object via a public interface. Those #create_* methods are purely for construction and do not return a value. Only #construct returns a value which should be the completed object Is there a transformation to consider to make this more testable? Just to show I'm not sitting back and waiting for the answer to be handed to me on a silver platter... I looked through the rspec specs and found a construction that might be useful. In spec/spec/extensions/main_spec.rb we see this: it should create an Options object do @main.send(:rspec_options).should be_instance_of(Spec::Runner::Options) @main.send(:rspec_options).should === $rspec_options end In a #before block the @main instance variable was instantiated and a module was included. I'm assuming #send is used to check the value of a private accessor. So I could potentially do something like this: describe ComplexObjectBuilder, construction do before(:each) do @builder = ComplexObjectBuilder.new @builder.foo(control1, val1) @builder.bar(control2, val2) end it should create a YAObject for #foo do @builder.send(:foo).should be_instance_of(YAObject) end it should create a ZObject for #bar do @builder.send(:bar).should be_instance_of(ZObject) end end Is this acceptable? I read through the specs on private methods thread and the consensus was this should only be done when there is *no other option*. Is there another option? cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] What is your workflow? Or how to use the story runner the right way.
On Mar 4, 2008, at 7:43 AM, Chris Parsons wrote: [snip details about story spec workflow] Sound like a lot of work, but given practice you can zip through these steps very quickly. You also get a free 'focusing tool' (lose sight of where you are? just run the story test and write more specs). Hope this is helpful. Maybe I should write up an extended example as a blog post, including mocking etc, as it seems to come up a lot. Thanks Chris Sorry to resurrect an old thread... I've just spent the last 10 hours working on understanding user stories and their role in designing code. Here's what I've done: * watched the RSpec User Stories peepcode * scoured this newsgroup for tips suggestions * used Chris' methodology to BDD a new app So far things are going well though the process is S L O W. I've tried to cobble together tips from other threads regarding directory structure for the stories, steps specs amongst other things, but it just feels really scattered to me. I would love to see Chris put together a more detailed example of his workflow. It's likely I am making some boneheaded mistakes that I just can't pick out yet. When I'm further with my example project, I'll try to post it up somewhere (or turn it into doc for the rspec site) so others can learn from my mistakes. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] for a beginner - good rspec examples?
On Mar 11, 2008, at 8:52 AM, Daniel Kehoe wrote: I'm learning to use rspec and I want to see some good examples. Any recommendations of open source projects that demonstrate the use of rspec? So far I've found: 1) the Caboose sample app (http://sample.caboo.se/) 2) the Altered Beast forums app (http://beast.caboo.se/forums/1/topics/4650 ) Any others come to mind? I'm especially interested in seeing examples that spec RESTful authentication. Daniel, I was in your place asking this question about a month ago. Here are the pointers that were helpful to me. [1] http://www.oreillynet.com/pub/a/ruby/2007/08/09/behavior-driven-development-using-ruby-part-1.html [2] http://svn.nightlite.org/applications/cody/trunk/ After examining the links above, I rewrote a small project that I already had working only this time I used BDD for the process. I ended up writing about 50% more code and created about 100% more methods, but the resulting program was much easier to understand and very easy to extend. I also had 100% code coverage which was a first for me. I don't know if the code I wrote would be useful to you but I would be happy to send you a tarball (under 50k) containing this project. Good luck. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] [Q] how to restructure tests for an abstract class?
On Feb 25, 2008, at 8:30 AM, David Chelimsky wrote: On Mon, Feb 25, 2008 at 6:23 AM, Chuck Remes [EMAIL PROTECTED] wrote: Thanks for asking this question. This is exactly what I was going to write, but you beat me to it! (Sorry for the top-post; just following the last responder.) cr On Feb 25, 2008, at 3:30 AM, Matthijs Langenberg wrote: Question is, would you duplicate the specs for all the classes that include a certain module (through shared behaviour for example), or would you use one set of specs for just the module, and specify that a class should include that module? Matthijs - I'd throw the same question back to you. Have you tried both approaches? How have they worked out for you? I won't wait for your answer :). But I am curious about other people's experiences with this. I can tell you this from my own experience - I tend to use shared groups for this for a couple of reasons. One, I like to see the specs for each object. I thought I'd share my experiences with the group. Please recall I'm new at BDD/TDD so I may get some of the terminology wrong or whatever. So I have a class that, by itself, doesn't do anything. Concrete subclasses are necessary to flesh out a few characteristics before the parent class code can perform its magic. This is an abstract class which I'm told isn't the Ruby Way, so I'm looking at turning it into a module (a topic for another message). Originally, I was curious how to refactor my classes (and tests). I decided to write a second concrete subclass to see what kind of problems I might run into. I figured *any* problem I encountered was just more information for me to figure out the correct direction. The second subclass started out normally enough. I spec'd some behavior unique to that subclass. So far, so good. Then it occurred to me that I had no idea if the parent class was really being exercised by my new tests; turns out it wasn't being exercised. To resolve this I started adding some tests to make sure I covered the original behavior of the parent class. Now I had code duplication. The parent class tests and my *first* subclass were duping some of the same behavior. Looking into the examples directory I saw the concept of #shared_examples_for. I refactored my tests using shared examples. Most of these went into the parent class (perhaps soon to be a module). All the tests in my subclasses then focused exclusively on the behavior unique to that specific class while the describe blocks called #it_should_behave_like for shared behaviors. This DRY'ed the code up considerably. An added benefit was some test breakage I ran across while refactoring the tests. My second subclass had some rather tight coupling to the tests, so when I made it shared the subclass test broke. It forced me to rethink some of the test and class design to loosen the coupling. Ultimately it led to a better class api. So, that's my rambling summary. Kudos to you if you read this far. My next goal is to DRY up some of my 'before (:each)' blocks. I continually do the same setup operations across #describe blocks (@buf = Buf.new; @msg = blah, etc). It looks like I may want to define subclasses of a parent Spec::ExampleGroup so the subclasses can inherit some of the #before setup. I'd love to hear experiences from others on this technique. Lastly, I thought I'd say a word on the resulting class code. This BDD project was a learning experience. I rewrote a set of classes that I had originally written the old-fashioned way; puzzle through the logic in my head, write the code, and then debug the crap out of it until it worked. The original classes are rather short (LOC) with only a few methods (3 or 4). The classes I wrote via BDD are longer, maybe by 40% in terms of LOC. Plus, I now have around 10 methods none of which exceeds 5 lines of real code. It's more readable, more logical, and *far* easier to subclass. I'm now a believer. YMMV. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] [Q] how to restructure tests for an abstract class?
Thanks for asking this question. This is exactly what I was going to write, but you beat me to it! (Sorry for the top-post; just following the last responder.) cr On Feb 25, 2008, at 3:30 AM, Matthijs Langenberg wrote: Question is, would you duplicate the specs for all the classes that include a certain module (through shared behaviour for example), or would you use one set of specs for just the module, and specify that a class should include that module? On Sun, Feb 24, 2008 at 12:19 AM, Pat Maddox [EMAIL PROTECTED] wrote: On Thu, Feb 21, 2008 at 8:09 AM, Chuck Remes [EMAIL PROTECTED] wrote: While practicing BDD on my first-ever BDD project, I have come to a point where it makes sense to change my original class to an abstract class and create one (or more) concrete subclasses that implement a specific method. What is the right way to restructure the tests in this scenario? Do I leave the existing tests in place and just create a new spec file that instantiates and tests the concrete subclass? I think I can continue to instantiate my abstract parent as long as I don't go near the behavior that will be defined by the concrete subclasses. Is that the right thing to do? Thanks for any hints. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users I think that shared example groups might be useful. Pat ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] [Q] how to restructure tests for an abstract class?
While practicing BDD on my first-ever BDD project, I have come to a point where it makes sense to change my original class to an abstract class and create one (or more) concrete subclasses that implement a specific method. What is the right way to restructure the tests in this scenario? Do I leave the existing tests in place and just create a new spec file that instantiates and tests the concrete subclass? I think I can continue to instantiate my abstract parent as long as I don't go near the behavior that will be defined by the concrete subclasses. Is that the right thing to do? Thanks for any hints. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] need to learn by example
On Feb 15, 2008, at 8:14 AM, Kiran1009 wrote: Hi, This is most USEFUL... http://www.oreillynet.com/pub/a/ruby/2007/08/09/behavior-driven-development-using-ruby-part-1.html Check this out... Excellent pointer!! Thank you. I'll see if this series of articles can be added to an rspec wiki (if there is one). cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] need to learn by example
I'm starting a new project which I would like to use as a learning opportunity for BDD. I've searched through the archives of this list for past pointers on web sites and books to peruse but I haven't found very many suggestions on good projects in the wild which put BDD on display. I'm hoping this thread can change that minor oversight. Please post your suggestions for ruby projects (or projects in other languages) that are good examples of BDD in action. I learn best by example; this thread is for all the other lurkers who do too. cr ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users