[rspec-users] spec template for CRUD?

Chris Hoffman chris.c.hoffman at gmail.com
Mon May 7 19:55:49 EDT 2007


An argument indeed would be effective.  As long as things like
instance variables are obeying particular conventions, we can make
assumptions based on this model class that is passed.  For example:

describe "list", :shared => true do
  it "should populate #{model.to_s.underscore.pluralize} by calling
#{model}.find(:all)"
  ...

-Chris

On 5/5/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> 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
> >
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list