Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Gather features from node's cookbooks.

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

0 comments on commit e7bc399

Please sign in to comment.
Something went wrong with that request. Please try again.