The day started with some nice conversations, some about the hackership some about my city, which can be described as a place where you drink and eat a lot!!
Then came the morming stand up round. Yesterday I finished the tutorial so today was the day to continue with units tests for the app, that kind of day that you can not postpone anymore. Of course, it always happens to me (with coding, writing, drawing), when I have to actually start doing stuff of my own I begin procrastinating. So I wrote some emails to some of the new people I met this weekend before is too late I we will forget each other and some others pending for more than a week.
But at some point, “real” testing had to be done, which finally is fun! 🙂
Since my idea, is to do a webcalendar based on events, the first test was event_spec.rb and it looked something like this.
require 'spec_helper'
describe Event do
it "should name be presente" do
@event= Event.new
@event.name = "Name of the event"
@event.name.should be_present
end
it "is invalid without a name" do
@event= Event.new
@event.should_not be_valid
end
it 'should be valid with type' do
@event= Event.new
@event.name = "Name of the event"
@event.type = "Workshop"
@event.should be_present
end
it "should have a location"
end
And well they passed but there was some repetition on them, so I decided to refactor them a bit, so they ended up looking like
require 'spec_helper'
describe Event do
before :each do
@event = Event.new(:name => "Printing the washing machine")
end
it "should name be presente" do
@event.name.should be_present
end
it "is invalid without a name" do
@event.should_not be_valid
end
it 'should be valid with type' do
@event.type = "Workshop"
@event.should be_present
end
it "should have a location"
end
a bit nicer, though is not well indented in this post :-/
While looking for good practices, I ended up on a page written in 2011, which of course was not the best thing to follow, so lesson learned, before reading check when was the documentation written 🙂
Then I continued adding more tests to events, and doing creating a spec for location, so tomorrow will be the time to test associations.
Nice 🙂
Some tips: you can use shoulda and shoulda-matchers to simplify some common specs about validation and associations:
https://github.com/thoughtbot/shoulda
Also, I recommend reading these best practices:
http://betterspecs.org/
And some good tips by @dhh
http://37signals.com/svn/posts/3159-testing-like-the-tsa
Enjoy!
Hands on testing #hackership http://t.co/fC0HtDLBYr
RT @OpPinkPower: Hands on testing #hackership http://t.co/EbZiiZu5Pq https://t.co/1Cvw2iAVGE
RT @OpPinkPower: Hands on testing #hackership http://t.co/fC0HtDLBYr
RT @carolina: Time to put hands on testing :-)))
http://t.co/9AcEpCKKUN @hacker_ship