aslakhellesoy-cucumber 0.3.102 → 0.3.102.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,15 @@
1
+ == (In Git)
2
+
3
+ This release gives you back some of the control over the Rails environment that was accidentally taken away from you in the
4
+ previous release.
5
+
6
+ Using this release on a Rails project requires a rerun of script/generate cucumber.
7
+
8
+ === New Features
9
+ * Added a new @no-txn tag to selectively turn off transactions for a particluar scenario.
10
+ * Added back a way to globally turn off transactions.
11
+ * Renamed @allow_rescue tag to @allow-rescue.
12
+
1
13
  == 2009-09-22
2
14
 
3
15
  This release has some changes in the Rails support, so make sure you run "script/generate cucumber" after you upgrade.
@@ -385,13 +385,14 @@ lib/cucumber/rails/test_unit.rb
385
385
  lib/cucumber/rails/world.rb
386
386
  lib/cucumber/rake/task.rb
387
387
  lib/cucumber/rb_support/rb_dsl.rb
388
- lib/cucumber/rb_support/rb_group.rb
389
388
  lib/cucumber/rb_support/rb_hook.rb
390
389
  lib/cucumber/rb_support/rb_language.rb
391
390
  lib/cucumber/rb_support/rb_step_definition.rb
392
391
  lib/cucumber/rb_support/rb_transform.rb
393
392
  lib/cucumber/rb_support/rb_world.rb
393
+ lib/cucumber/rb_support/regexp_argument_matcher.rb
394
394
  lib/cucumber/rspec_neuter.rb
395
+ lib/cucumber/step_argument.rb
395
396
  lib/cucumber/step_match.rb
396
397
  lib/cucumber/step_mother.rb
397
398
  lib/cucumber/version.rb
@@ -427,7 +428,6 @@ spec/cucumber/cli/main_spec.rb
427
428
  spec/cucumber/cli/options_spec.rb
428
429
  spec/cucumber/cli/profile_loader_spec.rb
429
430
  spec/cucumber/core_ext/proc_spec.rb
430
- spec/cucumber/core_ext/string_spec.rb
431
431
  spec/cucumber/formatter/ansicolor_spec.rb
432
432
  spec/cucumber/formatter/color_io_spec.rb
433
433
  spec/cucumber/formatter/duration_spec.rb
@@ -436,7 +436,9 @@ spec/cucumber/formatter/progress_spec.rb
436
436
  spec/cucumber/parser/feature_parser_spec.rb
437
437
  spec/cucumber/parser/table_parser_spec.rb
438
438
  spec/cucumber/rb_support/rb_step_definition_spec.rb
439
+ spec/cucumber/rb_support/regexp_argument_matcher_spec.rb
439
440
  spec/cucumber/sell_cucumbers.feature
441
+ spec/cucumber/step_match_spec.rb
440
442
  spec/cucumber/step_mother_spec.rb
441
443
  spec/cucumber/treetop_parser/empty_feature.feature
442
444
  spec/cucumber/treetop_parser/empty_scenario.feature
@@ -8,7 +8,8 @@ Feature: --formatter steps option - Steps Formatter
8
8
 
9
9
  Scenario: Printing steps
10
10
  When I run cucumber -f steps features
