-
Notifications
You must be signed in to change notification settings - Fork 5
(SIMP-3430) Create Centralized spec_helper.rb #2
Conversation
jeannegreulich
commented
Jan 24, 2020
- 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.
aa608a7
to
685d898
Compare
8c387b0
to
43691aa
Compare
- 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
43691aa
to
feb56d5
Compare
There was a problem hiding this 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 makesdefault_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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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')) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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.
VERSION = '0.0.2' | |
VERSION = '0.1.0' |
end | ||
|
||
group :test do | ||
gem 'rspec' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
I let Chris write his own update. |