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

(SDK-277) Exit cleanly if pdk commands are run outside of a module #100

Merged
merged 2 commits into from
Jun 26, 2017

Conversation

rodjek
Copy link
Contributor

@rodjek rodjek commented Jun 22, 2017

No description provided.

Copy link
Contributor

@DavidS DavidS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the changes are outside the literal scope of the original ticket, but consistency!

if PDK::Util.module_root.nil?
PDK.logger.error(_('pdk validate must be run inside a module'))
exit 1
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Please extract that to PDK::CLI::Util.check_in_module! and apply liberally to all the commands that should run in a module:
  • pdk new class
  • pdk test unit
  • pdk validate
  1. add (no metadata.json found) to ensure users know what we're missing.

require 'fileutils'

describe 'Running validation' do
context 'outside of a module' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have a uniform behaviour above, you can extract this (and https://github.com/puppetlabs/pdk/blob/master/spec/acceptance/new_class_spec.rb#L92) into a shared examples, so this becomes it_behaves_like 'requires running in a module directory'.

@rodjek
Copy link
Contributor Author

rodjek commented Jun 23, 2017

Good point, updated and deduped the tests. The shared example now get automagically included for all example groups with :module_command => true in their metadata.

@@ -1,6 +1,6 @@
require 'spec_helper_acceptance'

describe 'Running ruby validation' do
describe 'pdk validate ruby', module_command: true do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it generally understood by contributors how the shared_examples is being included here? I needed to read rspec-core source to understand what module_command does. It would be more readable to me if it used it_behaves_like 'a module command' to link to the shared example spec code; but I'm fairly new to rspec and shared_example metadata might be a generally understood concept?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I looked at that document and totally overlooked that section.
I still feel this method is a little bit 'magic', but if it's right there in the rspec docs then I think it's OK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the magic thing. And I can't say I'm blown away by the rspec docs either :-( It's definitely something we can keep an eye on, and easy enough to change our minds afterwards.

The main advantage is in my view that it allows for external composeability, that is, a new shared context can add itself to module_commands without requiring changes across the entire test suite. Admittedly that is pretty weak sauce, and also YAGNI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a very poorly documented but still powerful part of rspec

Copy link

@james-stocks james-stocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me except for one comment on the test code that might be a non-issue.

@DavidS DavidS changed the title (SDK-277) Exit cleanly if pdk validate is run outside of a module (SDK-277) Exit cleanly if pdk commands are run outside of a module Jun 26, 2017
@DavidS DavidS added the feature label Jun 26, 2017
@james-stocks james-stocks merged commit eda3649 into puppetlabs:master Jun 26, 2017
@DavidS DavidS added bug and removed feature labels Jun 28, 2017
@rodjek rodjek deleted the sdk-277 branch November 26, 2018 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants