Sha256: 1fe8d6954fe571cad703e06f601a132540f5fa7e0a716776eb2f215e958025cd

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

describe Shoulda::Matchers::ActionController::AssignToMatcher do
  it 'includes the actual class in the failure message' do
    define_class(:WrongClass) do
      def to_s
        'wrong class'
      end
    end

    controller = build_response { @var = WrongClass.new }
    matcher = assign_to(:var).with_kind_of(Fixnum)
    matcher.matches?(controller)

    matcher.failure_message_for_should.should =~ /kind of Fixnum for var, but got.*\(WrongClass\)$/
  end

  context 'a controller that assigns to an instance variable' do
    it 'accepts assigning to that variable' do
      controller.should assign_to(:var)
    end

    it 'accepts assigning to that variable with the correct class' do
      controller.should assign_to(:var).with_kind_of(String)
    end

    it 'rejects assigning to that variable with another class' do
      controller.should_not assign_to(:var).with_kind_of(Fixnum)
    end

    it 'accepts assigning the correct value to that variable' do
      controller.should assign_to(:var).with('value')
    end

    it 'rejects assigning another value to that variable' do
      controller.should_not assign_to(:var).with('other')
    end

    it 'rejects assigning to another variable' do
      controller.should_not assign_to(:other)
    end

    it 'accepts assigning to the same value in the test context' do
      expected = 'value'
      controller.should assign_to(:var).in_context(self).with { expected }
    end

    it 'rejects assigning to the another value in the test context' do
      expected = 'other'
      controller.should_not assign_to(:var).in_context(self).with { expected }
    end

    def controller
      build_response { @var = 'value' }
    end
  end

  context 'a controller that assigns a nil value to an instance variable' do
    it 'accepts assigning to that variable' do
      controller = build_response do
        @var = nil
      end
      controller.should assign_to(:var)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoulda-kept-assign-to-1.0.1 spec/shoulda/matchers/action_controller/assign_to_matcher_spec.rb