Skip to content

(MODULES-1882) convert function tests to rspec-puppet #464

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

Merged
merged 8 commits into from
Jun 1, 2015

Conversation

DavidS
Copy link
Contributor

@DavidS DavidS commented May 29, 2015

This PR contains a big set of changes to convert most of the unit tests to use plain rspec-puppet. The commits are ordered so that every single commit should pass the specs and the easy changes are up front.

Should the conversion generate more discussion, I'd split out everything up to and including "spec_helper: implement an easy way for specs to confine to puppet version" into a separate PR to get the easy fixes squared away and reduce the amount of stuff I need to carry forward locally. Please consider that when reviewing, and try to keep comments for those two parts a bit separate.

The current master has ~900 examples, while this branch contains ~1750 examples, and 70 pending.

@puppet-community-ci
Copy link

The result of the test was: PASS
Details at http://planck.nibalizer.com/buildlogs/puppetlabs+puppetlabs-stdlib+464+1432919317+PASS

I am a beta ci bot. I am probably lying to you.
You can contact nibalizer for more details.

@daenney
Copy link

daenney commented May 29, 2015

👏 👏 👏

So that bot totally lies. A few tests failed 😄.

scope = PuppetlabsSpec::PuppetInternals.scope
scope.stubs(:[]).with("::fqdn").returns(host)
scope.stubs(:lookupvar).with("::fqdn").returns(host)
scope.stubs(:lookupvar).with("::fqdn", {}).returns(host)
Copy link
Contributor

Choose a reason for hiding this comment

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

should this, for consistency, be handled with let(:facts) {{ :fqdn => host }}, or is that not possible here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you look at the tests, you'll see that the tests compare the output from different hosts. This precludes using the let(:facts) thingy. I've added a comment and unstub it too.

@nibalizer
Copy link
Contributor

@daenney from a CI perspective it did pass:

