[rspec-users] Preconditions

David Chelimsky dchelimsky at gmail.com
Fri Sep 7 19:58:00 EDT 2007


On 9/7/07, Geoffrey Wiseman <geoffrey.wiseman at gmail.com> wrote:
> On 9/7/07, Pat Maddox <pergesu at gmail.com> wrote:
> > describe MyModel, " when saved twice" do
> >
>
> This is the key point I hadn't considered; makes sense, as long as you make
> sure that there's a context wherein the specification that it should have a
> certain number of revisions.  Thanks!
>
> Realized this afternoon that I need to use finer-grained 'test methods' than
> I'm used to.  In some ways the it blocks are closer to assertions than to
> test methods in Test::Unit, in some ways.  So I went from my first crack,
> closer to:
>
> describe Customer, "xml" do
>   before do
>     # set up customer
>   end
>
>   it "should generate valid summary xml" do
>     # generate summary xml
>     # a bunch of shoulds  about the xml
>   end
>
>   it "should generate valid full xml" do
>     # generate full xml
>     # a bunch of shoulds
>   end
> end
>
> To something like this:
> describe Customer, "full xml" do
>    before do
>      # set up customer full xml
>    end
>
>    it "should have a root node of customer" do
>     @doc.root.name.should == 'customer'
>    end
>
>    it "should contain a customer id"
>   it "should have a name and address"
>
>   #etc
>  end
>
> describe Customer, "summary xml" do
>   # etc.
> end
>
> So I guess I'm still learning the mindset in places.  Although you could
> ahve test methods like that in Test::Unit, most of the time you wouldn't
> bother simply because of the shared setup.  But when the blocks affect how
> the spec is described, it's far more important to have fine-grained
> elements, I think.
>
> Actually, on that note -- what's the normal way to share a setup across
> multiple behaviors, a helper method in an includeable module?

You can include callable methods in modules, but they have to be
called from within the spec.

Alternative is shared behaviours:
http://rspec.rubyforge.org/documentation/index.html (scroll down a
bit).

>
> So, thanks for the guidance.
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list