rspec-protobuf
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 :)
- Fork it
- Create your feature branch (
git checkout -b my-feature
) - Ensure the tests pass (
bundle exec rspec
) - Commit your changes (
git commit -am 'awesome new feature'
) - Push your branch (
git push origin my-feature
) - Create a Pull Request