-
Notifications
You must be signed in to change notification settings - Fork 202
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
[RFC] New syntax #611
base: master
Are you sure you want to change the base?
[RFC] New syntax #611
Conversation
While I understand what you are trying to do, I believe the verbosity you are adding will actually lead to more code and confusion. For instance the |
How would this new format work with method chaining?
|
@cyberious 👍 I like it @logicminds something like this describe file('/tmp/test') do
its(:parameters) { is_expected.to include(ensure: 'present') }
it { is_expected.to come_before(file('/tmp')) }
end One of the main ideas behind the new syntax is to discourage the use of long chains of methods in the expectations and instead make it easy to do small, discrete expectations on a resource. This leads to much easier to read tests and output
|
@rodjek adjacent to this, a question on Slack was raised on how to test for global properties of the catalog, like, "no directory with a source should have recurse set to true". Do you see a possibility to integrate such functionality here? |
@DavidS Yep, that's similar to another issue #229 where the user wants to be able to check that all cron resources have certain IO redirects in their command string. What I'm thinking is a way to enumerate resources of a particular type, so maybe something like this? resources(:file).select { |f| f.ensure == 'directory' && f.source }.each do |file_resource|
describe file_resource do
it { is_expected.to have_attributes(:recurse => false) }
end
end |
It reminds me of (global) property-based testing:
|
Yeah, it could be written as: describe resources(:file).select { |f| f.ensure == 'directory' && f.source } do
it { is_expected.to all(have_attributes(:recurse => false)) }
end That would give slightly less easy to understand output in documentation format, but a more consise test. |
How would this deal with resources within a module? given the current double underscore I'd expect Another thing I'd like to see is easy verification of the full content. Currently we have helper functions:
|
I'm planning on introducing a new syntax in rspec-puppet 3.0.0 that encourages the use of standard rspec matchers where possible. If you're using serverspec for your acceptance tests, this will look pretty familiar.
I'm just in the planning and experimenting stage at the moment, and I'd love to hear any suggestions or feedback from the users rspec-puppet. The main change so far is making the resources in the catalogue the subjects of the test, rather than the catalogue itself.
Where currently, you might have a test like this:
It could instead be expressed using standard rspec matchers as:
By creating an expectation on an aspect of the resource, you're implicitly expecting that the resource is present in the catalogue, but you can explicitly specify this expectation by using the standard
exist
matcher.Or in the negative:
The relationships between resources is still implemented with custom matchers, but they are much more lightweight than they are currently.
By making these distinct expectations, you can now easily test negatives (for example, that a resource does not subscribe to another resource) and compound expectations:
As I said at the start, nothing here is set in stone and all suggestions are welcome and will be considered. Whatever the new syntax ends up being, it will work along side the existing syntax, so none of your existing tests will suddenly break. I do plan on deprecating the current syntax in a future major release and eventually removing it in an even later major release, but it won't be any time soon.