Hi again Ok, so I''m having a little research fling with JavaScript, and I''ve uncovered something I hadn''t seen before: "spying". Basically, inspecting mocks after-the-fact, rather than setting expectations upfront. Here are the articles I found: http://ajaxian.com/archives/mockme-a-new-javascript-mocking-framework http://blog.johanneslink.net/2008/08/08/ajax-travelogue-part-6-mocking-in-javascript/ http://blog.johanneslink.net/2008/08/09/ajax-travelogue-part-7-mockme/ Does anyone know more about this technique, and its pros and cons vs expectation-based mocking as used in RSpec mocks? Thanks for any info Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/
Ashley Moran wrote:> Hi again > > Ok, so I''m having a little research fling with JavaScript, and I''ve > uncovered something I hadn''t seen before: "spying". Basically, > inspecting mocks after-the-fact, rather than setting expectations > upfront. > > Here are the articles I found: > http://ajaxian.com/archives/mockme-a-new-javascript-mocking-framework > http://blog.johanneslink.net/2008/08/08/ajax-travelogue-part-6-mocking-in-javascript/ > > http://blog.johanneslink.net/2008/08/09/ajax-travelogue-part-7-mockme/ > > Does anyone know more about this technique, and its pros and cons vs > expectation-based mocking as used in RSpec mocks? > > Thanks for any info > Ashley >Pat has been working on adding the spy pattern to rspec and JoeSniff has already added it to the rr mocking framework on github I believe. There have been some recent posts on this mailing list about it. Searching for spy in this groups past threads should give you some links to learn more. HTH -Ben
On Oct 16, 2008, at 10:02 pm, Ben Mabey wrote:> Pat has been working on adding the spy pattern to rspec and JoeSniff > has already added it to the rr mocking framework on github I > believe. There have been some recent posts on this mailing list > about it. Searching for spy in this groups past threads should give > you some links to learn more. HTHHi Ben Ah, the original post about this was on my birthday, no wonder I missed it :) Sorry for the I''m-too-damn-lazy-too-search-my-inbox post! Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/
Ben Mabey <ben at benmabey.com> writes:> Pat has been working on adding the spy pattern to rspecI quit once I found not_a_mock [1] which works nicely. My preference would be to pull spies into RSpec eventually, but I want to use it a bit more first (and hopefully others will too). Pat [1] http://notahat.com/not_a_mock
On 18 Oct 2008, at 14:53, Pat Maddox wrote:> more first (and hopefully others will too). > > Pat > > [1] http://notahat.com/not_a_mockLooks sweet - it will be in my first mock on Monday! cheers, Matt
On Oct 19, 2008, at 9:32 am, Matt Wynne wrote:>> [1] http://notahat.com/not_a_mock > > Looks sweet - it will be in my first mock on Monday!Wow, there''s some serious work gone into that, and I never knew it existed! Searched my local archives (from March this year) for Pete Yandell and he hasn''t posted once to promote it. Gonna see if I can shoe-horn it into my Merb app somehow, now is the best time to inflict maximum learning pain on myself :) Thanks for the link Pat. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/
On 19 Oct 2008, at 21:18, Ashley Moran wrote:> > On Oct 19, 2008, at 9:32 am, Matt Wynne wrote: > >>> [1] http://notahat.com/not_a_mock >> >> Looks sweet - it will be in my first mock on Monday!Thinking about it - how do you use multiple mocking frameworks in a given project? Is it safe to re-open a Spec::Runner.configure do |config| block at the top of an individual spec after I''ve loaded spec_helper (which will have to be configured to use the default rspec mocking that 90% of the project uses)? cheers, Matt
On 18 Oct 2008, at 14:53, Pat Maddox wrote:> I quit once I found not_a_mock [1] which works nicely. My preferenceYay! Thanks for the pointer Pat. Baz. Rahoul Baruah Web design and development: http://www.3hv.co.uk/ Nottingham Forest: http://www.eighteensixtyfive.co.uk/ Serious Rails Hosting: http://www.brightbox.co.uk/ Lifecast: http://www.madeofstone.net/
On Mon, Oct 20, 2008 at 2:03 AM, Matt Wynne <matt at mattwynne.net> wrote:> > On 19 Oct 2008, at 21:18, Ashley Moran wrote: > >> >> On Oct 19, 2008, at 9:32 am, Matt Wynne wrote: >> >>>> [1] http://notahat.com/not_a_mock >>> >>> Looks sweet - it will be in my first mock on Monday! > > Thinking about it - how do you use multiple mocking frameworks in a given > project? > > Is it safe to re-open a Spec::Runner.configure do |config| block at the top > of an individual spec after I''ve loaded spec_helper (which will have to be > configured to use the default rspec mocking that 90% of the project uses)?Not really. The problem is that examples are stored for evaluation later, whereas the configuration is evaluated right away. The reason rspec won''t support using multiple mock frameworks is rspec mocks and mocha both extend Object (to support mock behaviour on real objects) and they use the same methods to create instances of mocks. I think that if we wanted to support multiple mock frameworks, all of the frameworks would have to offer an explicit mode where you could extend objects to behave like mocks but would have to do so explicitly for each object. Flexmock already works this way. FWIW, David> > cheers, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
So if I want to have a spec suite which uses a combination of mocking frameworks, is this possible? Maybe if some of the files include ../not_a_mock_spec_helper and the others include ../default_spec_helper and then both those files require some common spec_helper file? On 21 Oct 2008, at 14:47, David Chelimsky wrote:> On Mon, Oct 20, 2008 at 2:03 AM, Matt Wynne <matt at mattwynne.net> > wrote: >> >> On 19 Oct 2008, at 21:18, Ashley Moran wrote: >> >>> >>> On Oct 19, 2008, at 9:32 am, Matt Wynne wrote: >>> >>>>> [1] http://notahat.com/not_a_mock >>>> >>>> Looks sweet - it will be in my first mock on Monday! >> >> Thinking about it - how do you use multiple mocking frameworks in a >> given >> project? >> >> Is it safe to re-open a Spec::Runner.configure do |config| block at >> the top >> of an individual spec after I''ve loaded spec_helper (which will >> have to be >> configured to use the default rspec mocking that 90% of the project >> uses)? > > Not really. The problem is that examples are stored for evaluation > later, whereas the configuration is evaluated right away. > > The reason rspec won''t support using multiple mock frameworks is rspec > mocks and mocha both extend Object (to support mock behaviour on real > objects) and they use the same methods to create instances of mocks. > > I think that if we wanted to support multiple mock frameworks, all of > the frameworks would have to offer an explicit mode where you could > extend objects to behave like mocks but would have to do so explicitly > for each object. Flexmock already works this way. > > FWIW, > David > >> >> cheers, >> Matt >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On Tue, Oct 21, 2008 at 10:41 AM, Matt Wynne <matt at mattwynne.net> wrote:> So if I want to have a spec suite which uses a combination of mocking > frameworks, is this possible? > > Maybe if some of the files include ../not_a_mock_spec_helper and the others > include ../default_spec_helper and then both those files require some common > spec_helper file?That could work - but the conflict I described is a process-wide conflict - so you''d need to run the examples in those dirs w/ separate rake tasks to really eliminate the conflict.> > On 21 Oct 2008, at 14:47, David Chelimsky wrote: > >> On Mon, Oct 20, 2008 at 2:03 AM, Matt Wynne <matt at mattwynne.net> wrote: >>> >>> On 19 Oct 2008, at 21:18, Ashley Moran wrote: >>> >>>> >>>> On Oct 19, 2008, at 9:32 am, Matt Wynne wrote: >>>> >>>>>> [1] http://notahat.com/not_a_mock >>>>> >>>>> Looks sweet - it will be in my first mock on Monday! >>> >>> Thinking about it - how do you use multiple mocking frameworks in a given >>> project? >>> >>> Is it safe to re-open a Spec::Runner.configure do |config| block at the >>> top >>> of an individual spec after I''ve loaded spec_helper (which will have to >>> be >>> configured to use the default rspec mocking that 90% of the project >>> uses)? >> >> Not really. The problem is that examples are stored for evaluation >> later, whereas the configuration is evaluated right away. >> >> The reason rspec won''t support using multiple mock frameworks is rspec >> mocks and mocha both extend Object (to support mock behaviour on real >> objects) and they use the same methods to create instances of mocks. >> >> I think that if we wanted to support multiple mock frameworks, all of >> the frameworks would have to offer an explicit mode where you could >> extend objects to behave like mocks but would have to do so explicitly >> for each object. Flexmock already works this way. >> >> FWIW, >> David >> >>> >>> cheers, >>> Matt >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >