gouf
1/21/2015 - 8:50 AM

Create simple rspec custom matcher

Create simple rspec custom matcher

# Define custom matcher
RSpec::Matchers.define :be_hello do
  match do |string|
    string.eql? 'hello'
  end
end

describe Main do
  before { @m = Main.new }
  describe 'respond say' do
    subject { @m }

    it { is_expected.to respond_to(:say) }
  end

  describe 'say hello' do
    subject { @m.say }

    it { is_expected.to eq 'hello' }
    it { is_expected.to_not eq 'Hello' }
    it { is_expected.to_not eq 'brabra' }
    it { is_expected.to be_hello }
    it { expect('brabra').to_not be_hello }
  end
end
class Main
  def say
    'hello'
  end
end