aslakhellesoy-cucumber 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/License.txt +1 -1
  2. data/Manifest.txt +38 -24
  3. data/README.textile +31 -0
  4. data/TODO.txt +30 -0
  5. data/config/hoe.rb +6 -7
  6. data/examples/java/README.textile +52 -0
  7. data/examples/java/Rakefile +12 -0
  8. data/examples/java/features/hello.feature +11 -0
  9. data/examples/java/features/steps/hello_steps.rb +25 -0
  10. data/examples/java/features/steps/tree_steps.rb +14 -0
  11. data/examples/java/features/tree.feature +9 -0
  12. data/examples/java/src/cucumber/demo/Hello.java +15 -0
  13. data/examples/pure_ruby/Rakefile +6 -0
  14. data/examples/pure_ruby/features/addition.rb +23 -0
  15. data/examples/pure_ruby/{steps → features/steps}/addition_steps.rb +0 -0
  16. data/examples/simple_norwegian/Rakefile +6 -0
  17. data/examples/simple_norwegian/{steg → features/steps}/matte_steg.rb.rb +0 -0
  18. data/examples/simple_norwegian/{summering.story → features/summering.feature} +4 -1
  19. data/examples/web/Rakefile +6 -0
  20. data/examples/web/features/search.feature +9 -0
  21. data/examples/web/features/steps/stories_steps.rb +51 -0
  22. data/gem_tasks/treetop.rake +8 -14
  23. data/lib/cucumber.rb +10 -3
  24. data/lib/cucumber/cli.rb +29 -19
  25. data/lib/cucumber/core_ext/proc.rb +13 -5
  26. data/lib/cucumber/executor.rb +8 -10
  27. data/lib/cucumber/formatters/ansicolor.rb +2 -2
  28. data/lib/cucumber/formatters/html_formatter.rb +6 -6
  29. data/lib/cucumber/formatters/pretty_formatter.rb +68 -15
  30. data/lib/cucumber/{parser/languages.yml → languages.yml} +0 -4
  31. data/lib/cucumber/rake/task.rb +24 -26
  32. data/lib/cucumber/step_mother.rb +3 -3
  33. data/lib/cucumber/tree.rb +8 -117
  34. data/lib/cucumber/tree/feature.rb +45 -0
  35. data/lib/cucumber/tree/features.rb +21 -0
  36. data/lib/cucumber/tree/scenario.rb +79 -0
  37. data/lib/cucumber/tree/step.rb +133 -0
  38. data/lib/cucumber/tree/table.rb +26 -0
  39. data/lib/cucumber/{parser → tree}/top_down_visitor.rb +5 -8
  40. data/lib/cucumber/treetop_parser/feature.treetop.erb +98 -0
  41. data/lib/cucumber/treetop_parser/feature_en.rb +923 -0
  42. data/lib/cucumber/treetop_parser/feature_fr.rb +923 -0
  43. data/lib/cucumber/treetop_parser/feature_no.rb +923 -0
  44. data/lib/cucumber/treetop_parser/feature_parser.rb +32 -0
  45. data/lib/cucumber/treetop_parser/feature_pt.rb +923 -0
  46. data/lib/cucumber/version.rb +2 -2
  47. data/script/console +1 -1
  48. data/spec/cucumber/executor_spec.rb +9 -9
  49. data/spec/cucumber/formatters/{stories.html → features.html} +9 -9
  50. data/spec/cucumber/formatters/html_formatter_spec.rb +11 -11
  51. data/spec/cucumber/{sell_cucumbers.story → sell_cucumbers.feature} +1 -1
  52. data/spec/spec_helper.rb +8 -1
  53. metadata +61 -30
  54. data/README.txt +0 -78
  55. data/examples/Rakefile +0 -7
  56. data/examples/pure_ruby/addition.rb +0 -16
  57. data/examples/simple/addition.story +0 -12
  58. data/examples/simple/division.story +0 -17
  59. data/examples/simple/steps/addition_steps.rb +0 -43
  60. data/examples/web/run_stories.story +0 -10
  61. data/examples/web/steps/stories_steps.rb +0 -39
  62. data/lib/cucumber/parser/nodes.rb +0 -88
  63. data/lib/cucumber/parser/story_parser.rb +0 -13
  64. data/lib/cucumber/parser/story_parser.treetop.erb +0 -41
  65. data/lib/cucumber/parser/story_parser_en.rb +0 -554
  66. data/lib/cucumber/parser/story_parser_fr.rb +0 -554
  67. data/lib/cucumber/parser/story_parser_no.rb +0 -554
  68. data/lib/cucumber/parser/story_parser_pt.rb +0 -554
  69. data/lib/cucumber/ruby_tree.rb +0 -14
  70. data/lib/cucumber/ruby_tree/nodes.rb +0 -68
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 FIXME full name
1
+ Copyright (c) 2008 Aslak Hellesøy
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,21 +1,33 @@
1
1
  History.txt
2
2
  License.txt
3
3
  Manifest.txt
4
- README.txt
4
+ README.textile
5
5
  Rakefile
6
+ TODO.txt
6
7
  bin/cucumber
7
8
  config/hoe.rb
8
9
  config/requirements.rb
9
- examples/Rakefile
10
- examples/pure_ruby/addition.rb
11
- examples/pure_ruby/steps/addition_steps.rb
12
- examples/simple/addition.story
13
- examples/simple/division.story
14
- examples/simple/steps/addition_steps.rb
15
- examples/simple_norwegian/steg/matte_steg.rb.rb
16
- examples/simple_norwegian/summering.story
17
- examples/web/run_stories.story
18
- examples/web/steps/stories_steps.rb
10
+ examples/calculator/Rakefile
11
+ examples/calculator/features/addition.feature
12
+ examples/calculator/features/division.feature
13
+ examples/calculator/features/steps/addition_steps.rb
14
+ examples/calculator/lib/calculator.rb
15
+ examples/java/README.textile
16
+ examples/java/Rakefile
17
+ examples/java/features/hello.feature
18
+ examples/java/features/steps/hello_steps.rb
19
+ examples/java/features/steps/tree_steps.rb
20
+ examples/java/features/tree.feature
21
+ examples/java/src/cucumber/demo/Hello.java
22
+ examples/pure_ruby/Rakefile
23
+ examples/pure_ruby/features/addition.rb
24
+ examples/pure_ruby/features/steps/addition_steps.rb
25
+ examples/simple_norwegian/Rakefile
26
+ examples/simple_norwegian/features/steps/matte_steg.rb.rb
27
+ examples/simple_norwegian/features/summering.feature
28
+ examples/web/Rakefile
29
+ examples/web/features/search.feature
30
+ examples/web/features/steps/stories_steps.rb
19
31
  gem_tasks/deployment.rake
20
32
  gem_tasks/environment.rake
21
33
  gem_tasks/fix_cr_lf.rake
@@ -32,22 +44,24 @@ lib/cucumber/formatters/ansicolor.rb
32
44
  lib/cucumber/formatters/html_formatter.rb
33
45
  lib/cucumber/formatters/pretty_formatter.rb
34
46
  lib/cucumber/formatters/progress_formatter.rb
35
- lib/cucumber/parser/languages.yml
36
- lib/cucumber/parser/nodes.rb
37
- lib/cucumber/parser/story_parser.rb
38
- lib/cucumber/parser/story_parser.treetop.erb
39
- lib/cucumber/parser/story_parser_en.rb
40
- lib/cucumber/parser/story_parser_fr.rb
41
- lib/cucumber/parser/story_parser_no.rb
42
- lib/cucumber/parser/story_parser_pt.rb
43
- lib/cucumber/parser/top_down_visitor.rb
47
+ lib/cucumber/languages.yml
44
48
  lib/cucumber/rails/world.rb
45
49
  lib/cucumber/rake/task.rb
46
- lib/cucumber/ruby_tree.rb
47
- lib/cucumber/ruby_tree/nodes.rb
48
50
  lib/cucumber/step_methods.rb
49
51
  lib/cucumber/step_mother.rb
50
52
  lib/cucumber/tree.rb
53
+ lib/cucumber/tree/feature.rb
54
+ lib/cucumber/tree/features.rb
55
+ lib/cucumber/tree/scenario.rb
56
+ lib/cucumber/tree/step.rb
57
+ lib/cucumber/tree/table.rb
58
+ lib/cucumber/tree/top_down_visitor.rb
59
+ lib/cucumber/treetop_parser/feature.treetop.erb
60
+ lib/cucumber/treetop_parser/feature_en.rb
61
+ lib/cucumber/treetop_parser/feature_fr.rb
62
+ lib/cucumber/treetop_parser/feature_no.rb
63
+ lib/cucumber/treetop_parser/feature_parser.rb
64
+ lib/cucumber/treetop_parser/feature_pt.rb
51
65
  lib/cucumber/version.rb
52
66
  script/console
53
67
  script/console.cmd
@@ -61,9 +75,9 @@ setup.rb
61
75
  spec/cucumber/core_ext/string_spec.rb
62
76
  spec/cucumber/executor_spec.rb
63
77
  spec/cucumber/formatters/ansicolor_spec.rb
78
+ spec/cucumber/formatters/features.html
64
79
  spec/cucumber/formatters/html_formatter_spec.rb
65
- spec/cucumber/formatters/stories.html
66
- spec/cucumber/sell_cucumbers.story
80
+ spec/cucumber/sell_cucumbers.feature
67
81
  spec/spec.opts
68
82
  spec/spec_helper.rb
69
83
  website/index.html
@@ -0,0 +1,31 @@
1
+ h1. Cucumber
2
+
3
+ "Cucumber":http://github.com/aslakhellesoy/cucumber is a tool that can execute documentation written in plain text. Cucumber targets non technical domain experts as well as
4
+ programmers and QA people. Cucumber itself is written in Ruby, but it can be used to "test" code written in Ruby, Java
5
+ (or web applications written in any language). When "IronRuby":http://www.ironruby.net/ matures it can be used to "test"
6
+ .NET code too.
7
+
8
+ While Cucumber can be thought of as a "testing" tool, most people use it to support "BDD":http://behaviour-driven.org/, so
9
+ the "tests" are typically the first thing that gets written, and the production code is then written outside-in, to make
10
+ the test pass.
11
+
12
+ h2. Installation
13
+
14
+ After you have installed Ruby or JRuby - install Cucumber with the following commands:
15
+
16
+ Ruby:
17
+ <pre><code>gem sources --add http://gems.github.com/
18
+ gem install aslakhellesoy-cucumber
19
+ </code></pre>
20
+
21
+ JRuby:
22
+ <pre><code>jruby -S gem sources --add http://gems.github.com/
23
+ jruby -S gem install aslakhellesoy-cucumber
24
+ </code></pre>
25
+
26
+ h2. Getting started
27
+
28
+ I haven't written a tutorial yet. Take a look at the "examples":http://github.com/aslakhellesoy/cucumber/tree/master/examples.
29
+ Each example directory has a Rakefile, and you can run the features with
30
+
31
+ <pre><code>rake features</code></pre>
@@ -0,0 +1,30 @@
1
+ == FEATURES/PROBLEMS:
2
+
3
+ * Run examples with:
4
+ ** ruby -Ilib bin/cucumber examples/simple --require examples/simple/steps
5
+ ** ruby -Ilib bin/cucumber examples/web --require examples/web/steps
6
+
7
+ * TODO: OK Refactor: Extract explicit node classes with RDoc (for better API doc)
8
+ * TODO: OK Get rid of the compile method. Compile the parser in Rake.
9
+ * TODO: OK Make grammar support \r\n, \r and \n (Add some fixture features for that)
10
+ * TODO: OK Make grammar support indentation
11
+ * TODO: OK Make grammar be totally relaxed about narrative
12
+ * TODO: OK Add a yaml file for different languages
13
+ * TODO: OK Custom nodes for the syntax tree
14
+ * TODO: OK Actually execute the features
15
+ * TODO: Make rake run specs by default
16
+ * TODO: OK Make it work with pure ruby regexen
17
+ * TODO: Make it work with string steps
18
+ * TODO: bin/cucumber --require [dir|file|glob]* --language no --format [file]*
19
+ * TODO: OK Pending steps shold print a block of code that can be pasted into code
20
+ * TODO: cucumber --where "Some text from a step" that prints "__FILE__:__LINE__ (STEP PATTERN)"
21
+ * TODO: Customisable trace output (like javascriptlint)
22
+ * TODO: Experiment: Make $variables become @variables
23
+ * TODO: GivenScenario
24
+ * TODO: OK PureRuby
25
+ * Make two trees include accept mixin
26
+ * TODO: Call steps from steps
27
+ * TODO: i18n in ruby too
28
+ * TODO: Don't load any treetop files if no .feature files are found
29
+ * TODO: Summary prints execution time
30
+ * TODO: --nocolor option
@@ -2,11 +2,10 @@ require 'cucumber/version'
2
2
 
