Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

(SIMP-3430) Create Centralized spec_helper.rb #2

Closed
wants to merge 3 commits into from

Conversation

jeannegreulich
Copy link
Contributor

- created baseline for spec_helper.rb
  to do basc RSPEC configuration for SIMP module unit tests.
- added some basic methods that were also in spec_helpers
- added compliance markup methods for use in compliance
  markup unit tests.

SIMP-3430 #comment added simp-spec-helpers

- got spec_helpers.rb from pupmod-simp-pupmod
- moved normalize function from pupmod tests to spec_helper
- create global_spec_helper(dir, modulename) function
  to call from spec_helper.rb.
@jeannegreulich jeannegreulich changed the title (SIMP-3430) Create Centralized spec_helper.rb (SIMP-3430) Create Centralized spec_helper.rb (WIP) Jan 24, 2020
@jeannegreulich jeannegreulich force-pushed the spechelper branch 2 times, most recently from aa608a7 to 685d898 Compare January 27, 2020 21:04
@jeannegreulich jeannegreulich changed the title (SIMP-3430) Create Centralized spec_helper.rb (WIP) (SIMP-3430) Create Centralized spec_helper.rb Jan 27, 2020
@jeannegreulich jeannegreulich force-pushed the spechelper branch 3 times, most recently from 8c387b0 to 43691aa Compare January 29, 2020 22:06
- created baseline for spec_helper.rb
  to do basc RSPEC configuration for SIMP module unit tests.
- added some basic methods that were also in spec_helpers
- added compliance markup methods for use in compliance
  markup unit tests.
- note that you need compliance_markup in the fixtures file for
  these helpers to work.

SIMP-3430 #comment added simp-spec-helpers
Copy link
Member

@op-ct op-ct left a comment

Choose a reason for hiding this comment

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

Thanks for this patch--It's about time we returned to the the idea of centralizing our spec helper logic into a single gem.

Some concerns:

  • A monolithic global_spec_helper method may prescribe too much common functionality without providing individual modules' hooks to alter it (for instance, the current implementation makes default_hiera_config the only possible hiera config).
  • Quite a few line-item comments address things that are probably copypasta residue, like really old spec helper practices (like, last relevant in 2015 old) and updates to Hiera 5.
  • Now that we've centralized all this logic, the gem should probably have spec tests for it.
  • We'll need to take care that it doesn't introduce circular gem dependencies, though (IIRC, our previous attempt would have).

rvm:
- 2.4.5
env:
- SIMP_SKIP_NON_SIMPOS_TESTS=1
Copy link
Member

Choose a reason for hiding this comment

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

Is SIMP_SKIP_NON_SIMPOS_TESTS used by anything? It's not referenced in any other code in the repository.

}

c.mock_framework = :rspec
c.mock_with :mocha
Copy link
Member

Choose a reason for hiding this comment

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

Mock with :rspec, not :mocha.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

most of them mok with mocha. You can overwrite it in the spec_helpers_local (example in README.) When we have moved most of our stuff over, we can change the default to rspec.

Copy link
Member

Choose a reason for hiding this comment

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

Most of our modules are configured for mocha as a matter of copy/pasta, but they don't actually mock anything—they run just as fine when configured for :rspec (I just tested this on a simp-core + rake deps:checkout, setting up a big bash loop over the simp- modules to make the changes to spec/spec_helper.rb and running spec tests for each one).

My concern is that there are problems with mocking in mocha1 compared to rspec-mocks, and most of our modules aren't very invested yet. So I'd flip it around—we should encourage :rspec by default, and allow the modules who really can't and overwrite the spec_helpers_local for the modules that just can't switch just yet.

EOM

if not File.directory?(File.join(fixture_path,'hieradata')) then
FileUtils.mkdir_p(File.join(fixture_path,'hieradata'))
Copy link
Member

Choose a reason for hiding this comment

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

This looks like legacy logic that should go away

  • nothing bad happens when a Hiera 5 datadir path doesn't exist.
  • hieradata/ is a Hiera ≤4 naming convention.

end

if not File.directory?(File.join(fixture_path,'modules',module_name)) then
FileUtils.mkdir_p(File.join(fixture_path,'modules',module_name))
Copy link
Member

Choose a reason for hiding this comment

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

This mkdir_p seems unnecessary.

Puppet::Util::Log.newdestination(:console)
end

default_hiera_config =<<~EOM
Copy link
Member

Choose a reason for hiding this comment

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

We should probably expose a parameter that can override default_hiera_config (or just use fixtures/hiera.yaml if it already exists). Other wise, this is the only possible Hiera config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Put in a ticket for improvements. I was trying to centralize it so we could in the futre update from one place not optimize it to the nth degree. I took hat we had and centralized it so when we the latest ticket we could put in the changes to call this and then the next ticket would only require updates to this.

}
end

desc "Run spec tests"
Copy link
Member

Choose a reason for hiding this comment

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

There aren't any spec tests for this task to run.

gemspec: simp-spec-helpers.gemspec
gem: simp-spec-helpers
api_key:
secure: "need key"
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the reminder--I'll update this with a Travis variable in a later PR.

@@ -1,5 +1,5 @@
module Simp; end

module Simp::SpecHelpers
VERSION = '0.0.1'
VERSION = '0.0.2'
Copy link
Member

Choose a reason for hiding this comment

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

This patch adds new API functionality.

Suggested change
VERSION = '0.0.2'
VERSION = '0.1.0'

end

group :test do
gem 'rspec'
Copy link
Member

Choose a reason for hiding this comment

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

rspec is already included by the .gemspec file. Unless the Gemfile's gem statement refines a gemspec's gem (like how PUPPET_VERSION refines the puppet gem) there shouldn't be any redundant gems.



desc 'Ensure gemspec-safe permissions on all files'
task :chmod do
Copy link
Member

Choose a reason for hiding this comment

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

This task should be defined alongside pkg:gem

@jeannegreulich
Copy link
Contributor Author

I let Chris write his own update.

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

Successfully merging this pull request may close these issues.

2 participants