Browse files

Add cucumber feature, for demo-ing the formatter

  • Loading branch information...
1 parent 9ffdded commit 018199525e83ae08240c41b43c4350b79c0c1293 @pvdb committed Apr 12, 2012
Showing with 75 additions and 0 deletions.
  1. +4 −0 README.md
  2. +5 −0 Rakefile
  3. +1 −0 cucumber-pride.gemspec
  4. +17 −0 features/addition.feature
  5. +10 −0 features/division.feature
  6. +38 −0 features/step_definitions/calculator_steps.rb
View
4 README.md
@@ -26,6 +26,10 @@ Or install it yourself as:
$ gem install cucumber-pride
+## Tests
+
+The tests are a lie! They don't test cucumber-pride directly, they just produce enough output so that you can visually verify that everything is working. This was much faster than writing actual tests and works just as well in this case.
+
## Usage
TODO: Write usage instructions here
View
5 Rakefile
@@ -1,2 +1,7 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
+
+require 'cucumber/rake/task'
+Cucumber::Rake::Task.new do |t|
+ t.cucumber_opts = "--require lib --require features --format Cucumber::Pride::Formatter"
+end
View
1 cucumber-pride.gemspec
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
gem.version = Cucumber::Pride::VERSION
gem.add_dependency 'cucumber', ['~> 1.1.1']
+ gem.add_development_dependency 'rspec', ['~> 2.9.0']
end
View
17 features/addition.feature
@@ -0,0 +1,17 @@
+# language: en
+Feature: Addition
+ In order to avoid silly mistakes
+ As a math idiot
+ I want to be told the sum of two numbers
+
+ Scenario Outline: Add two numbers
+ Given I have entered <input_1> into the calculator
+ And I have entered <input_2> into the calculator
+ When I press <button>
+ Then the result should be <output> on the screen
+
+ Examples:
+ | input_1 | input_2 | button | output |
+ | 20 | 30 | add | 50 |
+ | 2 | 5 | add | 7 |
+ | 0 | 40 | add | 40 |
View
10 features/division.feature
@@ -0,0 +1,10 @@
+# language: en
+Feature: Division
+ In order to avoid silly mistakes
+ Cashiers must be able to calculate a fraction
+
+ Scenario: Regular numbers
+ * I have entered 3 into the calculator
+ * I have entered 2 into the calculator
+ * I press divide
+ * the result should be 1.5 on the screen
View
38 features/step_definitions/calculator_steps.rb
@@ -0,0 +1,38 @@
+# encoding: utf-8
+begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
+require 'cucumber/formatter/unicode'
+$:.unshift(File.dirname(__FILE__) + '/../../lib')
+
+class Calculator
+ def push(n)
+ @args ||= []
+ @args << n
+ end
+
+ def add
+ @args.inject(0){|n,sum| sum+=n}
+ end
+
+ def divide
+ @args[0].to_f / @args[1].to_f
+ end
+end
+
+Before do
+ @calc = Calculator.new
+end
+
+After do
+end
+
+Given /I have entered (\d+) into the calculator/ do |n|
+ @calc.push n.to_i
+end
+
+When /I press (\w+)/ do |op|
+ @result = @calc.send op
+end
+
+Then /the result should be (.*) on the screen/ do |result|
+ @result.should == result.to_f
+end

0 comments on commit 0181995

Please sign in to comment.