Sorry! My posts are very delayed. 

On Apr 17, 2012, at 8:50 PM, Luciano Borges wrote:

> 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
> 

Hadn't seen your entity was State before. You meant abbreviation must be 2 
characters and must be unique within the table. Anyway... my previous post 
still partially relevant for the example above.

>     it "The abbreviation can not be repeated" do
> 
>      # I don't know how to do!
> 
>     end

for unique constraints, I use something like below

describe 'code' do
      ....
      it 'should be unique' do
        attributes = @valid_attributes.merge(:code => 'foo')
        AgeLevel.create!(attributes)
        AgeLevel.new(attributes).should_not be_valid
      end

-lenny

>   end
> end
> 
> Thanks,
> Luciano
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to