Sha256: bba5c3e457196f7d19830019d71878d0961d4839950a7b301b0281d716b73575

Contents?: true

Size: 1.71 KB

Versions: 10

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'

describe 'validate_format_of' do

  context 'without message' do
    context '#should 'do
      it 'passes if validatation exists' do
        lambda { Tag.should validate_format_of(:name).with(/\w+/) }.should_pass
      end

      it 'fails if validation does not exist' do
        lambda { Tag.should validate_format_of(:id).with(/\w+/) }.
          should fail_with 'expected to validate format of id with /\w+/'
      end
    end

    context '#should_not' do
      it 'fails if validation exists' do
        lambda { Tag.should_not validate_format_of(:name).with(/\w+/) }.
          should fail_with 'expected to not validate format of name with /\w+/'
      end
    end
  end



  context 'with message' do
    context '#should' do
      it 'passes if messages are the same' do
        lambda{ Genre.should validate_format_of(:name).with(/\w+/).
          with_message('Bad format of genre')
        }.should_pass
      end

      it 'fails if messages are different' do
        lambda{ Genre.should validate_format_of(:name).with(/\w+/).
          with_message('Different message')
        }.should fail_with 'expected to validate format of name with /\w+/ and message "Different message"'
      end
    end

    context '#should_not' do
      it 'fails if validation message exists and it is the same' do
        lambda{ Genre.should_not validate_format_of(:name).with(/\w+/).
          with_message('Bad format of genre')
        }.should fail_with 'expected to not validate format of name with /\w+/ and message "Bad format of genre"'
      end
    end
  end

  context 'instance of model' do
    it 'should pass' do
      lambda { Tag.new.should validate_format_of(:name).with(/\w+/) }.should_pass
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
dm-rspec-0.2.4 spec/dm/matchers/validate_format_of_spec.rb
dm-rspec2-0.3.0 spec/dm/matchers/validate_format_of_spec.rb
dm-rspec-0.2.3 spec/dm/matchers/validate_format_of_spec.rb
dm-rspec-0.2.2 spec/dm/matchers/validate_format_of_spec.rb
dm-rspec2-0.2.4 spec/dm/matchers/validate_format_of_spec.rb
dm-rspec2-0.2.3 spec/dm/matchers/validate_format_of_spec.rb
dm-rspec2-0.2.2 spec/dm/matchers/validate_format_of_spec.rb
dm-rspec2-0.2.1 spec/dm/matchers/validate_format_of_spec.rb
dm-rspec-0.2.1 spec/dm/matchers/validate_format_of_spec.rb
dm-rspec-0.2.0 spec/dm/matchers/validate_format_of_spec.rb