Finished in 13 minutes 52 seconds (files took 1 minute 26.79 seconds to load)
�[33m446 examples, 0 failures, 197 pending�[0m

I think there are a lot of tests that are defered or not yet implemented but exist.

require 'puppetlabs_spec_helper_clone'

# hack to enable all the expect syntax (like allow_any_instance_of) in rspec-puppet examples
RSpec::Mocks::Syntax.enable_expect(RSpec::Puppet::ManifestMatchers)
Copy link
Contributor

Choose a reason for hiding this comment

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

will this hack go away?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. This is tracked at rodjek/rspec-puppet#298

@igalic
Copy link
Contributor

igalic commented May 29, 2015

thank you very much, 💯 x 👍 !

@puppet-community-ci
Copy link

The result of the test was: PASS
Details at http://ci.puppet.community/buildlogs/puppetlabs+puppetlabs-stdlib+464+1432994019+PASS

I am a beta ci bot. I am probably lying to you.
You can contact nibalizer for more details.

@daenney
Copy link

daenney commented May 31, 2015

@nibalizer Oh that's curious, I saw a couple of stack traces in that run and in the last run, specifically this one:

  194) values_at function success returns a specific negative index value
�[0m�[36m     # negative numbers don't work
�[0m     �[33mFailure/Error: expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["e"\]/)�[0m
     �[33mBeaker::Host::CommandFailure:�[0m
     �[33m  Host 'ubuntu-server-14041-x64' exited with 1 running:�[0m
     �[33m   puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest.pp.Tv9wP8�[0m
     �[33m  Last 10 lines of output were:�[0m
     �[33m      �[1;31mWarning: Setting templatedir is deprecated. See http://links.puppetlabs.com/env-settings-deprecations�[0m
     �[33m         (at /usr/lib/ruby/vendor_ruby/puppet/settings.rb:1134:in `issue_deprecation_warning')�[0m�[0m
     �[33m      �[0;32mInfo: Loading facts�[0m�[0m
     �[33m      �[1;31mError: values_at(): Unknown format of given index at /tmp/apply_manifest.pp.Tv9wP8:3 on node ubuntu�[0m�[0m
     �[33m      �[1;31mError: values_at(): Unknown format of given index at /tmp/apply_manifest.pp.Tv9wP8:3 on node ubuntu�[0m�[0m
     �[33m  �[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/beaker-2.7.1/lib/beaker/host.rb:378:in `exec'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/beaker-2.7.1/lib/beaker/dsl/helpers.rb:88:in `block in on'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/beaker-2.7.1/lib/beaker/shared/host_manager.rb:95:in `run_block_on'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/beaker-2.7.1/lib/beaker/dsl/patterns.rb:32:in `block_on'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/beaker-2.7.1/lib/beaker/dsl/helpers.rb:78:in `on'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/beaker-2.7.1/lib/beaker/dsl/helpers.rb:987:in `block in apply_manifest_on'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/beaker-2.7.1/lib/beaker/shared/host_manager.rb:95:in `run_block_on'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/beaker-2.7.1/lib/beaker/dsl/patterns.rb:32:in `block_on'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/beaker-2.7.1/lib/beaker/dsl/helpers.rb:916:in `apply_manifest_on'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/beaker-2.7.1/lib/beaker/dsl/helpers.rb:994:in `apply_manifest'�[0m
     �[36m# ./spec/acceptance/values_at_spec.rb:25:in `block (3 levels) in <top (required)>'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:177:in `instance_exec'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:177:in `block in run'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:385:in `block in with_around_and_singleton_context_hooks'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:343:in `block in with_around_example_hooks'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/hooks.rb:474:in `block in run'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/hooks.rb:612:in `run_around_example_hooks_for'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/hooks.rb:474:in `run'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:343:in `with_around_example_hooks'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:385:in `with_around_and_singleton_context_hooks'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:174:in `run'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example_group.rb:548:in `block in run_examples'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example_group.rb:544:in `map'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example_group.rb:544:in `run_examples'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example_group.rb:512:in `run'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example_group.rb:513:in `block in run'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example_group.rb:513:in `map'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/example_group.rb:513:in `run'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:110:in `block (3 levels) in run_specs'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:110:in `map'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:110:in `block (2 levels) in run_specs'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1526:in `with_suite_hooks'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:109:in `block in run_specs'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:62:in `report'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:108:in `run_specs'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:86:in `run'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:70:in `run'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:38:in `invoke'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/gems/rspec-core-3.2.2/exe/rspec:4:in `<top (required)>'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/bin/rspec:23:in `load'�[0m
     �[36m# /home/pcci/ruby_pcci_gempath/bin/rspec:23:in `<main>'�[0m
�[33m

That to me should've made the tests fail.

@igalic
Copy link
Contributor

igalic commented Jun 1, 2015

one of the things that really astonishes me is that i was actually able to read through this hole patchset…

@puppet-community-ci
Copy link

The result of the test was: PASS
Details at http://planck.nibalizer.com/buildlogs/puppetlabs+puppetlabs-stdlib+464+1433156545+PASS

I am a beta ci bot. I am probably lying to you.
You can contact nibalizer for more details.

DavidS added 6 commits June 1, 2015 12:21
The :validate task is already provided by
puppetlabs_spec_helper/rake_tasks and would check files twice.

The metadata.json linting is just good form.
…sion

Usage:

    describe 'puppet3 behaviour', :unless => RSpec.configuration.puppet_future do
    describe 'puppet4 behaviour', :if => RSpec.configuration.puppet_future do
@DavidS DavidS force-pushed the modules-1882-convert-to-rspec branch from d2d754a to 2f84350 Compare June 1, 2015 12:19
@DavidS
Copy link
Contributor Author

DavidS commented Jun 1, 2015

Rebased, fixed commit dates, fixed stuff @igalic noted.

@puppet-community-ci
Copy link

The result of the test was: PASS
Details at http://planck.nibalizer.com/buildlogs/puppetlabs+puppetlabs-stdlib+464+1433162267+PASS

I am a beta ci bot. I am probably lying to you.
You can contact nibalizer for more details.

Tests in the new style produces the following documentation output:

abs
  should not eq nil
  should run abs() and raise an Puppet::ParseError
  should run abs(-34) and return 34
  should run abs("-34") and return 34
  should run abs(34) and return 34
  should run abs("34") and return 34
This is copied and changed code from an older version of puppet's internal
test setup code. It does not work with puppet4.
@DavidS DavidS force-pushed the modules-1882-convert-to-rspec branch from 2f84350 to 18d4c21 Compare June 1, 2015 17:02
@puppet-community-ci
Copy link

The result of the test was: PASS
Details at http://planck.nibalizer.com/buildlogs/puppetlabs+puppetlabs-stdlib+464+1433179141+PASS

I am a beta ci bot. I am probably lying to you.
You can contact nibalizer for more details.

hunner added a commit that referenced this pull request Jun 1, 2015
(MODULES-1882) convert function tests to rspec-puppet
@hunner hunner merged commit a383705 into puppetlabs:master Jun 1, 2015
@DavidS DavidS deleted the modules-1882-convert-to-rspec branch June 1, 2015 21:00
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.

7 participants