On Feb 26, 2011, at 6:28 AM, Jonas Genannt wrote: > Hello, > > I have added support to *not* generate the ri and rdoc on installation > of gem packages: > > https://github.com/hggh/puppet/commit/5eaf151897ec3e17c4c9b7d2a135ad346fcfc1bb > > But I have some problems to get the unit test working, I have used as > base the aptitude test. > > https://github.com/hggh/puppet/commit/e5c0422d36218b462a69a263b7de96db070cb3fb > > But then I run this test, I get the following error: > > unsatisfied expectations: > - expected exactly once, not yet invoked: > #<Puppet::Type::Package::ProviderGem:0xb7025eb0>.gem('list', '--local', > 'install', '--include-dependencies', '--no-ri', '--no-rdoc', 'foo') > > 1 tests, 2 assertions, 1 failures, 0 errors > > Can anybody help me, to create an good unit test? - so I can create an > feature request for this?
There are already some tests for gems in rspec: spec/unit/provider/package/gem_spec.rb I know you used existing tests as an example, but we've been moving away from that style of test - that is, those that test the transactional aspects. It's better to stick with something like (following rspec form): describe Puppet::Type.type(:package).provider(:gem) do before do @resource = Puppet::Type.type(:package).new :name => "foo" @provider = Puppet::Type.type(:package).provider(:gem).new(@resource) end it "should use --no-ri and --no-rdoc when docs are disabled" do @resource[:doc] = false @provider.expects(:gem).with(...) @provider.install end end The benefit of this is that you're only testing that installation behaves appropriately, not that 'install' is called correctly and such (which is really either a behavior at the transaction or the Package level). You should probably also have a test for the opposite behavior (those flags are left off when the docs are enabled), along with a test for the default value of 'doc'. -- Never try to tell everything you know. It may take too short a time. --Norman Ford --------------------------------------------------------------------- Luke Kanies -|- http://puppetlabs.com -|- +1(615)594-8199 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@googlegroups.com. To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.