#472 √ wontfix
Joseph Wilk

rspec rails generator examining mock framework used

Reported by Joseph Wilk | July 18th, 2008 @ 11:57 AM | in No-Milestone-Assigned

script/generate rspec_*

Looks at the mock framework configured in spec helper and uses the relevant syntax when generating the specs.

Make the generation of the mock/stub code operate using different mock framework adapters. The adapters focus on generating mock and stub strings

For rspec mocking framework something like

def mock_to_s(class_name, method, args=nil, return=nil)
  mock_string = "#{class_name}.should_receive(#{method})"
  mock_string << ".with(#{args})" unless args.nil?
  mock_string << ".and_return(#{return})" unless return.nil?
end

People can provided different adapters for their framework to get valid generated specs.

This way we don't add lots of code specific to the different frameworks to rspec, we just enable making generate use the right mock framework.

I'm happy to work on this if people think it is a useful feature for rspec-rails? Do people think it is worth the effort or is Rspec's direction focused on getting people to use rspec style mocks/stubs?

The other direction is for people to write their own new templates for the relevant mock frameworks.

Comments and changes to this ticket

  • David Chelimsky

    David Chelimsky August 5th, 2008 @ 10:32 AM

      • → Assigned user changed from “” to “David Chelimsky”

    Hey Joseph,

    My initial reaction is that this would force rspec to follow API changes in the different frameworks. Even if this is unlikely to happen because they change infrequently, it's a burden I don't think rspec should absorb. We don't have a fulltime staff and we have enough trouble keeping up with changes in edge rails.

    Maybe the right home for this sort of thing would be a separate generator library. WDYT?

  • Joseph Wilk

    Joseph Wilk August 5th, 2008 @ 10:47 AM

    Hello David,

    Yes I agree with you, the more I've been thinking about it the more I thought it would be best suited as a separate generator library. I was stuck on the idea of lots of templates using mocking syntax but from closer examination its really only the scaffold generator.

    I will add something to the rspec-rr plugin I've been playing around with to try this out. Then perhaps look further at a separate generator lib for the major mock frameworks.

    Thanks

  • David Chelimsky

    David Chelimsky August 5th, 2008 @ 10:50 AM

      • → State changed from “new” to “wontfix”

    Thanks Joseph. I'm going to close this ticket then, but please keep the list posted on your endeavors with rspec-rr.

    Cheers,

    David

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Behaviour Driven Development for Ruby.

Shared Ticket Bins