[rspec-users] spec template for CRUD?

David Chelimsky dchelimsky at gmail.com
Sat May 5 08:17:54 EDT 2007


On 5/5/07, Marcus Crafter <crafterm at gmail.com> wrote:
> Hi David,
>
> On 05/05/2007, at 12:59 PM, David Chelimsky wrote:
>
> > On 5/4/07, Marcus Crafter <crafterm at gmail.com> wrote:
> >> Hi Chris,
> >>
> >> Looks good mate. Is there also a way of being able to get the name of
> >> the controller or some other variables into the 'it' strings to make
> >> the verbalisations read well for shared specs?
> >>
> >> like:
> >>
> >> it "should assign #{@model.to_s.underscore} for the view....." do
> >
> > How about ...
> >
> > it "should assign #{@model.humanize} for the view....." do
>
> Much better and would be fine with me, but the variable replacement
> currently doesn't resolve @model,etc at all unfortunately.

Oh, I see what you mean. Unfortunately, there's not really a good way
to do this so the variable is available for both the example name and
the example, so for now you'd have to duplicate:

describe SomeController do
  @model = MyModel #this is available for names
  it_should_behave_like "A CRUD Controller"

  before(:each) { @model = MyModel } #this is available within examples
end

What if we were to let  it_should_behave_like take some initialization
variables as well?

  it_should_behave_like "A CRUD Controller for", MyModel

???


>
> Any thoughts where to look? Digging deeper..
>
> Cheers,
>
> Marcus
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list