Sha256: 31f7b5a8a6e65ac61db9c1dbf7deb583e2a1fa47791d2a6eb1eb9dd4487954a7

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# encoding: utf-8

describe Assertion::Messages, "#message" do

  let(:test_klass)  { Test = Class.new { include Assertion::Messages } }
  let(:instance)    { test_klass.new                                   }

  shared_examples "translating" do |state, as: nil|

    subject(:message) { instance.message(state) }

    it { is_expected.to eql "translation missing: en.assertion.test.#{as}" }

    it "sends attributes to translation" do
      expect(I18n).to receive(:translate) do |_, args|
        expect(args.merge(instance.attributes)).to eql args
      end
      subject
    end

  end # shared examples

  context "without attributes" do

    it_behaves_like "translating", true,  as: "right"
    it_behaves_like "translating", false, as: "wrong"

  end # context

  context "with attributes" do

    before { test_klass.send(:define_method, :attributes) { { foo: :FOO } } }

    it_behaves_like "translating", true,  as: "right"
    it_behaves_like "translating", false, as: "wrong"

  end # context

  after { Object.send :remove_const, :Test }

end # describe Assertion::Messages

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
assertion-0.1.0 spec/unit/assertion/messages_spec.rb