Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#759) Add reference spec tests for sensu_check JSON provider #765

Merged
merged 1 commit into from
Jul 25, 2017

Conversation

jeffmccune
Copy link
Collaborator

Without this patch there are no spec tests for the sensu_check JSON provider.
This is problem because a reference is needed to specify the expected behavior
of all providers.

This patch implements a pattern of stubbing out the filesystem. All reads and
writes in the provider itself are routed through the read_file and
write_json_object methods. The RSpec tests then use rspec-mocks to stub out
the reads and set expectations on the output.

This reference may be applied to any provider using the flush method. The
setter methods in the provider for each property are expected to update state
in an instance variable, conventionally named @property_flush but named @conf
in the sensu_check provider. The flush method is responsible for writing out
@property_flush (@conf), which we intercept and set expectations on the data
provided.

Resolves #759

@jeffmccune jeffmccune requested a review from ghoneycutt July 21, 2017 22:15
@jeffmccune jeffmccune force-pushed the 759_provider_spec_tests branch 3 times, most recently from 333cd55 to 1479c9f Compare July 21, 2017 22:20
Without this patch there are no spec tests for the sensu_check JSON provider.
This is problem because a reference is needed to specify the expected behavior
of all providers.

This patch implements a pattern of stubbing out the filesystem.  All reads and
writes in the provider itself are routed through the `read_file` and
`write_json_object` methods.  The RSpec tests then use rspec-mocks to stub out
the reads and set expectations on the output.

This reference may be applied to any provider using the `flush` method.  The
setter methods in the provider for each property are expected to update state in
an instance variable, conventionally named @property_flush but named @conf in
the sensu_check provider.  The flush method is responsible for writing out
@property_flush (@conf), which we intercept and set expectations on the data
provided.

N.B. There is a bug with Rspec where the expected and actual values of
multi-line strings will not have a nice diff output if the two strings disagree
on the presence of the trailing newline.  See
https://github.com/rspec/rspec-support/issues/70 for more information.  Because
of this issue in combination with the use of IO#puts in the write_output class
method, care should be taken with the examples to make sure the expected and
actual values agree on the trailing newline.  In this patch, the fixture data
for the expected output is chomp()'ed to match the string passed to
write_output().

Resolves sensu#759
@jeffmccune jeffmccune force-pushed the 759_provider_spec_tests branch from 1479c9f to 6fb1efd Compare July 25, 2017 00:15
@ghoneycutt ghoneycutt merged commit 2662f12 into sensu:master Jul 25, 2017
@ghoneycutt
Copy link
Collaborator

Released in v2.28.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants