-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jhoblitt/check_rspec
Check rspec
- Loading branch information
Showing
10 changed files
with
208 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ Gemfile.lock | |
*.orig | ||
*.rej | ||
*.patch | ||
tmp/aruba/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ rvm: | |
- 1.9.2 | ||
- 1.9.3 | ||
- 2.0.0 | ||
script: "rake spec features" | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'optparse' | ||
require 'open3' | ||
require 'timeout' | ||
|
||
EXIT_CRITICAL = 2 | ||
|
||
options = { :timeout => 30.0 } | ||
option_parser = OptionParser.new do |opts| | ||
opts.banner = "Usage: check_rspec [options] [--] [passed to rspec]" | ||
opts.separator "" | ||
opts.separator "Specific options:" | ||
|
||
opts.on("-t", "--timeout TIMEOUT", "default: 30.0 (seconds)", Float) do |t| | ||
options[:timeout] = t | ||
end | ||
|
||
opts.on_tail("-h", "--help", "Show this message") do | ||
puts opts | ||
exit | ||
end | ||
end | ||
|
||
option_parser.parse! | ||
|
||
cmd = ['rspec', '--format', 'RSpec::Nagios::Formatter', ARGV] | ||
cmd_stdout, cmd_stderr, cmd_status = nil | ||
|
||
begin | ||
Timeout::timeout(options[:timeout]) { | ||
cmd_stdout, cmd_stderr, cmd_status = Open3.capture3(cmd.join(' ')) | ||
} | ||
rescue Timeout::Error | ||
puts "RSPEC Critical - timeout after #{options[:timeout]} seconds" | ||
exit EXIT_CRITICAL | ||
end | ||
|
||
puts cmd_stdout | ||
unless cmd_status.exitstatus == 0 | ||
exit EXIT_CRITICAL | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
Feature: command line options | ||
In order to modifiy the behavior of check_rspec | ||
As an Icinga administrator | ||
I want to be able to set command line options | ||
|
||
Scenario: run a passing rspec test | ||
Given a file named "trivial_spec.rb" with: | ||
""" | ||
describe do | ||
it { true.should == true } | ||
end | ||
""" | ||
When I successfully run `check_rspec trivial_spec.rb` | ||
Then the stdout should contain: | ||
""" | ||
RSPEC OK | ||
""" | ||
|
||
Scenario: run a failing rspec test | ||
Given a file named "trivial_spec.rb" with: | ||
""" | ||
describe do | ||
it { true.should == false } | ||
end | ||
""" | ||
When I run `check_rspec trivial_spec.rb` | ||
Then the exit status should be 2 | ||
And the stdout should contain: | ||
""" | ||
RSPEC Critical | ||
""" | ||
|
||
Scenario: run a test with --timeout | ||
Given a file named "trivial_spec.rb" with: | ||
""" | ||
describe do | ||
it { true.should == true } | ||
end | ||
""" | ||
When I successfully run `check_rspec --timeout 1 trivial_spec.rb` | ||
Then the stdout should contain: | ||
""" | ||
RSPEC OK | ||
""" | ||
|
||
Scenario: run a test with --timeout that times out | ||
Given a file named "trivial_spec.rb" with: | ||
""" | ||
describe do | ||
it { sleep(1) } | ||
end | ||
""" | ||
When I run `check_rspec --timeout 0.5 trivial_spec.rb` | ||
Then the exit status should be 2 | ||
And the stdout should contain: | ||
""" | ||
RSPEC Critical - timeout after 0.5 seconds | ||
""" | ||
|
||
Scenario: view usage with -h | ||
When I successfully run `check_rspec -h` | ||
And the stdout should contain: | ||
""" | ||
Usage: check_rspec [options] [--] [passed to rspec] | ||
Specific options: | ||
-t, --timeout TIMEOUT default: 30.0 (seconds) | ||
-h, --help Show this message | ||
""" | ||
|
||
Scenario: view usage with --help | ||
When I successfully run `check_rspec --help` | ||
And the stdout should contain: | ||
""" | ||
Usage: check_rspec [options] [--] [passed to rspec] | ||
Specific options: | ||
-t, --timeout TIMEOUT default: 30.0 (seconds) | ||
-h, --help Show this message | ||
""" | ||
|
||
Scenario: pass options to rspec | ||
Given a file named "trivial_spec.rb" with: | ||
""" | ||
describe 'foo' do | ||
it { true.should == true } | ||
end | ||
describe 'bar' do | ||
it { true.should == true } | ||
end | ||
""" | ||
When I successfully run `check_rspec -- -e 'foo' trivial_spec.rb` | ||
Then the stdout should contain: | ||
""" | ||
RSPEC OK - 1 example | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Feature: run rspec tests | ||
In order to monitor the enviroment | ||
As an Icinga administrator | ||
I want to get RSpec test results in Icinga plugin format | ||
|
||
Scenario: run a passing rspec test | ||
Given a file named "trivial_spec.rb" with: | ||
""" | ||
describe do | ||
it { true.should == true } | ||
end | ||
""" | ||
When I successfully run `check_rspec trivial_spec.rb` | ||
Then it should pass with regexp: | ||
""" | ||
^RSPEC OK - 1 example, 0 failures, finished in 0.\d+ seconds | examples=1 passing=1 failures=0 pending=0 conformance=100% time=0.\d+s$ | ||
""" | ||
|
||
Scenario: run a failing rspec test | ||
Given a file named "trivial_spec.rb" with: | ||
""" | ||
describe do | ||
it { true.should == false } | ||
end | ||
""" | ||
When I run `check_rspec trivial_spec.rb` | ||
Then the exit status should be 2 | ||
And it should fail with regexp: | ||
""" | ||
^RSPEC Critical - 1 example, 1 failures, finished in 0.\d+ seconds | examples=1 passing=0 failures=1 pending=0 conformance=0% time=0.\d+s$ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'aruba/cucumber' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters