flickrのアルバムを作る - photoのtestをrspecで書く

sudo gem install rspec

1.1.3が入った

./script/plugin install http://rspec.rubyforge.org/svn/tags/REL_1_1_3/rspec/
./script/plugin install http://rspec.rubyforge.org/svn/tags/REL_1_1_3/rspec_on_rails
./script/generate rspec
./script/generate rspec_model photo
rake db:migrate RAILS_ENV=test


http://www.flickr.com/services/api/misc.urls.html にならって
spec/fixture/photos.yml

# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

correct:
  farm: 1
  server: 2
  photo_id: 1418878
  secret: 1e92283336
  date_taken: 2004-11-29 16:01:26

# two:
#   column: value

spec/models/photo_spec.rb

require File.dirname(__FILE__) + '/../spec_helper'

describe Photo do
  fixtures :photos
  before(:each) do
    @photo = photos(:correct)
  end

  it "should be valid" do
    @photo.should be_valid
  end
  
  it 'invalid_photo_id - null value' do
    @photo.photo_id = nil
    @photo.should have(1).errors_on(:photo_id)
  end
end

app/models/photo.rb

class Photo < ActiveRecord::Base
  #belongs_to :album
  validates_presence_of :photo_id
  
end


./script/spec -c -fs spec/models/photo_spec.rb

Photo
- should be valid
- invalid_photo_id - null value

Finished in 0.080781 seconds

2 examples, 0 failures