3
3
  AUTHOR = 'Aslak Hellesøy' # can also be an array of Authors
4
4
  EMAIL = "aslak.hellesoy@gmail.com"
5
- DESCRIPTION = "Executable user stories"
5
+ DESCRIPTION = "Executable Feature scenarios"
6
6
  GEM_NAME = 'cucumber' # what ppl will type to install your gem
7
- RUBYFORGE_PROJECT = 'cucumber' # The unix name for your project
8
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
- DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
7
+ HOMEPATH = "http://github.com/aslakhellesoy/cucumber"
8
+ RUBYFORGE_PROJECT = nil
10
9
 
11
10
  @config_file = "~/.rubyforge/user-config.yml"
12
11
  @config = nil
@@ -32,7 +31,7 @@ REV = nil
32
31
  # UNCOMMENT IF REQUIRED:
33
32
  # REV = YAML.load(`svn info`)['Revision']
34
33
  VERS = Cucumber::VERSION::STRING + (REV ? ".#{REV}" : "")
35
- RDOC_OPTS = ['--quiet', '--title', 'cucumber documentation',
34
+ RDOC_OPTS = ['--quiet', '--title', 'Cucumber documentation',
36
35
  "--opname", "index.html",
37
36
  "--line-numbers",
38
37
  "--main", "README",
@@ -53,12 +52,12 @@ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
53
52
  p.summary = DESCRIPTION
54
53
  p.url = HOMEPATH
55
54
  p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
55
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store', '**/*.class', '**/*.jar'] #An array of file patterns to delete on clean.
57
56
 
58
57
  # == Optional
59
58
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
60
59
  #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
61
- p.extra_deps = [ ['term-ansicolor', '>= 1.0.3'], ['treetop', '>= 1.2.4'] ]
60
+ p.extra_deps = [ ['term-ansicolor', '>= 1.0.3'], ['treetop', '>= 1.2.4'], ['rspec', '>= 1.1.4'], ['diff-lcs', '>= 1.1.2'] ]
62
61
 
63
62
  #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
63
 
@@ -0,0 +1,52 @@
1
+ h1. Using Cucumber with Java
2
+
3
+ This directory contains code to demonstrate how Cucumber can be used to develop Java code.
4
+ You need JRuby 1.1.3 or higher installed and JRuby's bin directory on your PATH.
5
+
6
+ h2. Installing required gems
7
+
8
+ jruby -S gem install aslakhellesoy-cucumber
9
+ jruby -S gem install diff-lcs
10
+
11
+ h2. Running the scenarios
12
+
13
+ Open a shell in this directory (java) and execute the following command:
14
+
15
+ <pre><code>
16
+ jruby -S rake features
17
+ </code></pre>
18
+
19
+ This will compile the java code and package it in a jar file, and then run Cucumber against
20
+ that code.
21
+
22
+ There is a deliberate error. See if you can fix it!
23
+
24
+ h2. Background and Credits
25
+
26
+ Cucumber is a rewrite of RSpec's "Story runner", which was originally written by Dan North. Dan's original
27
+ implementation required that stories be written in Ruby. Shortly after, David Chelimsky added
28
+ "plain text":http://blog.davidchelimsky.net/articles/2007/10/21/story-runner-in-plain-english support.
29
+
30
+ This brought executable stories a little closer to non-technical users, which is one of the target audiences
31
+ for this kind of tool.
32
+
33
+ However, the RSpec Story runner has several shortcomings which is rather common for tools that move into new territory.
34
+ Some of the biggest problems with it are:
35
+
36
+ * Hard to get started with. A special "all.rb" file must be written before it can be used.
37
+ * No out of the box Rake support, which puts a lot of people off.
38
+ * No i18n, so if you want to write stories in a different language than English you're out of luck.
39
+ * Poor error reporting. No way to know on what line a plain text story failed during execution or parsing.
40
+ * Limited colouring of output.
41
+ * No simple way to execute only one scenario.
42
+ * No command line tool to run stories.
43
+
44
+ While all of this could have been fixed in the existing codebase, I figured it would be easier to do a rewrite from scratch.
45
+ I also had some ideas for extensions of the story grammar, so I decided to use "Treetop":http://treetop.rubyforge.org/
46
+ and base it on a proper "grammar":http://github.com/aslakhellesoy/cucumber/tree/master/lib/cucumber/treetop_parser/feature.treetop.erb
47
+
48
+ Cucumber addresses all of the shortcomings of RSpec's Story runner. If the community likes it, we'll consider phasing out
49
+ the RSpec story runner.
50
+
51
+ The term "Feature" has been adopted in favour of "Story" because I believe it is a more appropriate term. A feature's scenarios
52
+ typically increases over time - fed by several user stories.
@@ -0,0 +1,12 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'cucumber/rake/task'
3
+
4
+ Cucumber::Rake::Task.new(:features) do |t|
5
+ t.cucumber_opts = "--format pretty"
6
+ end
7
+
8
+ task :features => :compile
9
+
10
+ task :compile do
11
+ sh "javac src/cucumber/demo/Hello.java && jar cf src/cucumber_demo.jar -C src cucumber/demo/Hello.class"
12
+ end
@@ -0,0 +1,11 @@
1
+ Feature: Hello
2
+ In order to have more friends
3
+ I want to say hello
4
+
5
+ Scenario: Personal greeting
6
+ Given my name is Aslak
7
+ When I greet David
8
+ Then he should hear Hi, David. I'm Aslak.
9
+ And I should remember David as a friend
10
+ And I should get David's phone number
11
+
@@ -0,0 +1,25 @@
1
+ require 'spec' # so we can call .should
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../src') # so the jar is found
3
+ require 'cucumber_demo' # puts the jar on the classpath
4
+ include_class 'cucumber.demo.Hello'
5
+
6
+ Given /my name is (\w+)/ do |name|
7
+ @hello = Hello.new # A java object
8
+ @name = name
9
+ end
10
+
11
+ When /I greet (.*)/ do |someone|
12
+ @greeting = @hello.greet(someone, @name)
13
+ end
14
+
15
+ Then /he should hear (.*)\./ do |message|
16
+ @greeting.should == message
17
+ end
18
+
19
+ Then /I should remember (\w+) as a friend/ do |name|
20
+ @hello.friend?(name).should == true
21
+ end
22
+
23
+ Then /I should get (\w+)'s phone number/ do |name|
24
+ @hello.getPhoneNumber(name).should_not == nil
25
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec'
2
+ include_class 'java.util.TreeSet'
3
+
4
+ Given /I have an empty set/ do
5
+ @set = TreeSet.new
6
+ end
7
+
8
+ When /I add (\w+)/ do |s|
9
+ @set.add(s)
10
+ end
11
+
12
+ Then /the contents should be (.*)/ do |s|
13
+ @set.to_a.join(" ").should == s
14
+ end
@@ -0,0 +1,9 @@
1
+ Feature: Tree
2
+ In order to have more robust Java software
3
+ I want to use Cucumber against Java classes
4
+
5
+ Scenario: Use java.util.TreeSet
6
+ Given I have an empty set
7
+ When I add hello
8
+ And I add world
9
+ Then the contents should be hello world
@@ -0,0 +1,15 @@
1
+ package cucumber.demo;
2
+
3
+ public class Hello {
4
+ public String greet(String who, String from) {
5
+ return "Hi, " + who + ". I'm " + from;
6
+ }
7
+
8
+ public boolean isFriend(String who) {
9
+ return true;
10
+ }
11
+
12
+ public String getPhoneNumber(String who) {
13
+ return "99999";
14
+ }
15
+ }
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'cucumber/rake/task'
3
+
4
+ Cucumber::Rake::Task.new do |t|
5
+ t.cucumber_opts = "--format pretty"
6
+ end
@@ -0,0 +1,23 @@
1
+ require 'cucumber/cli' # Needed in order to run the feature with ruby
2
+
3
+ Feature %|Addition
4
+ As a math idiot
5
+ I want to be told the sum of two numbers
6
+ So that I don't make silly mistakes| do
7
+
8
+ Scenario "Add two numbers" do
9
+ Given "I have entered 50 into the calculator"
10
+ And "I have entered 70 into the calculator"
11
+ When "I add"
12
+ Then "the result should be 120 on the screen"
13
+ And "the result class should be Float"
14
+ end
15
+
16
+ Table do |t|
17
+ t | "input_1" | "input_2" | "output" | "class" | t
18
+ # This is kind of dumb - but it illustrates how scenarios can be "generated" in code.
19
+ 10.times do |n|
20
+ t | n | n*2 | n*3 | Fixnum | t
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'cucumber/rake/task'
3
+
4
+ Cucumber::Rake::Task.new do |t|
5
+ t.cucumber_opts = "--format pretty --language no"
6
+ end
@@ -1,4 +1,4 @@
1
- Historie: Addition
1
+ Egenskap: Summering
2
2
  Som en matteidiot
3
3
  Vil jeg bli fortalt summen av to tall
4
4
  Slik at jeg ikke gjør dumme feil
@@ -8,3 +8,6 @@ Historie: Addition
8
8
  Og at jeg har tastet inn 7
9
9
  Når jeg summerer
10
10
  Så skal resultatet være 12
11
+
12
+ |a|b|s|
13
+ |2|3|5|
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'cucumber/rake/task'
3
+
4
+ Cucumber::Rake::Task.new do |t|
5
+ t.cucumber_opts = "--format pretty"
6
+ end
@@ -0,0 +1,9 @@
1
+ Feature: Search
2
+ As an information seeker
3
+ I want to find more information
4
+ So that I can learn more
5
+
6
+ Scenario: Find what I'm looking for
7
+ Given I am on the Google search page
8
+ When I search for "rspec"
9
+ Then I should see a link to "RSpec-1.1.4: Overview":http://rspec.info/
@@ -0,0 +1,51 @@
1
+ require 'spec'
2
+
3
+ case PLATFORM
4
+ when /darwin/
5
+ require 'safariwatir'
6
+ Browser = Watir::Safari
7
+ when /win32|mingw/
8
+ require 'watir'
9
+ Browser = Watir::IE
10
+ when /java/
11
+ require 'celerity'
12
+ Browser = Celerity::Browser
13
+ else
14
+ raise "This platform is not supported (#{PLATFORM})"
15
+ end
16
+
17
+ class GoogleSearch
18
+ def initialize(b)
19
+ @b = b
20
+ end
21
+
22
+ def goto
23
+ @b.goto 'http://www.google.com/'
24
+ end
25
+
26
+ def search(text)
27
+ @b.text_field(:name, 'q').set(text)
28
+ @b.button(:name, 'btnG').click
29
+ end
30
+ end
31
+
32
+ Before do
33
+ @b = Browser.new
34
+ end
35
+
36
+ After do
37
+ @b.close
38
+ end
39
+
40
+ Given 'I am on the Google search page' do
41
+ @page = GoogleSearch.new(@b)
42
+ @page.goto
43
+ end
44
+
45
+ When /I search for "(.*)"/ do |query|
46
+ @page.search(query)
47
+ end
48
+
49
+ Then /I should see a link to "(.*)":(.*)/ do |text, url|
50
+ @b.link(:url, url).text.should == text
51
+ end