[Rspec-devel] (no subject)

David Chelimsky dchelimsky at gmail.com
Tue Aug 29 07:29:05 EDT 2006


Nice work Luke. Thanks for promoting the goodness....

The CRC_Card link doesn't go anywhere useful.

The spec that you wrote:

context "A user (in general)" do
  def setup
    @user = User.new
  end

  specify "should be invalid without a username" do
    @user.should_not_be_valid
    @user.username = 'someusername'
    @user.should_be_valid
  end
end

does something that I try to avoid - it sets one expectation, then
changes state, then sets a new expectation. The way I look at this is
that a user with a username and a user without one are two different
contexts. So I'd write this instead (note - "I'd write" - this is my
personal view):

context "A user with no username" do
  def setup
    @user = User.new
  end

  specify "should be invalid" do
    @user.should_not_be_valid
  end
end

context "A user with a username" do
  def setup
    @user = User.new
    @user.username = 'someusername'
  end

  specify "should be invalid" do
    @user.should_be_valid
  end
end

Taking this approach leads to much more granular specs. The down side
is there end up w/ many more specs.

I'd like to take more time but I've got to run. Given that you're
planning to post this soon, I thought I'd get this little bit in.

Cheers,
David




On 8/29/06, Luke Redpath <luke at agileevolved.com> wrote:
> Er, apologies for the missing subject. Should have said "RSpec/Rails
> Tutorial" ;)
>
> On 29 Aug 2006, at 11:48, Luke Redpath wrote:
>
> > Hi guys, I'm working on a two part article, aimed at BDD/RSpec
> > beginners mainly, but also those interested in how to apply BDD
> > principles to Rails development. Its entitled "Developing a Rails
> > model using BDD" and the first part draft is here:
> >
> > http://123.writeboard.com/1fb9120e320c6a92e
> >
> > Password is agile2006
> >
> > The article is a breakdown of my general workflow and the techniques
> > I use when writing my Rails specs.
> >
> > All feedback would be greatly appreciated; I want to publish this bad
> > boy later today on my blog. Pointing out grammar/spelling issues is
> > great but most important are any technical errors.
> >
> > Cheers
> > Luke
> > _______________________________________________
> > Rspec-devel mailing list
> > Rspec-devel at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-devel
>
> _______________________________________________
> Rspec-devel mailing list
> Rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>


More information about the Rspec-devel mailing list