Cucumber Changes And Conventions

Devan Goodwin dgoodwin at rm-rf.ca
Thu May 13 14:56:53 UTC 2010


- There is now a test config file you can use to point cucumber tests
against any host you like. Copy proxy/features/cucumber.conf.example
to proxy/features/cucumber.conf and edit accordingly. No config file =
default settings, localhost, 8443, admin/admin.

- @candlepin is now semi-immutable and for super admin credentials.
Now that we have live auth it's problematic to have tests
re-initializing it with different credentials as it's an instance
variable and a later When/Then or After block may try to use it
expecting it to be initialized for a super admin.

- Use the following to create an owner admin and login:

Given /^an owner admin "([^\"]*)"$/ do |username|
    @username = username
    @password = 'password'
    @candlepin.create_user(@test_owner['id'], @username, @password)
end

Given /^I am logged in as "([^\"]*)"$/ do |username|
    @owner_admin_cp = connect(username=username, password="password")
end

- Similarly to create a consumer and login:

When /I register a consumer "(\w+)"$/ do |consumer_name|
    consumer = {
        :consumer => {
            :type => {:label => :system},
            :name => consumer_name,
        }
    }
    register_consumer(consumer)
end

Given /^I am logged in as consumer "([^\"]*)"$/ do |consumer_name|
    @current_consumer_cp = @consumers[consumer_name]
end

- There's a few instance variables in play here:

@current_consumer_cp - Authenticated CP connection for last consumer
you logged in as.

@consumers - Hash of all authenticated CP connections for consumers
you've created, indexed by the consumer name you specify in your text.
(some tests need more than one consumer connection)

@current_owner_cp - Authenticated CP connection for last user you
logged in as. (aka owner admin)


- There is now a test owner created for each scenario in a Before
block, and deleted in an After. The delete will take care of cleaning
out any entitlements, pools, and consumers that were created within
that org. If you create any other orgs in your tests you should
remember to clean these up as well. In general try to use the test org
available as @test_owner whenever possible and this should mostly be
taken care of for you.

Some conventions:

- We're randomly capitalizing words in the features. This looks
strange and is confusing when you go to try and re-use an existing
regexp and you have no idea what capitalization might be in effect, so
it's near impossible to memorize. I propose we capitalize the first
words (Given And When Then) and do the rest lowercase.

- We should organize the _steps.rb files by domain subject matter, not
link them one to one with the features. Justin found this link:
http://wiki.github.com/aslakhellesoy/cucumber/feature-coupled-steps-antipattern
This should help us know where to look for things to re-use.

- As jbowes proposed I think we should probably try to:
  - Wrap vars in quotes in the regexes.
  - Not regex out words that aren't variables.
  - Try to have the regexps call reusable code methods. I'm not sure
how to organize where they live, I guess in the domain subject's
_steps.rb with the regexps?

Other ideas for organizing / cleanup?

Cheers,

Devan

-- 
Devan Goodwin <dgoodwin at rm-rf.ca>
http://rm-rf.ca



More information about the candlepin mailing list