[rspec-users] [Newbie''s Doubt] Model''s Tests

Luciano Borges
Wed, 18 Apr 2012 00:50:57 -0000

I''m studying Rspec and doing some model''s tests.

I have a table with a field which must have two characters, the field
should not be empty and can not be repeated.

My doubts is with #.

describe State do
  context "validations" do

    it "The abbreviation should not be empty" do
      subject.abbreviation = nil
      subject.should_not be_valid
    end

    *# I can do like example below or I have to break in parts?*

    it "The abbreviation  should have 2 characters" do
      subject.abbreviation = "BA"
      subject.should be_valid

      subject.abbreviation = "B"
      subject.should_not be_valid

      subject.abbreviation = "BAA"
      subject.should_not be_valid
    end

    it "The abbreviation can not be repeated" do

*     # I don''t know how to do!*

    end
  end
end

Thanks,
Luciano
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20120417/10b48e83/attachment.html>