Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
Created August 24, 2011 19:06
Show Gist options
  • Save natritmeyer/1168893 to your computer and use it in GitHub Desktop.
Save natritmeyer/1168893 to your computer and use it in GitHub Desktop.
BDD example with WPF, cucumber, ironruby and bewildr; Part 1
C:\wpfbdd>icucumber
Feature: Sheep Counter
As a farmer
In order to prevent any straggling sheep from getting eaten by the big bad wolf
I want to be able to keep track of my sheep as they move from field to field
Scenario: Before I start moving my sheep # features\sheep_counter.feature:6
When I start up my sheep counter # features/step_definitions/sheep_counter_steps.rb:1
Can't find: c:\wpfbdd\SheepCounter\SheepCounter\bin\Debug\SheepCounter.exe (RuntimeError)
features\sheep_counter.feature:7:in `When I start up my sheep counter'
Then it tells me that no sheep have moved field yet # features/step_definitions/sheep_counter_steps.rb:7
Scenario: Move one sheep # features\sheep_counter.feature:10
Given I have started my sheep counter # features/step_definitions/sheep_counter_steps.rb:11
Can't find: c:\wpfbdd\SheepCounter\SheepCounter\bin\Debug\SheepCounter.exe (RuntimeError)
features\sheep_counter.feature:11:in `Given I have started my sheep counter'
When I move one sheep # features/step_definitions/sheep_counter_steps.rb:15
Then it tells me that 1 sheep has moved # features/step_definitions/sheep_counter_steps.rb:19
Scenario: Move two sheep # features\sheep_counter.feature:15
Given I have started my sheep counter # features/step_definitions/sheep_counter_steps.rb:11
Can't find: c:\wpfbdd\SheepCounter\SheepCounter\bin\Debug\SheepCounter.exe (RuntimeError)
features\sheep_counter.feature:16:in `Given I have started my sheep counter'
And I have moved 1 sheep already # features/step_definitions/sheep_counter_steps.rb:23
When I move another sheep # features/step_definitions/sheep_counter_steps.rb:29
Then it tells me that 2 sheep have moved # features/step_definitions/sheep_counter_steps.rb:19
Failing Scenarios:
cucumber features\sheep_counter.feature:6 # Scenario: Before I start moving my sheep
cucumber features\sheep_counter.feature:10 # Scenario: Move one sheep
cucumber features\sheep_counter.feature:15 # Scenario: Move two sheep
3 scenarios (3 failed)
9 steps (3 failed, 6 skipped)
0m0.451s
C:\wpfbdd>icucumber
Feature: Sheep Counter
As a farmer
In order to prevent any straggling sheep from getting eaten by the big bad wolf
I want to be able to keep track of my sheep as they move from field to field
Scenario: Before I start moving my sheep # features\sheep_counter.feature:6
When I start up my sheep counter # features/step_definitions/sheep_counter_steps.rb:1
Bewildr::ElementDoesntExist (Bewildr::ElementDoesntExist)
features\sheep_counter.feature:7:in `When I start up my sheep counter'
Then it tells me that no sheep have moved field yet # features/step_definitions/sheep_counter_steps.rb:7
Scenario: Move one sheep # features\sheep_counter.feature:10
Given I have started my sheep counter # features/step_definitions/sheep_counter_steps.rb:11
Bewildr::ElementDoesntExist (Bewildr::ElementDoesntExist)
features\sheep_counter.feature:11:in `Given I have started my sheep counter'
When I move one sheep # features/step_definitions/sheep_counter_steps.rb:15
Then it tells me that 1 sheep has moved # features/step_definitions/sheep_counter_steps.rb:19
Scenario: Move two sheep # features\sheep_counter.feature:15
Given I have started my sheep counter # features/step_definitions/sheep_counter_steps.rb:11
Bewildr::ElementDoesntExist (Bewildr::ElementDoesntExist)
features\sheep_counter.feature:16:in `Given I have started my sheep counter'
And I have moved 1 sheep already # features/step_definitions/sheep_counter_steps.rb:23
When I move another sheep # features/step_definitions/sheep_counter_steps.rb:29
Then it tells me that 2 sheep have moved # features/step_definitions/sheep_counter_steps.rb:19
Failing Scenarios:
cucumber features\sheep_counter.feature:6 # Scenario: Before I start moving my sheep
cucumber features\sheep_counter.feature:10 # Scenario: Move one sheep
cucumber features\sheep_counter.feature:15 # Scenario: Move two sheep
3 scenarios (3 failed)
9 steps (3 failed, 6 skipped)
1m31.462s
C:\wpfbdd>icucumber
Feature: Sheep Counter
As a farmer
In order to prevent any straggling sheep from getting eaten by the big bad wolf
I want to be able to keep track of my sheep as they move from field to field
Scenario: Before I start moving my sheep # features\sheep_counter.feature:6
When I start up my sheep counter # features/step_definitions/sheep_counter_steps.rb:1
Then it tells me that no sheep have moved field yet # features/step_definitions/sheep_counter_steps.rb:7
undefined method `text' for #<Bewildr::Element:0x0004390 @automation_element=nil, @control_type=:non_existent> (NoMethodError)
features\sheep_counter.feature:8:in `Then it tells me that no sheep have moved field yet'
Scenario: Move one sheep # features\sheep_counter.feature:10
Given I have started my sheep counter # features/step_definitions/sheep_counter_steps.rb:11
When I move one sheep # features/step_definitions/sheep_counter_steps.rb:15
Bewildr::ElementDoesntExist (Bewildr::ElementDoesntExist)
features\sheep_counter.feature:12:in `When I move one sheep'
Then it tells me that 1 sheep has moved # features/step_definitions/sheep_counter_steps.rb:19
Scenario: Move two sheep # features\sheep_counter.feature:15
Given I have started my sheep counter # features/step_definitions/sheep_counter_steps.rb:11
And I have moved 1 sheep already # features/step_definitions/sheep_counter_steps.rb:23
undefined method `text' for #<Bewildr::Element:0x00043cc @automation_element=nil, @control_type=:non_existent> (NoMethodError)
features\sheep_counter.feature:17:in `And I have moved 1 sheep already'
When I move another sheep # features/step_definitions/sheep_counter_steps.rb:29
Then it tells me that 2 sheep have moved # features/step_definitions/sheep_counter_steps.rb:19
Failing Scenarios:
cucumber features\sheep_counter.feature:6 # Scenario: Before I start moving my sheep
cucumber features\sheep_counter.feature:10 # Scenario: Move one sheep
cucumber features\sheep_counter.feature:15 # Scenario: Move two sheep
3 scenarios (3 failed)
9 steps (3 failed, 3 skipped, 3 passed)
0m11.316s
C:\wpfbdd>icucumber
Feature: Sheep Counter
As a farmer
In order to prevent any straggling sheep from getting eaten by the big bad wolf
I want to be able to keep track of my sheep as they move from field to field
Scenario: Before I start moving my sheep # features\sheep_counter.feature:6
When I start up my sheep counter # features/step_definitions/sheep_counter_steps.rb:1
Then it tells me that no sheep have moved field yet # features/step_definitions/sheep_counter_steps.rb:7
expected: "0",
got: "Label" (using ==)
Diff:
@@ -1,2 +1,2 @@
-0
+Label
(Spec::Expectations::ExpectationNotMetError)
features\sheep_counter.feature:8:in `Then it tells me that no sheep have moved field yet'
Scenario: Move one sheep # features\sheep_counter.feature:10
Given I have started my sheep counter # features/step_definitions/sheep_counter_steps.rb:11
When I move one sheep # features/step_definitions/sheep_counter_steps.rb:15
Then it tells me that 1 sheep has moved # features/step_definitions/sheep_counter_steps.rb:19
expected: "1",
got: "Label" (using ==)
Diff:
@@ -1,2 +1,2 @@
-1
+Label
(Spec::Expectations::ExpectationNotMetError)
features\sheep_counter.feature:13:in `Then it tells me that 1 sheep has moved'
Scenario: Move two sheep # features\sheep_counter.feature:15
Given I have started my sheep counter # features/step_definitions/sheep_counter_steps.rb:11
And I have moved 1 sheep already # features/step_definitions/sheep_counter_steps.rb:23
Bewildr::ElementDoesntExist (Bewildr::ElementDoesntExist)
:0:in `/^I have moved (\d+) sheep already$/'
features\sheep_counter.feature:17:in `And I have moved 1 sheep already'
When I move another sheep # features/step_definitions/sheep_counter_steps.rb:29
Then it tells me that 2 sheep have moved # features/step_definitions/sheep_counter_steps.rb:19
Failing Scenarios:
cucumber features\sheep_counter.feature:6 # Scenario: Before I start moving my sheep
cucumber features\sheep_counter.feature:10 # Scenario: Move one sheep
cucumber features\sheep_counter.feature:15 # Scenario: Move two sheep
3 scenarios (3 failed)
9 steps (3 failed, 2 skipped, 4 passed)
0m21.130s
require 'rubygems'
require 'bewildr'
require 'rubygems'
require 'bewildr'
After do
Bewildr::Application.kill_all_processes_with_name("SheepCounter")
end
require 'rubygems'
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
include Rake::DSL
desc "Acceptance Tests"
RSpec::Core::RakeTask.new do |t|
t.pattern = "spec/**/*_spec.rb"
end
desc "Unit Tests"
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = "--format pretty"
end
Feature: Sheep Counter
As a farmer
In order to prevent any straggling sheep from getting eaten by the big bad wolf
I want to be able to keep track of my sheep as they move from field to field
Feature: Sheep Counter
As a farmer
In order to prevent any straggling sheep from getting eaten by the big bad wolf
I want to be able to keep track of my sheep as they move from field to field
Scenario: Before I start moving my sheep
When I start up my sheep counter
Then it tells me that no sheep have moved field yet
Scenario: Move one sheep
Given I have started my sheep counter
When I move one sheep
Then it tells me that 1 sheep has moved
Scenario: Move two sheep
Given I have started my sheep counter
And I have moved 1 sheep already
When I move another sheep
Then it tells me that 2 sheep have moved
When /^I start up my sheep counter$/ do
@counter_app, @counter_window = Bewildr::Application.start_app_and_wait_for_window("c:\\wpfbdd\\SheepCounter\\SheepCounter\\bin\\Debug\\SheepCounter.exe", "Sheep Counter")
@counter_app.should be_running
@counter_window.should be_open
end
Then /^it tells me that no sheep have moved field yet$/ do
@counter_window.get(:id => "sheep_count").text.should == "0"
end
Given /^I have started my sheep counter$/ do
Given 'I start up my sheep counter'
end
When /^I move one sheep$/ do
@counter_window.get(:id => "increment_sheep").click
end
Then /^it tells me that (\d+) sheep ha(?:s|ve) moved$/ do |expected|
@counter_window.get(:id => "sheep_count").text.should == expected
end
Given /^I have moved (\d+) sheep already$/ do |target|
while @counter_window.get(:id => "sheep_count").text != target do
@counter_window.get(:id => "increment_sheep").click
end
end
When /^I move another sheep$/ do
When 'I move one sheep'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment