[rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec
has.sox at gmail.com
Mon Jul 30 07:47:47 EDT 2007
On 7/30/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> On 7/30/07, Mikel Lindsaar <raasdnil at gmail.com> wrote:
> > I find myself doing the same thing... the, open the model and type in
> > the it shoulds...
> > I ws thinking along the same line... probably all that would be needed
> > is a rake task that hooks into the Mock class and runs all the specs
> > taking not of all the stubs and mocks method calls that are made.
> > Then it could PRODUCE the it shoulds...
> > @model = mock_model(People, :id => 1, :name => "Bob")
> > @model.should_receive(:alive?).and_return(true)
> > # rake spec:find_fakes
> > produces:
> > describe People "automatically" do
> > it "should have a name"
> > it "should respond to alive?"
> > end
> > Now... that would be cool....
> I would tend to disagree. RSpec is a Behaviour Driven Development
> tool. The idea is that you write a small example of behaviour FIRST,
> and use that example to drive the implementation. The reason you use
> examples to drive implementation comes from the idea in Test Driven
> Development that it will lead to tighter, more focused and more
> flexible implementations.
> If your examples come after the code, whether they are generated or
> you write them yourself, then you are losing out quite a bit of value
> of the process with which RSpec is aligned.
> Secondly, having a name is not behaviour. Using it might be. Or how
> you set it might be. For example:
> describe Thing do
> it "should use the first initializer argument as its name" do
> Thing.new("João").name.should == "João"
> it "should be alive when first created" do
> Thing.new.should be_alive
> Implicit in these examples are the fact that Thing has a name and
> responds to "alive?", but those are just artifacts in support of the
> That all make sense?
In a fairly abstract way. But how do you keep track of what methods have
been stubbed or mocked?
>From the above Thing.new.alive? will need to be defined. This seems to be
the spec for Thing, but if in a view I said
it "should do_stuff if @thing is alive" do
@thing = mock_model( Thing )
@thing.stub!( :alive? ).and_return( true )
controller.should_receive( :do_stuff )
How do I run the view first without Thing, and also keep track of alive?
being decalred on the Thing instance?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users