Title: [jbehave] [581] rbehave/trunk/rbehave: [dn] rbehave: replaced Given, When, Then methods with _given, _when, _then,
Revision
581
Author
tastapod
Date
2006-11-26 16:18:56 -0600 (Sun, 26 Nov 2006)

Log Message

[dn] rbehave: replaced Given, When, Then methods with _given, _when, _then,
which is less pretty but more consistent. Annoyingly Matz reserved
"when" and "then" a while ago.

Modified Paths

Diff

Modified: rbehave/trunk/rbehave/behaviour/behaviour_behaviour.rb (580 => 581)

--- rbehave/trunk/rbehave/behaviour/behaviour_behaviour.rb	2006-11-24 00:00:23 UTC (rev 580)
+++ rbehave/trunk/rbehave/behaviour/behaviour_behaviour.rb	2006-11-26 22:18:56 UTC (rev 581)
@@ -4,93 +4,93 @@
   include RBehave
   
   def should_succeed_when_Given_When_Then_invoked_in_correct_order
-    Given {
+    _given {
       @b = Behaviour.new
     }
-    When {
-      @b.Given {}
-      @b.When {}
-      @b.Then {}
+    _when {
+      @b._given {}
+      @b._when {}
+      @b._then {}
     }
-    Then {
+    _then {
       ensure_succeeded
     }
   end
 
   def should_fail_in_When_unless_Given_was_invoked
-    Given {
+    _given {
       @b = Behaviour.new
     }
-    When {
-      @b.When {}
+    _when {
+      @b._when {}
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
 
   def should_fail_in_Then_unless_When_was_invoked
-    Given {
+    _given {
       @b = Behaviour.new
     }
-    When {
-      @b.Then {}
+    _when {
+      @b._then {}
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
   
   def should_fail_if_Given_is_invoked_more_than_once
-    Given {
+    _given {
       @b = Behaviour.new
-      @b.Given {}
+      @b._given {}
     }
-    When {
-      @b.Given {}
+    _when {
+      @b._given {}
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
   
   def should_fail_if_When_is_invoked_more_than_once
-    Given {
+    _given {
       @b = Behaviour.new
-      @b.Given {}
-      @b.When {}
+      @b._given {}
+      @b._when {}
     }
-    When {
-      @b.When {}
+    _when {
+      @b._when {}
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
   
   def should_fail_if_Then_is_invoked_more_than_once
-    Given {
+    _given {
       @b = Behaviour.new
-      @b.Given {}; @b.When {}; @b.Then {}
+      @b._given {}; @b._when {}; @b._then {}
     }
-    When {
-      @b.Then {}
+    _when {
+      @b._then {}
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
   
   def should_fail_if_sections_are_called_in_wrong_order
-    Given {
+    _given {
       @b = Behaviour.new
     }
     
-    When {
-      @b.Given {}; @b.Then {}; @b.When {}
+    _when {
+      @b._given {}; @b._then {}; @b._when {}
     }
 
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
@@ -99,29 +99,29 @@
   class ThenFailed < StandardError; end
   
   def should_report_exception_from_Then_block_if_When_and_Then_both_fail
-    Given {
+    _given {
       @b = Behaviour.new
-      @b.Given{}
-      @b.When { raise WhenFailed }
+      @b._given{}
+      @b._when { raise WhenFailed }
     }
-    When {
-      @b.Then { raise ThenFailed }
+    _when {
+      @b._then { raise ThenFailed }
     }
-    Then {
+    _then {
       ensure_raised ThenFailed
     }
   end
   
   def should_reraise_exception_in_Then_block_if_When_failed_with_an_unexpected_error
-    Given {
+    _given {
       @b = Behaviour.new
-      @b.Given{}
-      @b.When { raise WhenFailed }
+      @b._given{}
+      @b._when { raise WhenFailed }
     }
-    When {
-      @b.Then {} # doesn't check for WhenFailed
+    _when {
+      @b._then {} # doesn't check for WhenFailed
     }
-    Then {
+    _then {
       ensure_raised WhenFailed
     }
   end

Modified: rbehave/trunk/rbehave/behaviour/expectation_behaviour.rb (580 => 581)

--- rbehave/trunk/rbehave/behaviour/expectation_behaviour.rb	2006-11-24 00:00:23 UTC (rev 580)
+++ rbehave/trunk/rbehave/behaviour/expectation_behaviour.rb	2006-11-26 22:18:56 UTC (rev 581)
@@ -11,103 +11,103 @@
   
   # mockFoo.expects.upcase("word").never
   def should_fail_when_called_if_expecting_never_to_be_called
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase)
       @expectation.never
     }
-    When {
+    _when {
       @expectation.call("hello")
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
   
   # mockFoo.expects.upcase("word").never
   def should_verify_ok_if_expecting_never_and_was_never_called
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase)
       @expectation.never
     }
-    When {
+    _when {
       @expectation.verify
     }
-    Then {
+    _then {
       ensure_succeeded
     }
   end
   
   # mockFoo.expects.upcase("word")
   def should_match_correct_method_name_with_no_args
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase)
     }
-    When {
-      @result = @expectation.matches(:upcase1)
+    _when {
+      @result = @expectation.matches(:upcase)
     }
-    Then {
+    _then {
       ensure_that @result, is(true)
     }
   end
   
   # mockFoo.expects.upcase("word")
   def should_match_correct_method_name_with_args
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase).with("hello")
     }
-    When {
+    _when {
       @result = @expectation.matches(:upcase, "hello")
     }
-    Then {
+    _then {
       ensure_that @result, is(true)
     }
   end
   
   def should_not_match_correct_method_name_with_incorrect_args
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase).with("hello")
     }
-    When {
+    _when {
       @result = @expectation.matches(:upcase, "goodbye")
     }
-    Then {
+    _then {
       ensure_that @result, is(false)
     }
   end
   
   def should_match_correct_method_name_with_args_when_none_explicitly_specified
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase)
     }
-    When {
+    _when {
       @result = @expectation.matches(:upcase, "hello")
     }
-    Then {
+    _then {
       ensure_that @result, is(true)
     }
   end
 
   def should_not_match_correct_method_name_with_args_when_no_args_explicitly_set
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase).with_no_arguments
     }
-    When {
+    _when {
       @result = @expectation.matches(:upcase, "hello")
     }
-    Then {
+    _then {
       ensure_that @result, is(false)
     }
   end
   
   # mockFoo.expects.upcase("word")
   def should_not_match_different_method_name
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase)
     }
-    When {
+    _when {
       @result = @expectation.matches(:different)
     }
-    Then {
+    _then {
       ensure_that @result, is(false)
     }
   end
@@ -121,77 +121,77 @@
   # end
   #
   def should_return_preset_value_when_invoked
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase).with("hello").will_return("HELLO")
     }
-    When {
+    _when {
       @result = @expectation.call("hello")
     }
-    Then {
+    _then {
       ensure_that @result, is("HELLO")
     }
   end
 
   def should_fail_if_called_more_times_than_expected
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase).with("hello").once()
       @expectation.call("hello")
     }
-    When {
+    _when {
       @expectation.call("hello")
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
   
   def should_fail_if_called_fewer_times_than_expected
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase).with("hello").once()
     }
-    When {
+    _when {
       @expectation.verify
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
 
   def should_allow_number_of_calls_within_expected_range
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase).with("hello").times(1..2)
     }
-    When {
+    _when {
       @expectation.call("hello")  # 1
       @expectation.call("hello")  # 2
     }
-    Then {
+    _then {
       ensure_succeeded
     }
   end
   
   def should_fail_if_fewer_calls_than_within_expected_range
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase).with("hello").times(1..2)
     }
-   When {
+   _when {
       @expectation.verify
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
   
   def should_fail_if_more_calls_than_within_expected_range
-    Given {
+    _given {
       @expectation = Expectation.new(String, :upcase).with("hello").times(1..2)
       @expectation.call("hello")  # 1
       @expectation.call("hello")  # 2
     }
-    When {
+    _when {
       @expectation.call("hello")  # 3
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end

Modified: rbehave/trunk/rbehave/behaviour/mock_behaviour.rb (580 => 581)

--- rbehave/trunk/rbehave/behaviour/mock_behaviour.rb	2006-11-24 00:00:23 UTC (rev 580)
+++ rbehave/trunk/rbehave/behaviour/mock_behaviour.rb	2006-11-26 22:18:56 UTC (rev 581)
@@ -9,121 +9,121 @@
   include RBehave
   
   def should_fail_for_unexpected_method_call
-    Given {
+    _given {
       @sheep = mock(Sheep)
     }
-    When {
+    _when {
       @sheep.baa
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
   
   def should_accept_call_with_no_arguments_when_arguments_unspecified
-    Given {
+    _given {
       @sheep = mock(Sheep)
       @sheep.expects.baa
     }
-    When {
+    _when {
       @sheep.baa
     }
-    Then {
+    _then {
       ensure_succeeded
     }
   end
   
   def should_accept_call_with_one_argument_when_arguments_unspecified
-    Given {
+    _given {
       @sheep = mock(Sheep)
       @sheep.expects.chew_grass
     }
-    When {
+    _when {
       @sheep.chew_grass("A")
     }
-    Then {
+    _then {
       ensure_succeeded
     }
   end
   
   def should_accept_call_with_one_argument_when_argument_is_specified
-    Given {
+    _given {
       @sheep = mock(Sheep)
       @sheep.expects.chew_grass("A")
     }
-    When {
+    _when {
       @sheep.chew_grass("A")
     }
-    Then {
+    _then {
       ensure_succeeded
     }
   end
   
   def should_reject_call_with_incorrect_argument_when_argument_is_specified
-    Given {
+    _given {
       @sheep = mock(Sheep)
       @sheep.expects.chew_grass("A")
     }
-    When {
+    _when {
       @sheep.chew_grass("B")
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
   
   def should_fail_on_verify_if_expected_method_was_not_called
-    Given {
+    _given {
       @sheep = mock(Sheep)
       @sheep.expects.baa
     }
-    When {
+    _when {
       verify_mocks
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end
   
   def should_accept_calls_for_multiple_expectations
-    Given {
+    _given {
       @sheep = mock(Sheep)
       @sheep.expects.baa("A")
       @sheep.expects.chew_grass(_not("A"))
     }
-    When {
+    _when {
       @sheep.baa("A")
       @sheep.chew_grass("B")
     }
-    Then {
+    _then {
       ensure_succeeded
     }
   end
   
   def should_verify_multiple_expectations
-    Given {
+    _given {
       @sheep = mock(Sheep)
       @sheep.expects.baa("A")
       @sheep.expects.chew_grass(_not("A"))
       @sheep.baa("A")
       @sheep.chew_grass("B")
     }
-    When {
+    _when {
       verify_mocks
     }
-    Then {
+    _then {
       ensure_succeeded
     }
   end
   
   def should_not_allow_expectation_for_unknown_method
-    Given {
+    _given {
       @sheep = mock(Sheep)
     }
-    When {
+    _when {
       @sheep.expects.no_such_method
     }
-    Then {
+    _then {
       ensure_raised VerificationError
     }
   end

Modified: rbehave/trunk/rbehave/behaviour/runner_behaviour.rb (580 => 581)

--- rbehave/trunk/rbehave/behaviour/runner_behaviour.rb	2006-11-24 00:00:23 UTC (rev 580)
+++ rbehave/trunk/rbehave/behaviour/runner_behaviour.rb	2006-11-26 22:18:56 UTC (rev 581)
@@ -7,19 +7,19 @@
   class SheepBehaviour < Behaviour
     include RBehave::DoNotAutorun # otherwise it gets run automagically
     def should_baa
-      Given{}; When{}; Then{}
+      _given{}; _when{}; _then{}
     end
   end
   
   def should_tell_listener_when_starting_run
-    Given {
+    _given {
       @listener = mock(Listener)
       @listener.expects.starting_run
     }
-    When {
+    _when {
       Runner.new(@listener)
     }
-    Then {
+    _then {
       verify_mocks
     }
   end

Modified: rbehave/trunk/rbehave/behaviour/text_listener_behaviour.rb (580 => 581)

--- rbehave/trunk/rbehave/behaviour/text_listener_behaviour.rb	2006-11-24 00:00:23 UTC (rev 580)
+++ rbehave/trunk/rbehave/behaviour/text_listener_behaviour.rb	2006-11-26 22:18:56 UTC (rev 581)
@@ -2,11 +2,11 @@
 
 class TextListenerBehaviour < RBehave::Behaviour
   def should_print_dot_when_method_succeeds
-    Given {
+    _given {
     }
-    When {
+    _when {
     }
-    Then {
+    _then {
     }
   end
 end

Modified: rbehave/trunk/rbehave/behaviour.rb (580 => 581)

--- rbehave/trunk/rbehave/behaviour.rb	2006-11-24 00:00:23 UTC (rev 580)
+++ rbehave/trunk/rbehave/behaviour.rb	2006-11-26 22:18:56 UTC (rev 581)
@@ -27,14 +27,14 @@
       @__jbehave_error
     end
     
-    def Given
-      raise VerificationError, "'Given' not expected here" unless @__jbehave_state == :starting
+    def _given
+      raise VerificationError, "'_given' not expected here" unless @__jbehave_state == :starting
       yield
       @__jbehave_state = :done_given
     end
     
-    def When
-      raise VerificationError, "'When' not expected here" unless @__jbehave_state == :done_given
+    def _when
+      raise VerificationError, "'_when' not expected here" unless @__jbehave_state == :done_given
       begin
         yield
       rescue StandardError => e
@@ -43,8 +43,8 @@
       @__jbehave_state = :done_when
     end
     
-    def Then
-      raise VerificationError, "'Then' not expected here" unless @__jbehave_state == :done_when
+    def _then
+      raise VerificationError, "'_then' not expected here" unless @__jbehave_state == :done_when
       begin
         yield
         ensure_succeeded unless @__jbehave_checked_for_failure

Modified: rbehave/trunk/rbehave/runner.rb (580 => 581)

--- rbehave/trunk/rbehave/runner.rb	2006-11-24 00:00:23 UTC (rev 580)
+++ rbehave/trunk/rbehave/runner.rb	2006-11-26 22:18:56 UTC (rev 581)
@@ -20,7 +20,7 @@
         Mocks.clear
         instance = cls.new
         instance.send method
-        raise VerificationError, "#{method}: method does not contain Given/When/Then" unless instance.finished?
+        raise VerificationError, "#{method}: method does not contain _given/_when/_then" unless instance.finished?
         putc '.' # TODO: move this into a listener
       rescue StandardError => error
         putc 'F'


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to