Skip to content

Latest commit

 

History

History
58 lines (44 loc) · 1.59 KB

README.md

File metadata and controls

58 lines (44 loc) · 1.59 KB

rspec-protobuf

Gem codecov

RSpec matchers for Protobuf.

require "rspec/protobuf"

subject { MyProtoMessage.new(msg: "hi") }

it { is_expected.to be_a_protobuf }

# check type
it { is_expected.to be_a_protobuf(MyProtoMessage) }

# check field values
it { is_expected.to be_a_protobuf(msg: "hi") }
it { is_expected.to be_a_protobuf(msg: /^h/) }

# composite matching
it { expect(result).to include(data: a_protobuf(MyProtoMessage, msg: starting_with("h"))) }

Improved RSpec Errors

Before

Failure/Error: is_expected.to have_attributes(date: { month: 2 })
     expected <ComplexMessage: complex: false, date: <DateMessage: type: :DATE_DEFAULT, month: 1, day: 0, year: 0>> to have attributes {:date => {:month => 2}} but had attributes {:date => <DateMessage: type: :DATE_DEFAULT, month: 1, day: 0, year: 0>}
     Diff:
     @@ -1 +1 @@
     -:date => {:month=>2},
     +:date => <DateMessage: type: :DATE_DEFAULT, month: 1, day: 0, year: 0>,

After

Failure/Error: is_expected.to be_a_protobuf(date: { month: 2 })
     Diff:
     @@ -1 +1 @@
     -:date => {:month=>2},
     +:date => {:month=>1},

Contributing

Yes please :)

  1. Fork it
  2. Create your feature branch (git checkout -b my-feature)
  3. Ensure the tests pass (bundle exec rspec)
  4. Commit your changes (git commit -am 'awesome new feature')
  5. Push your branch (git push origin my-feature)
  6. Create a Pull Request