rspec 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +125 -9
- data/EXAMPLES.rd +50 -27
- data/README +14 -1
- data/Rakefile +95 -42
- data/UPGRADE +31 -0
- data/bin/spec +0 -1
- data/bin/spec_translator +6 -0
- data/examples/auto_spec_description_example.rb +19 -0
- data/examples/{setup_teardown_example.rb → before_and_after_example.rb} +6 -6
- data/examples/behave_as_example.rb +45 -0
- data/examples/custom_expectation_matchers.rb +13 -12
- data/examples/dynamic_spec.rb +2 -2
- data/examples/file_accessor_spec.rb +2 -2
- data/examples/greeter_spec.rb +3 -3
- data/examples/helper_method_example.rb +2 -2
- data/examples/io_processor_spec.rb +4 -4
- data/examples/legacy_spec.rb +10 -0
- data/examples/mocking_example.rb +5 -5
- data/examples/multi_threaded_behaviour_runner.rb +25 -0
- data/examples/partial_mock_example.rb +4 -4
- data/examples/predicate_example.rb +4 -4
- data/examples/priority.txt +1 -0
- data/examples/shared_behaviours_example.rb +31 -0
- data/examples/stack_spec.rb +52 -69
- data/examples/stubbing_example.rb +10 -10
- data/examples/test_case_adapter_example.rb +26 -0
- data/examples/test_case_spec.rb +6 -6
- data/lib/spec.rb +9 -4
- data/lib/spec/dsl.rb +10 -0
- data/lib/spec/dsl/behaviour.rb +189 -0
- data/lib/spec/dsl/behaviour_callbacks.rb +43 -0
- data/lib/spec/dsl/behaviour_eval.rb +170 -0
- data/lib/spec/dsl/behaviour_factory.rb +32 -0
- data/lib/spec/dsl/composite_proc_builder.rb +28 -0
- data/lib/spec/dsl/configuration.rb +38 -0
- data/lib/spec/dsl/description.rb +34 -0
- data/lib/spec/dsl/example.rb +114 -0
- data/lib/spec/dsl/example_matcher.rb +28 -0
- data/lib/spec/{runner/spec_should_raise_handler.rb → dsl/example_should_raise_handler.rb} +4 -4
- data/lib/spec/expectations.rb +0 -3
- data/lib/spec/expectations/differs/default.rb +0 -1
- data/lib/spec/expectations/extensions.rb +0 -1
- data/lib/spec/expectations/extensions/object.rb +10 -53
- data/lib/spec/expectations/handler.rb +14 -18
- data/lib/spec/extensions.rb +1 -0
- data/lib/spec/extensions/object.rb +6 -0
- data/lib/spec/matchers.rb +19 -21
- data/lib/spec/matchers/be.rb +40 -11
- data/lib/spec/matchers/be_close.rb +2 -2
- data/lib/spec/matchers/operator_matcher.rb +52 -0
- data/lib/spec/matchers/respond_to.rb +21 -11
- data/lib/spec/mocks.rb +5 -28
- data/lib/spec/mocks/argument_constraint_matchers.rb +12 -0
- data/lib/spec/mocks/argument_expectation.rb +7 -4
- data/lib/spec/mocks/methods.rb +11 -16
- data/lib/spec/mocks/mock.rb +6 -3
- data/lib/spec/mocks/{mock_handler.rb → proxy.rb} +4 -7
- data/lib/spec/mocks/space.rb +28 -0
- data/lib/spec/mocks/spec_methods.rb +30 -0
- data/lib/spec/rake/spectask.rb +23 -21
- data/lib/spec/rake/verify_rcov.rb +1 -0
- data/lib/spec/runner.rb +88 -35
- data/lib/spec/runner/backtrace_tweaker.rb +2 -1
- data/lib/spec/runner/behaviour_runner.rb +102 -0
- data/lib/spec/runner/command_line.rb +5 -17
- data/lib/spec/runner/drb_command_line.rb +2 -2
- data/lib/spec/runner/extensions/kernel.rb +22 -9
- data/lib/spec/runner/formatter.rb +4 -0
- data/lib/spec/runner/formatter/base_formatter.rb +63 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +22 -52
- data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +25 -0
- data/lib/spec/runner/formatter/failing_examples_formatter.rb +22 -0
- data/lib/spec/runner/formatter/html_formatter.rb +74 -29
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +6 -8
- data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
- data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +6 -6
- data/lib/spec/runner/heckle_runner.rb +8 -7
- data/lib/spec/runner/option_parser.rb +136 -55
- data/lib/spec/runner/options.rb +26 -0
- data/lib/spec/runner/reporter.rb +38 -31
- data/lib/spec/runner/spec_parser.rb +22 -13
- data/lib/spec/test_case_adapter.rb +10 -0
- data/lib/spec/translator.rb +103 -86
- data/lib/spec/version.rb +7 -15
- data/plugins/mock_frameworks/flexmock.rb +27 -0
- data/plugins/mock_frameworks/mocha.rb +21 -0
- data/plugins/mock_frameworks/rspec.rb +18 -0
- data/spec/spec/dsl/behaviour_eval_spec.rb +49 -0
- data/spec/spec/dsl/behaviour_factory_spec.rb +30 -0
- data/spec/spec/dsl/behaviour_spec.rb +508 -0
- data/spec/spec/dsl/composite_proc_builder_spec.rb +57 -0
- data/spec/spec/dsl/configuration_spec.rb +43 -0
- data/spec/spec/dsl/description_spec.rb +51 -0
- data/spec/spec/dsl/example_class_spec.rb +24 -0
- data/spec/spec/dsl/example_instance_spec.rb +140 -0
- data/spec/spec/dsl/example_should_raise_spec.rb +137 -0
- data/spec/spec/dsl/predicate_matcher_spec.rb +21 -0
- data/spec/spec/dsl/shared_behaviour_spec.rb +186 -0
- data/spec/spec/expectations/differs/default_spec.rb +12 -12
- data/spec/spec/expectations/extensions/object_spec.rb +10 -10
- data/spec/spec/expectations/fail_with_spec.rb +20 -20
- data/spec/spec/matchers/be_close_spec.rb +37 -31
- data/spec/spec/matchers/be_spec.rb +50 -41
- data/spec/spec/matchers/change_spec.rb +54 -54
- data/spec/spec/matchers/description_generation_spec.rb +43 -31
- data/spec/spec/matchers/eql_spec.rb +24 -37
- data/spec/spec/matchers/equal_spec.rb +24 -37
- data/spec/spec/matchers/exist_spec.rb +48 -0
- data/spec/spec/matchers/handler_spec.rb +36 -23
- data/spec/spec/matchers/has_spec.rb +8 -8
- data/spec/spec/matchers/have_spec.rb +38 -38
- data/spec/spec/matchers/include_spec.rb +6 -6
- data/spec/spec/matchers/match_spec.rb +8 -8
- data/spec/spec/matchers/matcher_methods_spec.rb +24 -31
- data/spec/spec/matchers/raise_error_spec.rb +34 -34
- data/spec/spec/matchers/respond_to_spec.rb +32 -8
- data/spec/spec/matchers/satisfy_spec.rb +6 -6
- data/spec/spec/matchers/should_===_spec.rb +38 -0
- data/spec/spec/matchers/should_==_spec.rb +37 -0
- data/spec/spec/matchers/should_=~_spec.rb +36 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +47 -55
- data/spec/spec/mocks/any_number_of_times_spec.rb +16 -21
- data/spec/spec/mocks/argument_expectation_spec.rb +3 -3
- data/spec/spec/mocks/at_least_spec.rb +30 -30
- data/spec/spec/mocks/at_most_spec.rb +53 -57
- data/spec/spec/mocks/bug_report_10260_spec.rb +8 -0
- data/spec/spec/mocks/bug_report_7611_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_7805_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_8165_spec.rb +5 -5
- data/spec/spec/mocks/bug_report_8302_spec.rb +5 -5
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +26 -27
- data/spec/spec/mocks/mock_ordering_spec.rb +19 -15
- data/spec/spec/mocks/mock_space_spec.rb +54 -0
- data/spec/spec/mocks/mock_spec.rb +111 -141
- data/spec/spec/mocks/multiple_return_value_spec.rb +48 -48
- data/spec/spec/mocks/null_object_mock_spec.rb +10 -10
- data/spec/spec/mocks/once_counts_spec.rb +32 -35
- data/spec/spec/mocks/options_hash_spec.rb +12 -10
- data/spec/spec/mocks/partial_mock_spec.rb +15 -15
- data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +24 -22
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +19 -19
- data/spec/spec/mocks/precise_counts_spec.rb +28 -32
- data/spec/spec/mocks/record_messages_spec.rb +10 -10
- data/spec/spec/mocks/stub_spec.rb +45 -45
- data/spec/spec/mocks/twice_counts_spec.rb +21 -21
- data/spec/spec/package/bin_spec_spec.rb +12 -0
- data/spec/spec/runner/behaviour_runner_spec.rb +114 -0
- data/spec/spec/runner/command_line_spec.rb +8 -8
- data/spec/spec/runner/context_matching_spec.rb +14 -15
- data/spec/spec/runner/drb_command_line_spec.rb +12 -12
- data/spec/spec/runner/execution_context_spec.rb +8 -29
- data/spec/spec/runner/extensions/kernel_spec.rb +36 -0
- data/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb +27 -0
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +28 -0
- data/spec/spec/runner/formatter/html_formatter_spec.rb +9 -8
- data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +6 -6
- data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +10 -10
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +22 -27
- data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +6 -5
- data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +17 -17
- data/spec/spec/runner/formatter/snippet_extractor_spec.rb +11 -0
- data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +6 -6
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +17 -17
- data/spec/spec/runner/heckle_runner_spec.rb +21 -21
- data/spec/spec/runner/heckler_spec.rb +5 -5
- data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +12 -12
- data/spec/spec/runner/object_ext_spec.rb +3 -3
- data/spec/spec/runner/option_parser_spec.rb +171 -102
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +21 -12
- data/spec/spec/runner/reporter_spec.rb +106 -97
- data/spec/spec/runner/spec_matcher_spec.rb +46 -51
- data/spec/spec/runner/spec_parser_spec.rb +72 -16
- data/spec/spec/spec_classes.rb +12 -3
- data/spec/spec/translator_spec.rb +165 -36
- metadata +66 -76
- data/RELEASE-PLAN +0 -117
- data/examples/auto_spec_name_generation_example.rb +0 -18
- data/lib/spec/callback.rb +0 -11
- data/lib/spec/callback/callback_container.rb +0 -60
- data/lib/spec/callback/extensions/module.rb +0 -24
- data/lib/spec/callback/extensions/object.rb +0 -37
- data/lib/spec/deprecated.rb +0 -3
- data/lib/spec/expectations/extensions/proc.rb +0 -57
- data/lib/spec/expectations/should.rb +0 -5
- data/lib/spec/expectations/should/base.rb +0 -64
- data/lib/spec/expectations/should/change.rb +0 -69
- data/lib/spec/expectations/should/have.rb +0 -128
- data/lib/spec/expectations/should/not.rb +0 -74
- data/lib/spec/expectations/should/should.rb +0 -81
- data/lib/spec/expectations/sugar.rb +0 -47
- data/lib/spec/runner/context.rb +0 -154
- data/lib/spec/runner/context_eval.rb +0 -142
- data/lib/spec/runner/context_runner.rb +0 -55
- data/lib/spec/runner/execution_context.rb +0 -17
- data/lib/spec/runner/spec_matcher.rb +0 -25
- data/lib/spec/runner/specification.rb +0 -114
- data/spec/spec/callback/callback_container_spec.rb +0 -27
- data/spec/spec/callback/module_spec.rb +0 -37
- data/spec/spec/callback/object_spec.rb +0 -90
- data/spec/spec/callback/object_with_class_callback_spec.rb +0 -19
- data/spec/spec/expectations/should/should_==_spec.rb +0 -19
- data/spec/spec/expectations/should/should_=~_spec.rb +0 -13
- data/spec/spec/expectations/should/should_be_a_kind_of_spec.rb +0 -21
- data/spec/spec/expectations/should/should_be_an_instance_of_spec.rb +0 -30
- data/spec/spec/expectations/should/should_be_arbitrary_predicate_spec.rb +0 -81
- data/spec/spec/expectations/should/should_be_close_spec.rb +0 -18
- data/spec/spec/expectations/should/should_be_comparison_operator_spec.rb +0 -44
- data/spec/spec/expectations/should/should_be_false_spec.rb +0 -39
- data/spec/spec/expectations/should/should_be_spec.rb +0 -11
- data/spec/spec/expectations/should/should_be_true_spec.rb +0 -27
- data/spec/spec/expectations/should/should_change_spec.rb +0 -184
- data/spec/spec/expectations/should/should_eql_spec.rb +0 -11
- data/spec/spec/expectations/should/should_equal_spec.rb +0 -11
- data/spec/spec/expectations/should/should_have_at_least_spec.rb +0 -53
- data/spec/spec/expectations/should/should_have_at_most_spec.rb +0 -45
- data/spec/spec/expectations/should/should_have_key_spec.rb +0 -21
- data/spec/spec/expectations/should/should_have_spec.rb +0 -64
- data/spec/spec/expectations/should/should_include_spec.rb +0 -59
- data/spec/spec/expectations/should/should_match_spec.rb +0 -25
- data/spec/spec/expectations/should/should_not_==_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_be_a_kind_of_spec.rb +0 -21
- data/spec/spec/expectations/should/should_not_be_an_instance_of_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_be_arbitrary_predicate_spec.rb +0 -68
- data/spec/spec/expectations/should/should_not_be_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_change_spec.rb +0 -24
- data/spec/spec/expectations/should/should_not_eql_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_equal_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_have_key_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_include_spec.rb +0 -58
- data/spec/spec/expectations/should/should_not_match_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_raise_spec.rb +0 -75
- data/spec/spec/expectations/should/should_not_respond_to_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_throw_spec.rb +0 -35
- data/spec/spec/expectations/should/should_raise_spec.rb +0 -66
- data/spec/spec/expectations/should/should_respond_to_spec.rb +0 -15
- data/spec/spec/expectations/should/should_satisfy_spec.rb +0 -35
- data/spec/spec/expectations/should/should_throw_spec.rb +0 -27
- data/spec/spec/runner/context_runner_spec.rb +0 -100
- data/spec/spec/runner/context_spec.rb +0 -405
- data/spec/spec/runner/kernel_ext_spec.rb +0 -16
- data/spec/spec/runner/spec_name_generation_spec.rb +0 -102
- data/spec/spec/runner/specification_class_spec.rb +0 -72
- data/spec/spec/runner/specification_instance_spec.rb +0 -160
- data/spec/spec/runner/specification_should_raise_spec.rb +0 -136
data/UPGRADE
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= Upgrading existing code to RSpec-0.9
|
2
|
+
|
3
|
+
== General (see below for Spec::Rails specifics)
|
4
|
+
|
5
|
+
=== New Syntax for should and should_not
|
6
|
+
|
7
|
+
* Use translator (should get 90% of your code)
|
8
|
+
* Manually fix "parenthesis" warnings
|
9
|
+
|
10
|
+
=== Change before_context_eval to before_eval
|
11
|
+
|
12
|
+
before_context_eval is an un-published hook used by
|
13
|
+
Spec::Rails to create specialized behaviour contexts.
|
14
|
+
Most of you don't need to change this, but for those
|
15
|
+
who have exploited it, you'll need to change it to
|
16
|
+
before_eval.
|
17
|
+
|
18
|
+
== Spec::Rails
|
19
|
+
|
20
|
+
=== spec_helper.rb
|
21
|
+
|
22
|
+
We've added a new way to configure Spec::Runner to do
|
23
|
+
things like use_transactional_fixtures and use_instantiated_fixtures.
|
24
|
+
You'll need to update spec/spec_helper.rb accordingly. You can either
|
25
|
+
just re-generate it:
|
26
|
+
|
27
|
+
script/generate rspec
|
28
|
+
|
29
|
+
Or modify spec_helper.rb based on the template, which can be found at:
|
30
|
+
|
31
|
+
vendor/plugins/rspec_on_rails/generators/rspec/templates/spec_helper.rb
|
data/bin/spec
CHANGED
data/bin/spec_translator
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
# Run spec w/ -fs to see the output of this file
|
4
|
+
|
5
|
+
describe "Examples with no descriptions" do
|
6
|
+
|
7
|
+
# description is auto-generated as "should equal(5)" based on the last #should
|
8
|
+
it do
|
9
|
+
3.should equal(3)
|
10
|
+
5.should equal(5)
|
11
|
+
end
|
12
|
+
|
13
|
+
it { 3.should be < 5 }
|
14
|
+
|
15
|
+
it { ["a"].should include("a") }
|
16
|
+
|
17
|
+
it { [1,2,3].should respond_to(:size) }
|
18
|
+
|
19
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
$global = 0
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
describe "State created in before(:all)" do
|
4
|
+
before :all do
|
5
5
|
@sideeffect = 1
|
6
6
|
$global +=1
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
before :each do
|
10
10
|
@isolated = 1
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
it "should be accessible from example" do
|
14
14
|
@sideeffect.should == 1
|
15
15
|
$global.should == 1
|
16
16
|
@isolated.should == 1
|
@@ -19,7 +19,7 @@ context "State created in context_setup" do
|
|
19
19
|
@isolated += 1
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
it "should not have sideffects" do
|
23
23
|
@sideeffect.should == 1
|
24
24
|
$global.should == 1
|
25
25
|
@isolated.should == 1
|
@@ -28,7 +28,7 @@ context "State created in context_setup" do
|
|
28
28
|
@isolated += 1
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
after :all do
|
32
32
|
$global = 0
|
33
33
|
end
|
34
34
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
def behave_as_electric_musician
|
4
|
+
respond_to(:read_notes, :turn_down_amp)
|
5
|
+
end
|
6
|
+
|
7
|
+
def behave_as_musician
|
8
|
+
respond_to(:read_notes)
|
9
|
+
end
|
10
|
+
|
11
|
+
module BehaveAsExample
|
12
|
+
|
13
|
+
class BluesGuitarist
|
14
|
+
def read_notes; end
|
15
|
+
def turn_down_amp; end
|
16
|
+
end
|
17
|
+
|
18
|
+
class RockGuitarist
|
19
|
+
def read_notes; end
|
20
|
+
def turn_down_amp; end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ClassicGuitarist
|
24
|
+
def read_notes; end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe BluesGuitarist do
|
28
|
+
it "should behave as guitarist" do
|
29
|
+
BluesGuitarist.new.should behave_as_electric_musician
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe RockGuitarist do
|
34
|
+
it "should behave as guitarist" do
|
35
|
+
RockGuitarist.new.should behave_as_electric_musician
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe ClassicGuitarist do
|
40
|
+
it "should not behave as guitarist" do
|
41
|
+
ClassicGuitarist.new.should behave_as_musician
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -35,19 +35,20 @@ module Animals
|
|
35
35
|
[:cheese]
|
36
36
|
end
|
37
37
|
end
|
38
|
-
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
describe Mouse do
|
40
|
+
include AnimalSpecHelper
|
41
|
+
before(:each) do
|
42
|
+
@mouse = Animals::Mouse.new
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
it "should eat cheese" do
|
46
|
+
@mouse.should eat(:cheese)
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
49
|
+
it "should not eat cat" do
|
50
|
+
@mouse.should_not eat(:cat)
|
51
|
+
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
|
+
end
|
data/examples/dynamic_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe "Some integers" do
|
4
4
|
(1..10).each do |n|
|
5
|
-
|
5
|
+
it "The root of #{n} square should be #{n}" do
|
6
6
|
Math.sqrt(n*n).should == n
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
require File.dirname(__FILE__) + '/file_accessor'
|
3
3
|
require 'stringio'
|
4
4
|
|
5
|
-
|
5
|
+
describe "A FileAccessor" do
|
6
6
|
# This sequence diagram illustrates what this spec specifies.
|
7
7
|
#
|
8
8
|
# +--------------+ +----------+ +-------------+
|
@@ -20,7 +20,7 @@ context "A FileAccessor" do
|
|
20
20
|
# | |<..................................| |
|
21
21
|
# | | |
|
22
22
|
#
|
23
|
-
|
23
|
+
it "should open a file and pass it to the processor's process method" do
|
24
24
|
# This is the primary actor
|
25
25
|
accessor = FileAccessor.new
|
26
26
|
|
data/examples/greeter_spec.rb
CHANGED
@@ -16,13 +16,13 @@ class Greeter
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
describe "Greeter" do
|
20
|
+
it "should say Hi to person" do
|
21
21
|
greeter = Greeter.new("Kevin")
|
22
22
|
greeter.greet.should == "Hi Kevin!"
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
it "should say Hi to nobody" do
|
26
26
|
greeter = Greeter.new
|
27
27
|
# Uncomment the next line to make Heckle happy
|
28
28
|
#greeter.greet.should == "Hi there!"
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe "a context with helper a method" do
|
4
4
|
def helper_method
|
5
5
|
"received call"
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
it "should make that method available to specs" do
|
9
9
|
helper_method.should == "received call"
|
10
10
|
end
|
11
11
|
end
|
@@ -2,18 +2,18 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
require File.dirname(__FILE__) + '/io_processor'
|
3
3
|
require 'stringio'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
describe "An IoProcessor" do
|
6
|
+
before(:each) do
|
7
7
|
@processor = IoProcessor.new
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
it "should raise nothing when the file is exactly 32 bytes" do
|
11
11
|
lambda {
|
12
12
|
@processor.process(StringIO.new("z"*32))
|
13
13
|
}.should_not raise_error
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
it "should raise an exception when the file length is less than 32 bytes" do
|
17
17
|
lambda {
|
18
18
|
@processor.process(StringIO.new("z"*31))
|
19
19
|
}.should raise_error(DataTooShort)
|
data/examples/mocking_example.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
describe "A consumer of a mock" do
|
4
|
+
it "should be able to send messages to the mock" do
|
5
5
|
mock = mock("poke me")
|
6
6
|
mock.should_receive(:poke)
|
7
7
|
mock.poke
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
describe "a mock" do
|
12
|
+
it "should be able to mock the same message twice w/ different args" do
|
13
13
|
mock = mock("mock")
|
14
14
|
mock.should_receive(:msg).with(:arg1).and_return(:val1)
|
15
15
|
mock.should_receive(:msg).with(:arg2).and_return(:val2)
|
@@ -17,7 +17,7 @@ context "a mock" do
|
|
17
17
|
mock.msg(:arg2).should eql(:val2)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
it "should be able to mock the same message twice w/ different args in reverse order" do
|
21
21
|
mock = mock("mock")
|
22
22
|
mock.should_receive(:msg).with(:arg1).and_return(:val1)
|
23
23
|
mock.should_receive(:msg).with(:arg2).and_return(:val2)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
class MultiThreadedBehaviourRunner < Spec::Runner::BehaviourRunner
|
3
|
+
def initialize(options)
|
4
|
+
super
|
5
|
+
# configure these
|
6
|
+
@thread_count = 4
|
7
|
+
@thread_wait = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_behaviours(behaviours)
|
11
|
+
@threads = []
|
12
|
+
q = Queue.new
|
13
|
+
behaviours.each { |b| q << b}
|
14
|
+
@thread_count.times do
|
15
|
+
@threads << Thread.new(q) do |queue|
|
16
|
+
while not queue.empty?
|
17
|
+
behaviour = queue.pop
|
18
|
+
behaviour.run(@options.reporter, @options.dry_run, @options.reverse)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
sleep @thread_wait
|
22
|
+
end
|
23
|
+
@threads.each {|t| t.join}
|
24
|
+
end
|
25
|
+
end
|
@@ -6,18 +6,18 @@ class MockableClass
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
describe "A partial mock" do
|
10
10
|
|
11
|
-
|
11
|
+
it "should work at the class level" do
|
12
12
|
MockableClass.should_receive(:find).with(1).and_return {:stub_return}
|
13
13
|
MockableClass.find(1).should equal(:stub_return)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
it "should revert to the original after each spec" do
|
17
17
|
MockableClass.find(1).should equal(:original_return)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
it "can be mocked w/ ordering" do
|
21
21
|
MockableClass.should_receive(:msg_1).ordered
|
22
22
|
MockableClass.should_receive(:msg_2).ordered
|
23
23
|
MockableClass.should_receive(:msg_3).ordered
|
@@ -10,17 +10,17 @@ class BddFramework
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
describe "BDD framework" do
|
14
14
|
|
15
|
-
|
15
|
+
before(:each) do
|
16
16
|
@bdd_framework = BddFramework.new
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
it "should be adopted quickly" do
|
20
20
|
@bdd_framework.should be_adopted_quickly
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
it "should be intuitive" do
|
24
24
|
@bdd_framework.should be_intuitive
|
25
25
|
end
|
26
26
|
|
@@ -0,0 +1 @@
|
|
1
|
+
examples/custom_expectation_matchers.rb
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
module SharedBehaviourExample
|
4
|
+
class OneThing
|
5
|
+
def what_things_do
|
6
|
+
"stuff"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class AnotherThing
|
11
|
+
def what_things_do
|
12
|
+
"stuff"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "All Things", :shared => true do
|
17
|
+
it "should do what things do" do
|
18
|
+
@thing.what_things_do.should == "stuff"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe OneThing do
|
23
|
+
it_should_behave_like "All Things"
|
24
|
+
before(:each) { @thing = OneThing.new }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe AnotherThing do
|
28
|
+
it_should_behave_like "All Things"
|
29
|
+
before(:each) { @thing = AnotherThing.new }
|
30
|
+
end
|
31
|
+
end
|
data/examples/stack_spec.rb
CHANGED
@@ -1,113 +1,96 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
require File.dirname(__FILE__) + "/stack"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
["a","b","c"].each { |x| @stack.push x }
|
8
|
-
end
|
4
|
+
describe "non-empty Stack", :shared => true do
|
5
|
+
# NOTE that this one auto-generates the description "should not be empty"
|
6
|
+
it { @stack.should_not be_empty }
|
9
7
|
|
10
|
-
|
11
|
-
@stack.
|
12
|
-
@stack.peek.should == "d"
|
8
|
+
it "should return the top item when sent #peek" do
|
9
|
+
@stack.peek.should == @last_item_added
|
13
10
|
end
|
14
|
-
|
15
|
-
|
16
|
-
@stack.peek.should ==
|
11
|
+
|
12
|
+
it "should NOT remove the top item when sent #peek" do
|
13
|
+
@stack.peek.should == @last_item_added
|
14
|
+
@stack.peek.should == @last_item_added
|
17
15
|
end
|
18
16
|
|
19
|
-
|
20
|
-
@stack.
|
21
|
-
@stack.peek.should == "c"
|
17
|
+
it "should return the top item when sent #pop" do
|
18
|
+
@stack.pop.should == @last_item_added
|
22
19
|
end
|
23
20
|
|
24
|
-
|
25
|
-
@stack.pop.should ==
|
21
|
+
it "should remove the top item when sent #pop" do
|
22
|
+
@stack.pop.should == @last_item_added
|
23
|
+
unless @stack.empty?
|
24
|
+
@stack.pop.should_not == @last_item_added
|
25
|
+
end
|
26
26
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "non-full Stack", :shared => true do
|
30
|
+
# NOTE that this one auto-generates the description "should not be full"
|
31
|
+
it { @stack.should_not be_full }
|
32
|
+
|
33
|
+
it "should add to the top when sent #push" do
|
34
|
+
@stack.push "newly added top item"
|
35
|
+
@stack.peek.should == "newly added top item"
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
34
|
-
|
35
|
-
|
39
|
+
describe Stack, " (empty)" do
|
40
|
+
before(:each) do
|
36
41
|
@stack = Stack.new
|
37
42
|
end
|
38
43
|
|
39
|
-
# NOTE that this one auto-generates the description "should
|
40
|
-
|
44
|
+
# NOTE that this one auto-generates the description "should be empty"
|
45
|
+
it { @stack.should be_empty }
|
41
46
|
|
42
|
-
|
43
|
-
@stack.push "anything"
|
44
|
-
@stack.should_not be_empty
|
45
|
-
end
|
47
|
+
it_should_behave_like "non-full Stack"
|
46
48
|
|
47
|
-
|
49
|
+
it "should complain when sent #peek" do
|
48
50
|
lambda { @stack.peek }.should raise_error(StackUnderflowError)
|
49
51
|
end
|
50
52
|
|
51
|
-
|
53
|
+
it "should complain when sent #pop" do
|
52
54
|
lambda { @stack.pop }.should raise_error(StackUnderflowError)
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
+
describe Stack, " (with one item)" do
|
59
|
+
before(:each) do
|
58
60
|
@stack = Stack.new
|
59
61
|
@stack.push 3
|
62
|
+
@last_item_added = 3
|
60
63
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
specify "should remain not empty after #peek" do
|
66
|
-
@stack.peek
|
67
|
-
@stack.should_not be_empty
|
68
|
-
end
|
69
|
-
|
70
|
-
specify "should become empty after #pop" do
|
71
|
-
@stack.pop
|
72
|
-
@stack.should be_empty
|
73
|
-
end
|
64
|
+
|
65
|
+
it_should_behave_like "non-empty Stack"
|
66
|
+
it_should_behave_like "non-full Stack"
|
67
|
+
|
74
68
|
end
|
75
69
|
|
76
|
-
|
77
|
-
|
70
|
+
describe Stack, " (with one item less than capacity)" do
|
71
|
+
before(:each) do
|
78
72
|
@stack = Stack.new
|
79
73
|
(1..9).each { |i| @stack.push i }
|
74
|
+
@last_item_added = 9
|
80
75
|
end
|
81
76
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
specify "should become full when sent #push" do
|
86
|
-
@stack.push Object.new
|
87
|
-
@stack.should be_full
|
88
|
-
end
|
77
|
+
it_should_behave_like "non-empty Stack"
|
78
|
+
it_should_behave_like "non-full Stack"
|
89
79
|
end
|
90
80
|
|
91
|
-
|
92
|
-
|
81
|
+
describe Stack, " (full)" do
|
82
|
+
before(:each) do
|
93
83
|
@stack = Stack.new
|
94
84
|
(1..10).each { |i| @stack.push i }
|
85
|
+
@last_item_added = 10
|
95
86
|
end
|
96
|
-
|
87
|
+
|
97
88
|
# NOTE that this one auto-generates the description "should be full"
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
@stack.peek
|
102
|
-
@stack.should be_full
|
103
|
-
end
|
104
|
-
|
105
|
-
specify "should no longer be full after #pop" do
|
106
|
-
@stack.pop
|
107
|
-
@stack.should_not be_full
|
108
|
-
end
|
89
|
+
it { @stack.should be_full }
|
90
|
+
|
91
|
+
it_should_behave_like "non-empty Stack"
|
109
92
|
|
110
|
-
|
93
|
+
it "should complain on #push" do
|
111
94
|
lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
|
112
95
|
end
|
113
96
|
end
|