auxesis-cucumber-nagios 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Lindsay Holmwood
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ Dependencies
2
+ ============
3
+
4
+ - ruby1.8
5
+ - rake
6
+ - rubygems
7
+
8
+
9
+ Setting up
10
+ ==========
11
+
12
+ To install dependencies, run:
13
+
14
+ rake deps
15
+
16
+
17
+ Writing Features
18
+ ================
19
+
20
+ I suggest you put your features under under features/$fqdn/$name.feature.
21
+
22
+ You'll want to have a read of the Cucumber documentation, however
23
+ your tests will look something like this:
24
+
25
+ Feature: google.com.au
26
+ It should be up
27
+ And I should be able to search for things
28
+
29
+ Scenario: Searching for things
30
+ Given I visit "http://www.google.com"
31
+ When I fill in "q" with "wikipedia"
32
+ And I press "Google Search"
33
+ Then I should see "www.wikipedia.org"
34
+
35
+ There's a collection of steps that will cover most of the things you'll be
36
+ testing for in features/steps/webrat_steps.rb.
37
+
38
+ You can write custom steps for testing specific output and behaviour, e.g.
39
+ in features/smh.com.au/smh.feature:
40
+
41
+ Feature: smh.com.au
42
+ It should be up
43
+ And provide links to content
44
+
45
+ Scenario: Visiting home page
46
+ When I go to http://smh.com.au/
47
+ Then I should see site navigation
48
+ And there should be a section named "Opinion"
49
+
50
+ There aren't steps for "Then I should see site navigation", so you have to
51
+ write one yourself. :-) In features/smh.com.au/steps/smh_steps.rb:
52
+
53
+ Then /^I should see site navigation$/ do
54
+ doc = Nokogiri::HTML(response.body.to_s)
55
+ doc.css("ul#nav li a").size.should > 5
56
+ end
57
+
58
+ You can use Nokogiri for testing responses with XPath matchers and CSS
59
+ selectors.
60
+
61
+ I suggest you use bin/cucumber directly so you can get better feedback when
62
+ writing your tests:
63
+
64
+ bin/cucumber --require bin/common.rb \
65
+ --require features/
66
+ features/smh/smh.feature
67
+
68
+
69
+ Running
70
+ =======
71
+
72
+ Invoke the cucumber feature with the cucumber-nagios script:
73
+
74
+ bin/cucumber-nagios features/myblog.feature
75
+
76
+ cucumber-nagios can be run from anywhere:
77
+
78
+ /path/to/bin/cucumber-nagios /path/to/features/smh/smh.feature
79
+
80
+ It should return a standard Nagios-formatted response string:
81
+
82
+ Critical: 0, Warning: 0, 2 okay | value=2.000000;;;;
83
+
84
+ Steps that fail will show up in the "Critical" total, and steps that pass
85
+ show up in the "okay" total.
86
+
87
+ The value printed at the end is a total of the steps completed minus the
88
+ failing steps:
89
+
90
+ Critical: 1, Warning: 0, 2 okay | value=2.000000;;;;
91
+
92
+
93
+ Caveats
94
+ =======
95
+
96
+ You may want to think about keeping to one scenario to a file, otherwise
97
+ you'll get multiple lines of output for a test:
98
+
99
+ Critical: 1, Warning: 0, 2 okay | value=2.000000;;;;
100
+ Critical: 1, Warning: 0, 4 okay | value=4.000000;;;;
101
+
102
+ I assume Nagios will only read the last line, so this might be an ok behaviour
103
+ when you want to test for an aggregate of failures across a site.
104
+
105
+
106
+
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bin/common'
5
+ Gem.clear_paths
6
+ Gem.path.unshift(File.join(File.dirname(__FILE__), 'gems'))
7
+
8
+ begin
9
+ require 'cucumber/rake/task'
10
+
11
+ Cucumber::Rake::Task.new do |t|
12
+ t.binary = "bin/cucumber"
13
+ t.cucumber_opts = "--require bin/common.rb --format Nagios::NagiosFormatter"
14
+ end
15
+ rescue LoadError
16
+ end
17
+
18
+
19
+ desc "freeze deps"
20
+ task :deps do
21
+ deps = ['cucumber', 'webrat', 'mechanize']
22
+ deps.each do |dep|
23
+ puts "installing #{dep}"
24
+ system("gem install #{dep} -i gems --no-rdoc --no-ri")
25
+ end
26
+ end
data/bin/common.rb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ Gem.clear_paths
6
+ Gem.path << File.expand_path(File.join(File.dirname(__FILE__), '..', 'gems'))
7
+
data/bin/cucumber ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # Add '.rb' to work around a bug in IronRuby's File#dirname
3
+ $:.unshift(File.dirname(__FILE__ + '.rb') + '/../lib') unless $:.include?(File.dirname(__FILE__ + '.rb') + '/../lib')
4
+
5
+ begin
6
+ require 'common'
7
+ rescue LoadError
8
+ require 'bin/common'
9
+ end
10
+
11
+ require 'cucumber/cli'
12
+ Cucumber::CLI.execute(ARGV)
@@ -0,0 +1,26 @@
1
+ #!/bin/sh
2
+
3
+ if [ "$#" != "1" ]; then
4
+ echo "Usage: $0 <feature>"
5
+ exit 99
6
+ fi
7
+
8
+ dirname=$(dirname $0)
9
+ feature=$1
10
+
11
+ if [ ! -e "$feature" ]; then
12
+ echo "Error: feature file doesn't exist!"
13
+ exit 98
14
+ fi
15
+
16
+ $dirname/cucumber --require $dirname/common.rb \
17
+ --require features/ \
18
+ --format Nagios::NagiosFormatter \
19
+ $feature
20
+ retval=$?
21
+
22
+ if [ "$retval" -eq "1" ]; then
23
+ exit 2
24
+ else
25
+ exit $retval
26
+ fi
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'templater'
5
+
6
+ module CucumberNagiosGenerators
7
+
8
+ extend Templater::Manifold
9
+
10
+ class ProjectGenerator < Templater::Generator
11
+ def self.source_root
12
+ File.join(File.dirname(__FILE__), '..', 'lib', 'generators', 'project')
13
+ end
14
+
15
+ def destination_root
16
+ # takes :name from first_argument
17
+ File.join(@destination_root, name)
18
+ end
19
+
20
+ desc "Generate a new self-contained cucumber-nagios project."
21
+ first_argument :name, :required => true, :desc => "Project name"
22
+
23
+ file '.gitignore', '.gitignore'
24
+ file '.bzrignore', '.bzrignore'
25
+ glob!
26
+
27
+ end
28
+
29
+ desc "Generate a cucumber-nagios project."
30
+ add :project, ProjectGenerator
31
+
32
+ end
33
+
34
+
35
+ CucumberNagiosGenerators.run_cli Dir.pwd, 'cucumber-nagios-gen', '0.1', ARGV
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'cucumber-nagios'
3
+ s.version = '0.2'
4
+ s.date = '2009-03-04'
5
+
6
+ s.summary = "web app testing plugin for Nagios using Cucumber/Webrat/Mechanize"
7
+ s.description = "cucumber-nagios lets you write high-level behavioural tests for your web applications that can be plugged into Nagios"
8
+
9
+ s.authors = ['Lindsay Holmwood']
10
+ s.email = 'lindsay@holmwood.id.au'
11
+ s.homepage = 'http://holmwood.id.au/~lindsay/2009/02/23/web-app-integration-testing-for-sysadmins-with-cucumber-nagios/'
12
+ s.has_rdoc = false
13
+
14
+ s.add_dependency('templater', '>= 0.5')
15
+
16
+ s.files = %w(bin/common.rb bin/cucumber bin/cucumber-nagios bin/cucumber-nagios-gen cucumber-nagios.gemspec lib/generators/project/Rakefile lib/generators/project/features lib/generators/project/features/steps lib/generators/project/features/steps/result_steps.rb lib/generators/project/features/steps/webrat_steps.rb lib/generators/project/features/support lib/generators/project/features/support/env.rb lib/generators/project/features/support/nagios.rb lib/generators/project/bin lib/generators/project/bin/common.rb lib/generators/project/bin/cucumber lib/generators/project/bin/cucumber-nagios lib/generators/project/bin/cucumber-nagios-gen lib/generators/project/.bzrignore lib/generators/project/.gitignore lib/generators/project/README LICENSE README.md Rakefile)
17
+ end
18
+
19
+
@@ -0,0 +1,8 @@
1
+ .DS_Store
2
+ *~
3
+ .#*
4
+ .bzr
5
+ .bzrignore
6
+ gems/specifications/*
7
+ gems/gems/*
8
+ gems/bin/*
@@ -0,0 +1,45 @@
1
+ THINGS YOU SHOULD DO
2
+ ====================
3
+
4
+ 1. freeze your project
5
+ 2. version control your project
6
+
7
+
8
+ Freezing
9
+ ========
10
+
11
+ Freezing your dependencies allows you to drop your cucumber-nagios project to
12
+ any machine and have it run. Its only requirement is Ruby and Rake.
13
+
14
+ To freeze your project, run:
15
+
16
+ $ rake deps
17
+
18
+
19
+ Redeploying
20
+ ===========
21
+
22
+ Just run the freezer again:
23
+
24
+ $ rake deps
25
+
26
+
27
+ Version control
28
+ ===============
29
+
30
+ I highly recommend storing your cucumber-nagios features in a version control
31
+ system.
32
+
33
+ To get up and running with git:
34
+
35
+ $ git init
36
+ $ git add .
37
+ $ git commit -m 'created cucumber-nagios project'
38
+
39
+ To get up and running with bzr:
40
+
41
+ $ bzr init
42
+ $ bzr add
43
+ $ bzr commit -m 'created cucumber-nagios project'
44
+
45
+ .bzrignore and .gitignores are created when you generate your project.
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bin/common'
5
+ Gem.clear_paths
6
+ Gem.path.unshift(File.join(File.dirname(__FILE__), 'gems'))
7
+
8
+ begin
9
+ require 'cucumber/rake/task'
10
+
11
+ Cucumber::Rake::Task.new do |t|
12
+ t.binary = "bin/cucumber"
13
+ t.cucumber_opts = "--require bin/common.rb --format Nagios::NagiosFormatter"
14
+ end
15
+ rescue LoadError
16
+ end
17
+
18
+
19
+ desc "freeze deps"
20
+ task :deps do
21
+ deps = ['cucumber', 'webrat', 'mechanize']
22
+ deps.each do |dep|
23
+ puts "installing #{dep}"
24
+ system("gem install #{dep} -i gems --no-rdoc --no-ri")
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ Gem.clear_paths
6
+ Gem.path << File.expand_path(File.join(File.dirname(__FILE__), '..', 'gems'))
7
+
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # Add '.rb' to work around a bug in IronRuby's File#dirname
3
+ $:.unshift(File.dirname(__FILE__ + '.rb') + '/../lib') unless $:.include?(File.dirname(__FILE__ + '.rb') + '/../lib')
4
+
5
+ begin
6
+ require 'common'
7
+ rescue LoadError
8
+ require 'bin/common'
9
+ end
10
+
11
+ require 'cucumber/cli'
12
+ Cucumber::CLI.execute(ARGV)
@@ -0,0 +1,26 @@
1
+ #!/bin/sh
2
+
3
+ if [ "$#" != "1" ]; then
4
+ echo "Usage: $0 <feature>"
5
+ exit 99
6
+ fi
7
+
8
+ dirname=$(dirname $0)
9
+ feature=$1
10
+
11
+ if [ ! -e "$feature" ]; then
12
+ echo "Error: feature file doesn't exist!"
13
+ exit 98
14
+ fi
15
+
16
+ $dirname/cucumber --require $dirname/common.rb \
17
+ --require features/ \
18
+ --format Nagios::NagiosFormatter \
19
+ $feature
20
+ retval=$?
21
+
22
+ if [ "$retval" -eq "1" ]; then
23
+ exit 2
24
+ else
25
+ exit $retval
26
+ fi
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'templater'
5
+
6
+ module CucumberNagiosGenerators
7
+
8
+ extend Templater::Manifold
9
+
10
+ class ProjectGenerator < Templater::Generator
11
+ def self.source_root
12
+ File.join(File.dirname(__FILE__), '..', 'lib', 'generators', 'project')
13
+ end
14
+
15
+ def destination_root
16
+ # takes :name from first_argument
17
+ File.join(@destination_root, name)
18
+ end
19
+
20
+ desc "Generate a new self-contained cucumber-nagios project."
21
+ first_argument :name, :required => true, :desc => "Project name"
22
+
23
+ glob!
24
+ #file :rakefile, 'Rakefile'
25
+
26
+ end
27
+
28
+ desc "Generate a cucumber-nagios project."
29
+ add :project, ProjectGenerator
30
+
31
+ end
32
+
33
+
34
+ CucumberNagiosGenerators.run_cli Dir.pwd, 'cucumber-nagios-gen', '0.1', ARGV
@@ -0,0 +1,15 @@
1
+ Then /^I should see "(.*)"$/ do |text|
2
+ response.body.to_s.should =~ /#{text}/m
3
+ end
4
+
5
+ Then /^I should not see "(.*)"$/ do |text|
6
+ response.body.to_s.should_not =~ /#{text}/m
7
+ end
8
+
9
+ Then /^I should see an? (\w+) message$/ do |message_type|
10
+ response.should have_xpath("//*[@class='#{message_type}']")
11
+ end
12
+
13
+ Then /^the (.*) ?request should fail/ do |_|
14
+ response.should_not be_successful
15
+ end
@@ -0,0 +1,36 @@
1
+ When /^I go to (.*)$/ do |path|
2
+ visit path
3
+ end
4
+
5
+ When /^I press "(.*)"$/ do |button|
6
+ click_button(button)
7
+ end
8
+
9
+ When /^I follow "(.*)"$/ do |link|
10
+ click_link(link)
11
+ end
12
+
13
+ When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
14
+ fill_in(field, :with => value)
15
+ end
16
+
17
+ When /^I select "(.*)" from "(.*)"$/ do |value, field|
18
+ select(value, :from => field)
19
+ end
20
+
21
+ When /^I check "(.*)"$/ do |field|
22
+ check(field)
23
+ end
24
+
25
+ When /^I uncheck "(.*)"$/ do |field|
26
+ uncheck(field)
27
+ end
28
+
29
+ When /^I choose "(.*)"$/ do |field|
30
+ choose(field)
31
+ end
32
+
33
+ When /^I attach the file at "(.*)" to "(.*)" $/ do |path, field|
34
+ attach_file(field, path)
35
+ end
36
+
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'webrat'
5
+ require 'webrat/mechanize'
6
+
7
+ class MechanizeWorld < Webrat::MechanizeSession
8
+ require 'spec'
9
+ include Spec::Matchers
10
+ end
11
+
12
+ World do
13
+ MechanizeWorld.new
14
+ end
15
+
16
+ def response
17
+ webrat_session.response
18
+ end
19
+
20
+
@@ -0,0 +1,32 @@
1
+ # features/support/nagios.rb
2
+ require 'rubygems'
3
+
4
+ module Nagios
5
+ class NagiosFormatter
6
+ def initialize(io, step_mother, options={})
7
+ @failed = []
8
+ @passed = []
9
+ end
10
+
11
+ def step_passed(step, name, params)
12
+ @passed << step
13
+ end
14
+
15
+ def step_failed(step, name, params)
16
+ @failed << step
17
+ end
18
+
19
+ def scenario_executed(scenario)
20
+ @total = @failed.size + @passed.size
21
+ message = ""
22
+ message += "Critical: #{@failed.size}, "
23
+ message += "Warning: 0, "
24
+ message += "#{@passed.size} okay"
25
+ # nagios performance data
26
+ message += " | passed=#{@passed.size}"
27
+ message += ", failed=#{@failed.size}, total=#{@total}"
28
+ puts message
29
+ end
30
+ end
31
+ end
32
+
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auxesis-cucumber-nagios
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.2"
5
+ platform: ruby
6
+ authors:
7
+ - Lindsay Holmwood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-04 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: templater
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.5"
24
+ version:
25
+ description: cucumber-nagios lets you write high-level behavioural tests for your web applications that can be plugged into Nagios
26
+ email: lindsay@holmwood.id.au
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - bin/common.rb
35
+ - bin/cucumber
36
+ - bin/cucumber-nagios
37
+ - bin/cucumber-nagios-gen
38
+ - cucumber-nagios.gemspec
39
+ - lib/generators/project/Rakefile
40
+ - lib/generators/project/features
41
+ - lib/generators/project/features/steps
42
+ - lib/generators/project/features/steps/result_steps.rb
43
+ - lib/generators/project/features/steps/webrat_steps.rb
44
+ - lib/generators/project/features/support
45
+ - lib/generators/project/features/support/env.rb
46
+ - lib/generators/project/features/support/nagios.rb
47
+ - lib/generators/project/bin
48
+ - lib/generators/project/bin/common.rb
49
+ - lib/generators/project/bin/cucumber
50
+ - lib/generators/project/bin/cucumber-nagios
51
+ - lib/generators/project/bin/cucumber-nagios-gen
52
+ - lib/generators/project/.bzrignore
53
+ - lib/generators/project/.gitignore
54
+ - lib/generators/project/README
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ has_rdoc: false
59
+ homepage: http://holmwood.id.au/~lindsay/2009/02/23/web-app-integration-testing-for-sysadmins-with-cucumber-nagios/
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.2.0
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: web app testing plugin for Nagios using Cucumber/Webrat/Mechanize
84
+ test_files: []
85
+