user_spec.rb: check for availibility of doc for properties/params always pass

8 views
Skip to first unread message

Johan De Wit

unread,
Nov 22, 2013, 6:07:46 AM11/22/13
to puppe...@googlegroups.com
Hi,

I found this rspec check in above mentioned file, and would love to use
it in all my type/provider rspec's.

in the _rsepc.rb

properties = [:attributeoptions, :saslsecprops, :tlsverifyvlient,
:loglevel, :authzregexp]

properties.each do |property|
it "should have a #{property}property" do
described_class.attrclass(property).ancestors.should
be_include(Puppet::Property)
end

it "should have documentation for its #{property}property" do
described_class.attrclass(property).doc.should be_instance_of(String)
end
end

En in my <type>.rb

newproperty(:attributeoptions) do
end
newproperty(:saslsecprops) do
end
newproperty(:tlsverifyvlient) do
end
newproperty(:loglevel) do
end
newproperty(:authzregexp) do
end


I noticed the all tests passes, but the only the first should pass.

Looking at it with pry, i noticed the following :

[22] pry(#<Class>)> described_class.attrclass(:loglevel)
=> Puppet::Type::Ldapconfig::Loglevel
[23] pry(#<Class>)> described_class.attrclass(:loglevel)
=> Puppet::Type::Ldapconfig::Loglevel
[24] pry(#<Class>)> described_class.attrclass(:loglevel).doc
=> ""
[25] pry(#<Class>)> described_class.attrclass(:configdir).doc
=> "The (absolete) path of the directory where the dynamic configuration
files reside"
[26] pry(#<Class>)> described_class.attrclass(:loglevel).doc.class
=> String

As you can see, even if no desc is defined in the newproperty block, the
test will always pass.

changing the code to

it "should have documentation for its #{property} property" do
described_class.attrclass(property).doc.strip.should_not == ""
end

gives the expected behaviour.

Here is my environment : :
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-linux]
puppet 3.3.2 (community)


some relevant gems (i think)

rspec (2.14.1, 2.13.0, 2.8.0)
rspec-core (2.14.5, 2.13.1, 2.8.0)
rspec-expectations (2.14.1, 2.13.0, 2.8.0)
rspec-mocks (2.14.3, 2.13.1, 2.8.0)
rspec-puppet (0.1.6)
rspec-system (2.2.0)
rspec-system-puppet (2.1.0)
rspec-system-serverspec (1.0.1)
serverspec (0.10.9)

puppet (3.2.3)
puppet-lint (0.3.2)
puppetlabs_spec_helper (0.4.1)

Patch attached for
https://github.com/puppetlabs/puppet/blob/master/spec/unit/type/user_spec.rb

Grts

Johan

--
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer (805008667232363)
Puppet Certified Professional 2013 (PCP0000006)
_________________________________________________________

Open-Future Phone +32 (0)2/255 70 70
Zavelstraat 72 Fax +32 (0)2/255 70 71
3071 KORTENBERG Mobile +32 (0)474/42 40 73
BELGIUM http://www.open-future.be
_________________________________________________________



Next Events:
Puppet Advanced Training | https://www.open-future.be/puppet-advanced-training-12-till-14th-november
Zabbix Certified Training | http://www.open-future.be/zabbix-certified-training-18-till-20th-november
Zabbix Large Environments Training | http://www.open-future.be/zabbix-large-environments-training-21-till-22nd-november
Puppet Fundamentals Training | http://www.open-future.be/puppet-fundamentals-training-10-till-12th-december
Subscribe to our newsletter | http://eepurl.com/BUG8H
user_spec.rb.patch
Reply all
Reply to author
Forward
0 new messages