require 'spec_helper'

describe Virtus::Coercion::Object, '.to_string' do
  subject { object.to_string(value) }

  let(:object) { described_class }
  let(:value)  { stub('value')   }

  context 'when the value responds to #to_str' do
    let(:coerced) { stub('coerced') }

    before do
      value.should_receive(:to_str).with().and_return(coerced)
    end

    it { should be(coerced) }
  end

  context 'when the value does not respond to #to_str' do
    it { should be(value) }
  end
end

require 'spec_helper'

describe Virtus::Coercion::Object, '.to_string' do
  subject { object.to_string(value) }

  let(:object) { described_class }
  let(:value)  { Object.new      }

  context 'when the value responds to #to_str' do
    let(:coerced) { stub('coerced') }

    before do
      value.should_receive(:to_str).with().and_return(coerced)
    end

    it { should be(coerced) }
  end

  context 'when the value does not respond to #to_str' do
    it { should be(value) }
  end
end

Fix spec by replacing the mock with an Object instance
Fix spec by replacing the mock with an Object instance

* For some reason RSpec::Mocks::Mock defines #to_str in rspec 2, and with the
  spec we're trying to assert what will happen when a non-String-like object is
  passed to the string coercion method.