11
- Then it should pass with
11
+ Then STDERR should be empty
12
+ And it should pass with
12
13
  """
13
14
  features/step_definitions/steps_lib1.rb
14
15
  /^I defined a first step$/ # features/step_definitions/steps_lib1.rb:1
@@ -7,28 +7,6 @@ class String #:nodoc:
7
7
  end
8
8
  end
9
9
 
10
- # TODO: Move to StepMatch
11
- # +groups+ is an array of 2-element arrays, where
12
- # the 1st element is the value of a regexp match group,
13
- # and the 2nd element is its start index.
14
- def gzub(groups, format=nil, &proc)
15
- s = dup
16
- offset = 0
17
- groups.each do |group|
18
- replacement = if block_given?
19
- proc.call(group.val)
20
- elsif Proc === format
21
- format.call(group.val)
22
- else
23
- format % group.val
24
- end
25
-
26
- s[group.start + offset, group.val.length] = replacement
27
- offset += replacement.length - group.val.length
28
- end
29
- s
30
- end
31
-
32
10
  if (Cucumber::JRUBY && Cucumber::RAILS) || Cucumber::RUBY_1_9
33
11
  # Workaround for http://tinyurl.com/55uu3u
34
12
  alias jlength length
@@ -23,9 +23,9 @@ module Cucumber
23
23
 
24
24
  sources = @step_definition_files[step_definition_file]
25
25
  source_indent = source_indent(sources)
26
- sources.sort.each do |file_colon_line, regexp|
27
- @io.print "#{regexp}".indent(2)
28
- @io.print " # #{file_colon_line}".indent(source_indent - regexp.size)
26
+ sources.sort.each do |file_colon_line, regexp_source|
27
+ @io.print regexp_source.indent(2)
28
+ @io.print " # #{file_colon_line}".indent(source_indent - regexp_source.jlength)
29
29
  @io.puts
30
30
  end
31
31
  @io.puts
@@ -37,7 +37,7 @@ module Cucumber
37
37
  def collect_steps(step_mother)
38
38
  step_mother.step_definitions.inject({}) do |step_definitions, step_definition|
39
39
  step_definitions[step_definition.file] ||= []
40
- step_definitions[step_definition.file] << [ step_definition.file_colon_line, step_definition.regexp.inspect ]
40
+ step_definitions[step_definition.file] << [ step_definition.file_colon_line, step_definition.regexp_source ]
41
41
  step_definitions
42
42
  end
43
43
  end
@@ -44,7 +44,7 @@ module Cucumber
44
44
  sorted_defs.each do |step_definition|
45
45
  step_matches_and_descriptions = @step_definitions[step_definition].sort_by do |step_match_and_description|
46
46
  step_match = step_match_and_description[0]
47
- step_match.step_definition.regexp.inspect
47
+ step_match.step_definition.regexp_source
48
48
  end
49
49
 
50
50
  step_matches = step_matches_and_descriptions.map{|step_match_and_description| step_match_and_description[0]}
@@ -55,7 +55,7 @@ module Cucumber
55
55
  lengths << step_definition.text_length
56
56
  max_length = lengths.max
57
57
 
58
- @io.print step_definition.regexp.inspect
58
+ @io.print step_definition.regexp_source
59
59
  @io.puts format_string(" # #{step_definition.file_colon_line}".indent(max_length - step_definition.text_length), :comment)
60
60
  da = step_matches_and_descriptions.map do |step_match_and_description|
61
61
  step_match = step_match_and_description[0]
@@ -76,7 +76,7 @@ module Cucumber
76
76
 
77
77
  @io.puts format_string("(::) UNUSED (::)", :failed)
78
78
  @all_step_definitions.each do |step_definition|
79
- @io.print format_string(step_definition.regexp.inspect, :failed)
79
+ @io.print format_string(step_definition.regexp_source, :failed)
80
80
  @io.puts format_string(" # #{step_definition.file_colon_line}".indent(max_length - step_definition.text_length), :comment)
81
81
  end
82
82
  end
@@ -4,19 +4,19 @@ module Cucumber
4
4
  module LanguageSupport
5
5
  module StepDefinitionMethods
6
6
  def step_match(name_to_match, name_to_report)
7
- if(groups = groups(name_to_match))
8
- StepMatch.new(self, name_to_match, name_to_report, groups)
7
+ if(arguments = arguments_from(name_to_match))
8
+ StepMatch.new(self, name_to_match, name_to_report, arguments)
9
9
  else
10
10
  nil
11
11
  end
12
12
  end
13
13
 
14
14
  def backtrace_line
15
- "#{file_colon_line}:in `#{regexp.inspect}'"
15
+ "#{file_colon_line}:in `#{regexp_source}'"
16
16
  end
17
17
 
18
18
  def text_length
19
- regexp.inspect.jlength
19
+ regexp_source.jlength
20
20
  end
21
21
  end
22
22
  end
@@ -28,6 +28,6 @@ rescue NameError # Failsafe was introduced in Rails 2.3.2
28
28
  end
29
29
  end
30
30
 
31
- Before('@allow_rescue') do
31
+ Before('@allow-rescue') do
32
32
  ActionController::Base.allow_rescue = true
33
33
  end
@@ -1,24 +1,37 @@
1
1
  if defined?(ActiveRecord::Base)
2
- Cucumber::Rails::World.use_transactional_fixtures = true
3
-
2
+ Before('~@no-txn') do
3
+ @__cucumber_use_txn = Cucumber::Rails::World.use_transactional_fixtures
4
+ Cucumber::Rails::World.use_transactional_fixtures = true
5
+ end
6
+
7
+ Before('@no-txn') do
8
+ @__cucumber_use_txn = Cucumber::Rails::World.use_transactional_fixtures
9
+ Cucumber::Rails::World.use_transactional_fixtures = false
10
+ end
11
+
4
12
  Before do
5
- @__cucumber_ar_connection = ActiveRecord::Base.connection
6
- if @__cucumber_ar_connection.respond_to?(:increment_open_transactions)
7
- @__cucumber_ar_connection.increment_open_transactions
8
- else
9
- ActiveRecord::Base.__send__(:increment_open_transactions)
13
+ if Cucumber::Rails::World.use_transactional_fixtures
14
+ @__cucumber_ar_connection = ActiveRecord::Base.connection
15
+ if @__cucumber_ar_connection.respond_to?(:increment_open_transactions)
16
+ @__cucumber_ar_connection.increment_open_transactions
17
+ else
18
+ ActiveRecord::Base.__send__(:increment_open_transactions)
19
+ end
20
+ @__cucumber_ar_connection.begin_db_transaction
10
21
  end
11
- @__cucumber_ar_connection.begin_db_transaction
12
22
  ActionMailer::Base.deliveries = [] if defined?(ActionMailer::Base)
13
23
  end
14
-
24
+
15
25
  After do
16
- @__cucumber_ar_connection.rollback_db_transaction
17
- if @__cucumber_ar_connection.respond_to?(:decrement_open_transactions)
18
- @__cucumber_ar_connection.decrement_open_transactions
19
- else
20
- ActiveRecord::Base.__send__(:decrement_open_transactions)
26
+ if Cucumber::Rails::World.use_transactional_fixtures
27
+ @__cucumber_ar_connection.rollback_db_transaction
28
+ if @__cucumber_ar_connection.respond_to?(:decrement_open_transactions)
29
+ @__cucumber_ar_connection.decrement_open_transactions
30
+ else
31
+ ActiveRecord::Base.__send__(:decrement_open_transactions)
32
+ end
21
33
  end
34
+ Cucumber::Rails::World.use_transactional_fixtures = @__cucumber_use_txn
22
35
  end
23
36
  else
24
37
  module Cucumber::Rails
@@ -3,6 +3,7 @@ require 'cucumber/rb_support/rb_world'
3
3
  require 'cucumber/rb_support/rb_step_definition'
4
4
  require 'cucumber/rb_support/rb_hook'
5
5
  require 'cucumber/rb_support/rb_transform'
6
+ require 'cucumber/rb_support/regexp_argument_matcher'
6
7
 
7
8
  module Cucumber
8
9
  module RbSupport
@@ -55,6 +56,10 @@ module Cucumber
55
56
  end
56
57
  end
57
58
 
59
+ def arguments_from(regexp, step_name)
60
+ @regexp_argument_matcher.arguments_from(regexp, step_name)
61
+ end
62
+
58
63
  def snippet_text(step_keyword, step_name, multiline_arg_class = nil)
59
64
  escaped = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/')
60
65
  escaped = escaped.gsub(PARAM_PATTERN, ESCAPED_PARAM_PATTERN)
@@ -1,7 +1,7 @@
1
1
  require 'cucumber/step_match'
2
2
  require 'cucumber/core_ext/string'
3
3
  require 'cucumber/core_ext/proc'
4
- require 'cucumber/rb_support/rb_group'
4
+ require 'cucumber/rb_support/regexp_argument_matcher'
5
5
 
6
6
  module Cucumber
7
7
  module RbSupport
@@ -24,8 +24,6 @@ module Cucumber
24
24
  end
25
25
  end
26
26
 
27
- attr_reader :proc, :regexp
28
-
29
27
  def initialize(rb_language, regexp, proc)
30
28
  raise MissingProc if proc.nil?
31
29
  if String === regexp
@@ -35,28 +33,23 @@ module Cucumber
35
33
  @rb_language, @regexp, @proc = rb_language, regexp, proc
36
34
  end
37
35
 
36
+ def regexp_source
37
+ @regexp.inspect
38
+ end
39
+
38
40
  def ==(step_definition)
39
- self.regexp == step_definition.regexp
41
+ regexp_source == step_definition.regexp_source
40
42
  end
41
43
 
42
- def groups(step_name)
43
- match = regexp.match(step_name)
44
- if match
45
- n = 0
46
- match.captures.map do |val|
47
- n += 1
48
- RbGroup.new(val, match.offset(n)[0])
49
- end
50
- else
51
- nil
52
- end
44
+ def arguments_from(step_name)
45
+ RegexpArgumentMatcher.arguments_from(@regexp, step_name)
53
46
  end
54
47
 
55
48
  def invoke(args)
56
49
  args = args.map{|arg| Ast::PyString === arg ? arg.to_s : arg}
57
50
  begin
58
51
  args = @rb_language.execute_transforms(args)
59
- @rb_language.current_world.cucumber_instance_exec(true, regexp.inspect, *args, &@proc)
52
+ @rb_language.current_world.cucumber_instance_exec(true, regexp_source, *args, &@proc)
60
53
  rescue Cucumber::ArityMismatchError => e
61
54
  e.backtrace.unshift(self.backtrace_line)
62
55
  raise e
@@ -0,0 +1,20 @@
1
+ require 'cucumber/step_argument'
2
+
3
+ module Cucumber
4
+ module RbSupport
5
+ class RegexpArgumentMatcher
6
+ def self.arguments_from(regexp, step_name)
7
+ match = regexp.match(step_name)
8
+ if match
9
+ n = 0
10
+ match.captures.map do |val|
11
+ n += 1
12
+ StepArgument.new(val, match.offset(n)[0])
13
+ end
14
+ else
15
+ nil
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ module Cucumber
2
+ class StepArgument
3
+ attr_reader :val, :pos
4
+
5
+ def initialize(val, pos)
6
+ @val, @pos = val, pos
7
+ end
8
+ end
9
+ end
@@ -2,12 +2,12 @@ module Cucumber
2
2
  class StepMatch #:nodoc:
3
3
  attr_reader :step_definition
4
4
 
5
- def initialize(step_definition, step_name, formatted_step_name, groups)
6
- @step_definition, @step_name, @formatted_step_name, @groups = step_definition, step_name, formatted_step_name, groups
5
+ def initialize(step_definition, step_name, formatted_step_name, step_arguments)
6
+ @step_definition, @step_name, @formatted_step_name, @step_arguments = step_definition, step_name, formatted_step_name, step_arguments
7
7
  end
8
8
 
9
9
  def args
10
- @groups.map{|g| g.val}
10
+ @step_arguments.map{|g| g.val}
11
11
  end
12
12
 
13
13
  def name
@@ -35,8 +35,8 @@ module Cucumber
35
35
  #
36
36
  # lambda { |param| "[#{param}]" }
37
37
  #
38
- def format_args(format = lambda{|a| a})
39
- @formatted_step_name || @step_name.gzub(@groups, format)
38
+ def format_args(format = lambda{|a| a}, &proc)
39
+ @formatted_step_name || replace_arguments(@step_name, @step_arguments, format, &proc)
40
40
  end
41
41
 
42
42
  def file_colon_line
@@ -50,6 +50,24 @@ module Cucumber
50
50
  def text_length
51
51
  @step_definition.text_length
52
52
  end
53
+
54
+ def replace_arguments(string, step_arguments, format, &proc)
55
+ s = string.dup
56
+ offset = 0
57
+ step_arguments.each do |step_argument|
58
+ replacement = if block_given?
59
+ proc.call(step_argument.val)
60
+ elsif Proc === format
61
+ format.call(step_argument.val)
62
+ else
63
+ format % step_argument.val
64
+ end
65
+
66
+ s[step_argument.pos + offset, step_argument.val.jlength] = replacement
67
+ offset += replacement.length - step_argument.val.jlength
68
+ end
69
+ s
70
+ end
53
71
  end
54
72
 
55
73
  class NoStepMatch #:nodoc:
@@ -3,7 +3,7 @@ module Cucumber #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
5
  TINY = 102
6
- PATCH = nil # Set to nil for official release
6
+ PATCH = 1 # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
9
9
  end
@@ -3,6 +3,20 @@ ENV["RAILS_ENV"] ||= "cucumber"
3
3
  require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
4
4
  require 'cucumber/rails/world'
5
5
 
6
+ # Whether or not to run each scenario within a database transaction.
7
+ #
8
+ # If you leave this to true, you can turn off traqnsactions on a
9
+ # per-scenario basis, simply tagging it with @no-txn
10
+ Cucumber::Rails::World.use_transactional_fixtures = true
11
+
12
+ # Whether or not to allow Rails to rescue errors and render them on
13
+ # an error page. Default is false, which will cause an error to be
14
+ # raised.
15
+ #
16
+ # If you leave this to false, you can turn on Rails rescuing on a
17
+ # per-scenario basis, simply tagging it with @allow-rescue
18
+ ActionController::Base.allow_rescue = false
19
+
6
20
  # Comment out the next line if you don't want Cucumber Unicode support
7
21
  require 'cucumber/formatter/unicode'
8
22
 
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/rb_support/regexp_argument_matcher'
3
+
4
+ module Cucumber
5
+ module RbSupport
6
+ describe RegexpArgumentMatcher do
7
+ it "should create 2 arguments" do
8
+ arguments = RegexpArgumentMatcher.arguments_from(/I (\w+) (\w+)/, "I like fish")
9
+ arguments.map{|argument| [argument.val, argument.pos]}.should == [["like", 2], ["fish", 7]]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'cucumber/rb_support/rb_step_definition'
3
+ require 'cucumber/rb_support/rb_language'
4
+
5
+ module Cucumber
6
+ describe StepMatch do
7
+ before do
8
+ @rb_language = RbSupport::RbLanguage.new(nil)
9
+ end
10
+
11
+ def stepdef(regexp)
12
+ RbSupport::RbStepDefinition.new(@rb_language, regexp, lambda{})
13
+ end
14
+
15
+ it "should format groups with format string" do
16
+ m = stepdef(/I (\w+) (\d+) (\w+) this (\w+)/).step_match("I ate 1 egg this morning", nil)
17
+ m.format_args("<span>%s</span>").should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
18
+ end
19
+
20
+ it "should format groups with format string when there are dupes" do
21
+ m = stepdef(/I (\w+) (\d+) (\w+) this (\w+)/).step_match("I bob 1 bo this bobs", nil)
22
+ m.format_args("<span>%s</span>").should == "I <span>bob</span> <span>1</span> <span>bo</span> this <span>bobs</span>"
23
+ end
24
+
25
+ it "should format groups with block" do
26
+ m = stepdef(/I (\w+) (\d+) (\w+) this (\w+)/).step_match("I ate 1 egg this morning", nil)
27
+ m.format_args(&lambda{|m| "<span>#{m}</span>"}).should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
28
+ end
29
+
30
+ it "should format groups with proc object" do
31
+ m = stepdef(/I (\w+) (\d+) (\w+) this (\w+)/).step_match("I ate 1 egg this morning", nil)
32
+ m.format_args(lambda{|m| "<span>#{m}</span>"}).should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aslakhellesoy-cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.102
4
+ version: 0.3.102.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Aslak Helles\xC3\xB8y"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-22 00:00:00 -07:00
12
+ date: 2009-09-23 00:00:00 -07:00
13
13
  default_executable: cucumber
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -463,13 +463,14 @@ files:
463
463
  - lib/cucumber/rails/world.rb
464
464
  - lib/cucumber/rake/task.rb
465
465
  - lib/cucumber/rb_support/rb_dsl.rb
466
- - lib/cucumber/rb_support/rb_group.rb
467
466
  - lib/cucumber/rb_support/rb_hook.rb
468
467
  - lib/cucumber/rb_support/rb_language.rb
469
468
  - lib/cucumber/rb_support/rb_step_definition.rb
470
469
  - lib/cucumber/rb_support/rb_transform.rb
471
470
  - lib/cucumber/rb_support/rb_world.rb
471
+ - lib/cucumber/rb_support/regexp_argument_matcher.rb
472
472
  - lib/cucumber/rspec_neuter.rb
473
+ - lib/cucumber/step_argument.rb
473
474
  - lib/cucumber/step_match.rb
474
475
  - lib/cucumber/step_mother.rb
475
476
  - lib/cucumber/version.rb
@@ -505,7 +506,6 @@ files:
505
506
  - spec/cucumber/cli/options_spec.rb
506
507
  - spec/cucumber/cli/profile_loader_spec.rb
507
508
  - spec/cucumber/core_ext/proc_spec.rb
508
- - spec/cucumber/core_ext/string_spec.rb
509
509
  - spec/cucumber/formatter/ansicolor_spec.rb
510
510
  - spec/cucumber/formatter/color_io_spec.rb
511
511
  - spec/cucumber/formatter/duration_spec.rb
@@ -514,7 +514,9 @@ files:
514
514
  - spec/cucumber/parser/feature_parser_spec.rb
515
515
  - spec/cucumber/parser/table_parser_spec.rb
516
516
  - spec/cucumber/rb_support/rb_step_definition_spec.rb
517
+ - spec/cucumber/rb_support/regexp_argument_matcher_spec.rb
517
518
  - spec/cucumber/sell_cucumbers.feature
519
+ - spec/cucumber/step_match_spec.rb
518
520
  - spec/cucumber/step_mother_spec.rb
519
521
  - spec/cucumber/treetop_parser/empty_feature.feature
520
522
  - spec/cucumber/treetop_parser/empty_scenario.feature
@@ -1,11 +0,0 @@
1
- module Cucumber
2
- module RbSupport
3
- class RbGroup
4
- attr_reader :val, :start
5
-
6
- def initialize(val, start)
7
- @val, @start = val, start
8
- end
9
- end
10
- end
11
- end
@@ -1,41 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'cucumber/core_ext/string'
3
- require 'cucumber/rb_support/rb_group'
4
-
5
- describe String, "#gzub" do
6
- def groups(a)
7
- a.map{|c| Cucumber::RbSupport::RbGroup.new(c[0], c[1])}
8
- end
9
-
10
- it "should format groups with format string" do
11
- "I ate 1 egg this morning".gzub(groups([['ate', 2], ['1', 6], ['egg', 8], ['morning', 17]]), "<span>%s</span>").should ==
12
- "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
13
- end
14
-
15
- it "should format groups with format string when there are dupes" do
16
- "I bob 1 bo this bobs".gzub(groups([['bob', 2], ['1', 6], ['bo', 8], ['bobs', 16]]), "<span>%s</span>").should ==
17
- "I <span>bob</span> <span>1</span> <span>bo</span> this <span>bobs</span>"
18
- end
19
-
20
- it "should format groups with block" do
21
- f = "I ate 1 egg this morning".gzub(groups([['ate', 2], ['1', 6], ['egg', 8], ['morning', 17]])) do |m|
22
- "<span>#{m}</span>"
23
- end
24
- f.should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
25
- end
26
-
27
- it "should format groups with proc object" do
28
- proc = lambda do |m|
29
- "<span>#{m}</span>"
30
- end
31
- f = "I ate 1 egg this morning".gzub(groups([['ate', 2], ['1', 6], ['egg', 8], ['morning', 17]]), proc)
32
- f.should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
33
- end
34
-
35
- it "should format groups with block with not all placeholders having a value" do
36
- f = "another member named Bob joins the group".gzub(groups([['another', 0], ['member', 8], ['Bob', 21]])) do |m|
37
- "<span>#{m}</span>"
38
- end
39
- f.should == "<span>another</span> <span>member</span> named <span>Bob</span> joins the group"
40
- end
41
- end