[Rspec-devel] (no subject)

Luke Redpath luke at agileevolved.com
Tue Aug 29 07:43:01 EDT 2006


Hi David

Thanks for your comments. I agree that finer grained specs can be  
useful in some situations but in this situation having a context for  
each attribute, with and without, is more verbose than it needs to  
be. Its worth mentioning that the last two lines of the specs will be  
refactored out in the second part of the article. The reason they are  
there to begin with is that just testing a user without a username is  
invalid only partly tests the specification in my opinion. By setting  
the username then checking it is valid, the spec is fully tested.

My final spec would see all of the set/revalidate lines removed into  
a single spec:

specify "should be valid with a complete set of valid attributes" do
   @user.attributes = valid_user_attributes
   @user.should_be_valid
end

That single spec eliminates the need for the verbosity in the other  
specs, but I want to approach my article in a "get things working,  
then refactor" style.

Thanks for the heads up on the CRC link, I've fixed that.

Cheers
Luke

On 29 Aug 2006, at 12:29, David Chelimsky wrote:

> 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
>>
> _______________________________________________
> Rspec-devel mailing list
> Rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel



More information about the Rspec-devel mailing list