Permalink
Browse files

Gather features from node's cookbooks.

  • Loading branch information...
1 parent 42f7475 commit e7bc399e2c758f4998959cd8a4d5de37cae6927c @iafonov committed Mar 30, 2012
Showing with 63 additions and 7 deletions.
  1. +3 −3 README.md
  2. +44 −0 files/default/cucumber_handler.rb
  3. +16 −4 recipes/default.rb
View
@@ -20,8 +20,8 @@ Attributes
Usage
=====
1. Install this cookbook to your chef repo. (`git clone git://github.com/iafonov/simple_cuke.git cookbooks/simple_cuke`)
-2. Add `recipe[simple_cuke]` to run_list
-3. Start writing cucumber features and place them in `files/default/suite/features` folder
+2. Add `recipe[simple_cuke]` to `run_list`
+3. Start writing cucumber features and place them in `files/default/features` folders of cookbooks
4. Run `chef-client` and enjoy
How it works
@@ -106,7 +106,7 @@ How it works (in details)
=========================
The idea behind implementation is to be as simple and straightforward as possible. The workflow consists of the following three steps:
-1. Default recipe synchronizes the `files/default/suite` cookbook's folder with remote node via calling `remote_directory` LWRP.
+1. Default recipe synchronizes the `files/default/suite` folders of cookbooks with remote node via calling `remote_directory` LWRP.
2. [Chef handler](http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers) is registered.
3. When handler is executed it installs the bundle (it consists of cucumber & aruba) and runs cucumber features.
@@ -0,0 +1,44 @@
+class CucumberHandler < Chef::Handler
+ def initialize(options)
+ @suite_path = options[:suite_path]
+ @reporters_path = options[:reporters_path]
+ @excluded_roles = options[:all_roles] - options[:node_roles]
+ @reporter = load_reporter(options[:reporter] || :console)
+ end
+
+ def report
+ return if @reporter.nil?
+
+ install_bundle
+ result, report = run_tests
+
+ result ? @reporter.success(report) : @reporter.fail(report)
+ end
+
+private
+
+ def install_bundle
+ `cd #{@suite_path} && bundle install`
+ end
+
+ def run_tests
+ report = `cd #{@suite_path} && bundle exec cucumber --tags #{roles_tags}`
+ return $?.success?, report
+ end
+
+ def load_reporter(name)
+ require File.join(@reporters_path, "#{name}_reporter.rb")
+
+ Object.const_get("#{name.to_s.capitalize}Reporter").new
+ rescue LoadError
+ Chef::Log.error("Reporter file wasn't found in #{@reporters_path}")
+ nil
+ rescue NameError
+ Chef::Log.error("Reporter class definition is invalid")
+ nil
+ end
+
+ def roles_tags
+ @excluded_roles.map{|role| "~@#{role}"}.join(",")
+ end
+end
View
@@ -2,12 +2,12 @@
handler_path = node['chef_handler']['handler_path']
reporters_path = File.join(handler_path, "reporters")
-cookbook_file File.join(handler_path, "verify_handler.rb") do
- source "verify_handler.rb"
+cookbook_file File.join(handler_path, "cucumber_handler.rb") do
+ source "cucumber_handler.rb"
end.run_action(:create)
-chef_handler "VerifyHandler" do
- source File.join(handler_path, "verify_handler.rb")
+chef_handler "CucumberHandler" do
+ source File.join(handler_path, "cucumber_handler.rb")
action :enable
arguments :suite_path => suite_path,
:reporters_path => reporters_path,
@@ -26,4 +26,16 @@
source 'suite'
purge true
recursive true
+end
+
+# code borrowed from https://github.com/btm/minitest-handler-cookbook/blob/master/recipes/default.rb
+node[:recipes].each do |recipe|
+ cookbook_name = recipe.split('::').first
+ remote_directory "#{cookbook_name}" do
+ source "features"
+ cookbook cookbook_name
+ path "#{suite_path}/features/#{cookbook_name}"
+ purge true
+ ignore_failure true
+ end
end

0 comments on commit e7bc399

Please sign in to comment.