Sha256: 08b1534a4b2fd5a3c11e47a930b15aaf948328269a2e8381fde99fbea8df53c7

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

require "spec_helper"
require 'active_support/all'
require 'rspec/rails/matchers/be_valid'

describe "be_valid matcher" do
  include RSpec::Rails::Matchers

  class Post
    include ActiveModel::Validations
    attr_accessor :title
    validates_presence_of :title
  end

  let(:post) { Post.new }

  it "includes the error messages in the failure message" do
    expect {
      expect(post).to be_valid
    }.to raise_exception(/Title can't be blank/)
  end

  it "includes a failure message for the negative case" do
    post.stub(:valid?) { true }
    expect {
      expect(post).not_to be_valid
    }.to raise_exception(/expected .* not to be valid/)
  end

  it "uses a custom failure message if provided" do
    expect {
      expect(post).to be_valid, "Post was not valid!"
    }.to raise_exception(/Post was not valid!/)
  end

  it "includes the validation context if provided" do
    post.should_receive(:valid?).with(:create) { true }
    expect(post).to be_valid(:create)
  end

  it "does not include the validation context if not provided" do
    post.should_receive(:valid?).with(no_args) { true }
    expect(post).to be_valid
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-rails-2.13.0/spec/rspec/rails/matchers/be_valid_spec.rb
rspec-rails-2.14.1 spec/rspec/rails/matchers/be_valid_spec.rb
rspec-rails-3.0.0.beta1 spec/rspec/rails/matchers/be_valid_spec.rb
rspec-rails-2.99.0.beta1 spec/rspec/rails/matchers/be_valid_spec.rb
rspec-rails-2.14.0 spec/rspec/rails/matchers/be_valid_spec.rb
rspec-rails-2.13.1 spec/rspec/rails/matchers/be_valid_spec.rb
rspec-rails-2.13.0 spec/rspec/rails/matchers/be_valid_spec.rb