Sha256: 86b3f0735fb80a9d99ec5ebef7f23d4a9cd93ea8a45dac4a53ad2d4888de149d

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

Feature: errors_on

  Scenario: with one validation error
    Given a file named "spec/models/widget_spec.rb" with:
      """ruby
      require "spec_helper"

      class ValidatingWidget < ActiveRecord::Base
        self.table_name = :widgets
        validates_presence_of :name

        # In Rails 4, mass assignment protection is implemented on controllers
        attr_accessible :name if ::ActiveRecord::VERSION::STRING < '4'

        validates_length_of :name, :minimum => 10, :on => :publication
      end

      describe ValidatingWidget do
        it "fails validation with no name (using error_on)" do
          expect(ValidatingWidget.new).to have(1).error_on(:name)
        end

        it "fails validation with no name (using errors_on)" do
          expect(ValidatingWidget.new).to have(1).errors_on(:name)
        end

        it "fails validation with no name expecting a specific message" do
          expect(ValidatingWidget.new.errors_on(:name)).to include("can't be blank")
        end

        it "fails validation with a short name (using a validation context)" do
          expect(ValidatingWidget.new(:name => "too short")).
            to have(1).errors_on(:name, :context => :publication)
        end

        it "passes validation with a longer name (using a validation context)" do
          expect(ValidatingWidget.new(:name => "a longer name")).
            to have(0).errors_on(:name, :context => :publication)
        end

        it "passes validation with a name (using 0)" do
          expect(ValidatingWidget.new(:name => "liquid nitrogen")).to have(0).errors_on(:name)
        end

        it "passes validation with a name (using :no)" do
          expect(ValidatingWidget.new(:name => "liquid nitrogen")).to have(:no).errors_on(:name)
        end
      end
      """
    When I run `rspec spec/models/widget_spec.rb`
    Then the examples should all pass

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rspec-rails-3.0.0.beta2 features/model_specs/errors_on.feature
rspec-rails-2.99.0.beta2 features/model_specs/errors_on.feature
rspec-rails-2.14.1 features/model_specs/errors_on.feature
rspec-rails-3.0.0.beta1 features/model_specs/errors_on.feature
rspec-rails-2.99.0.beta1 features/model_specs/errors_on.feature