rspec 1.1.12 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +2 -1
- data/.document +7 -0
- data/History.txt +58 -0
- data/License.txt +1 -1
- data/Manifest.txt +45 -82
- data/README.txt +3 -6
- data/Rakefile +33 -13
- data/Ruby1.9.markdown +32 -0
- data/TODO.txt +10 -4
- data/Upgrade.markdown +63 -0
- data/bin/spec +1 -1
- data/cucumber.yml +3 -0
- data/examples/failing/{failing_autogenerated_docstrings_example.rb → failing_implicit_docstrings_example.rb} +0 -0
- data/examples/failing/pending_example.rb +9 -0
- data/examples/failing/spec_helper.rb +1 -1
- data/examples/passing/{custom_expectation_matchers.rb → custom_matchers.rb} +0 -0
- data/examples/passing/filtered_formatter.rb +18 -0
- data/examples/passing/filtered_formatter_example.rb +31 -0
- data/examples/passing/implicit_docstrings_example.rb +18 -0
- data/examples/passing/spec_helper.rb +1 -1
- data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +17 -18
- data/features/before_and_after_blocks/before_and_after_blocks.feature +4 -4
- data/features/example_groups/example_group_with_should_methods.feature +1 -1
- data/features/example_groups/{autogenerated_docstrings.feature → implicit_docstrings.feature} +7 -9
- data/features/example_groups/nested_groups.feature +1 -1
- data/features/heckle/heckle.feature +56 -0
- data/features/interop/examples_and_tests_together.feature +1 -1
- data/features/interop/test_but_not_test_unit.feature +1 -1
- data/features/interop/test_case_with_should_methods.feature +1 -1
- data/features/matchers/create_matcher.feature +115 -0
- data/features/mock_framework_integration/use_flexmock.feature +22 -4
- data/features/mock_framework_integration/use_mocha.feature +27 -0
- data/features/mock_framework_integration/use_rr.feature +27 -0
- data/features/mocks/mix_stubs_and_mocks.feature +22 -0
- data/features/pending/pending_examples.feature +81 -0
- data/features/step_definitions/running_rspec.rb +5 -3
- data/features/support/env.rb +1 -1
- data/features/support/matchers/smart_match.rb +2 -2
- data/lib/autotest/rspec.rb +1 -1
- data/lib/spec.rb +1 -1
- data/lib/{adapters → spec/adapters}/mock_frameworks/flexmock.rb +0 -0
- data/lib/{adapters → spec/adapters}/mock_frameworks/mocha.rb +0 -0
- data/lib/{adapters → spec/adapters}/mock_frameworks/rr.rb +0 -0
- data/lib/{adapters → spec/adapters}/mock_frameworks/rspec.rb +0 -1
- data/lib/spec/autorun.rb +3 -0
- data/lib/spec/dsl.rb +3 -1
- data/lib/spec/dsl/matchers.rb +13 -0
- data/lib/spec/example.rb +4 -0
- data/lib/spec/example/before_and_after_hooks.rb +5 -20
- data/lib/spec/example/errors.rb +3 -3
- data/lib/spec/example/example_description.rb +15 -0
- data/lib/spec/example/example_group.rb +0 -15
- data/lib/spec/example/example_group_factory.rb +34 -46
- data/lib/spec/example/example_group_hierarchy.rb +53 -0
- data/lib/spec/example/example_group_methods.rb +101 -211
- data/lib/spec/example/example_methods.rb +61 -81
- data/lib/spec/example/module_reopening_fix.rb +23 -1
- data/lib/spec/example/pending.rb +3 -2
- data/lib/spec/example/predicate_matchers.rb +47 -0
- data/lib/spec/example/subject.rb +91 -0
- data/lib/spec/expectations.rb +1 -1
- data/lib/spec/expectations/differs/default.rb +0 -1
- data/lib/spec/expectations/extensions.rb +0 -1
- data/lib/spec/expectations/handler.rb +13 -6
- data/lib/spec/interop/test.rb +5 -0
- data/lib/spec/interop/test/unit/testcase.rb +5 -22
- data/lib/spec/matchers.rb +22 -8
- data/lib/spec/matchers/be.rb +4 -9
- data/lib/spec/matchers/be_close.rb +20 -5
- data/lib/spec/matchers/be_instance_of.rb +45 -0
- data/lib/spec/matchers/be_kind_of.rb +45 -0
- data/lib/spec/matchers/change.rb +8 -6
- data/lib/spec/matchers/compatibility.rb +14 -0
- data/lib/spec/matchers/eql.rb +24 -6
- data/lib/spec/matchers/equal.rb +24 -6
- data/lib/spec/matchers/exist.rb +21 -5
- data/lib/spec/matchers/extensions/instance_exec.rb +25 -0
- data/lib/spec/matchers/generated_descriptions.rb +2 -2
- data/lib/spec/matchers/has.rb +28 -11
- data/lib/spec/matchers/have.rb +2 -2
- data/lib/spec/matchers/include.rb +2 -2
- data/lib/spec/matchers/match.rb +25 -7
- data/lib/spec/matchers/match_array.rb +3 -3
- data/lib/spec/matchers/matcher.rb +51 -0
- data/lib/spec/matchers/method_missing.rb +2 -2
- data/lib/spec/matchers/operator_matcher.rb +12 -5
- data/lib/spec/matchers/raise_error.rb +3 -3
- data/lib/spec/matchers/respond_to.rb +3 -3
- data/lib/spec/matchers/satisfy.rb +7 -7
- data/lib/spec/matchers/throw_symbol.rb +3 -5
- data/lib/spec/mocks.rb +3 -3
- data/lib/spec/mocks/argument_expectation.rb +15 -15
- data/lib/spec/mocks/{argument_constraints.rb → argument_matchers.rb} +19 -23
- data/lib/spec/mocks/error_generator.rb +5 -8
- data/lib/spec/mocks/framework.rb +1 -1
- data/lib/spec/mocks/message_expectation.rb +5 -13
- data/lib/spec/mocks/mock.rb +4 -5
- data/lib/spec/mocks/proxy.rb +9 -5
- data/lib/spec/mocks/spec_methods.rb +10 -1
- data/lib/spec/rake/spectask.rb +0 -1
- data/lib/spec/runner.rb +6 -28
- data/lib/spec/runner/configuration.rb +3 -3
- data/lib/spec/runner/drb_command_line.rb +2 -1
- data/lib/spec/runner/example_group_runner.rb +3 -2
- data/lib/spec/runner/formatter/base_text_formatter.rb +34 -19
- data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +3 -5
- data/lib/spec/runner/formatter/html_formatter.rb +2 -3
- data/lib/spec/runner/formatter/nested_text_formatter.rb +7 -25
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +1 -1
- data/lib/spec/runner/formatter/snippet_extractor.rb +1 -1
- data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -7
- data/lib/spec/runner/heckle_runner.rb +3 -6
- data/lib/spec/runner/heckle_runner_unsupported.rb +1 -1
- data/lib/spec/runner/option_parser.rb +19 -21
- data/lib/spec/runner/options.rb +32 -27
- data/lib/spec/runner/reporter.rb +8 -9
- data/lib/spec/test/unit.rb +10 -0
- data/lib/spec/version.rb +2 -2
- data/{features/support → resources}/helpers/cmdline.rb +2 -2
- data/resources/rake/verify_rcov.rake +1 -1
- data/resources/spec/example_group_with_should_methods.rb +1 -1
- data/resources/spec/simple_spec.rb +1 -1
- data/resources/test/spec_and_test_together.rb +2 -3
- data/resources/test/spec_including_test_but_not_unit.rb +1 -1
- data/resources/test/test_case_with_should_methods.rb +2 -3
- data/spec/autotest/autotest_helper.rb +0 -1
- data/spec/autotest/rspec_spec.rb +95 -98
- data/spec/spec/dsl/main_spec.rb +3 -3
- data/spec/spec/dsl/matchers_spec.rb +25 -0
- data/spec/spec/example/example_group_class_definition_spec.rb +14 -15
- data/spec/spec/example/example_group_factory_spec.rb +31 -44
- data/spec/spec/example/example_group_methods_spec.rb +86 -52
- data/spec/spec/example/example_group_spec.rb +32 -79
- data/spec/spec/example/example_matcher_spec.rb +10 -10
- data/spec/spec/example/example_methods_spec.rb +108 -242
- data/spec/spec/example/nested_example_group_spec.rb +2 -2
- data/spec/spec/example/pending_module_spec.rb +66 -41
- data/spec/spec/example/shared_example_group_spec.rb +4 -4
- data/spec/spec/{matchers → expectations}/handler_spec.rb +52 -4
- data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +2 -2
- data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +2 -2
- data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +2 -2
- data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +2 -2
- data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +2 -2
- data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +2 -2
- data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +2 -2
- data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +2 -2
- data/spec/spec/interop/test/unit/testcase_spec.rb +0 -4
- data/spec/spec/matchers/be_close_spec.rb +1 -1
- data/spec/spec/matchers/be_instance_of_spec.rb +29 -0
- data/spec/spec/matchers/be_kind_of_spec.rb +29 -0
- data/spec/spec/matchers/change_spec.rb +20 -0
- data/spec/spec/matchers/compatibility_spec.rb +34 -0
- data/spec/spec/matchers/description_generation_spec.rb +0 -12
- data/spec/spec/matchers/eql_spec.rb +2 -2
- data/spec/spec/matchers/equal_spec.rb +2 -2
- data/spec/spec/matchers/exist_spec.rb +8 -4
- data/spec/spec/matchers/have_spec.rb +4 -4
- data/spec/spec/matchers/match_spec.rb +2 -2
- data/spec/spec/matchers/matcher_methods_spec.rb +1 -1
- data/spec/spec/matchers/matcher_spec.rb +97 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +8 -8
- data/spec/spec/mocks/{bug_report_496.rb → bug_report_496_spec.rb} +0 -0
- data/spec/spec/mocks/{failing_mock_argument_constraints_spec.rb → failing_argument_matchers_spec.rb} +2 -2
- data/spec/spec/mocks/hash_including_matcher_spec.rb +4 -4
- data/spec/spec/mocks/hash_not_including_matcher_spec.rb +3 -3
- data/spec/spec/mocks/mock_spec.rb +27 -2
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +1 -1
- data/spec/spec/mocks/partial_mock_spec.rb +18 -3
- data/spec/spec/mocks/{passing_mock_argument_constraints_spec.rb → passing_argument_matchers_spec.rb} +6 -6
- data/spec/spec/mocks/stubbed_message_expectations_spec.rb +13 -1
- data/spec/spec/package/bin_spec_spec.rb +2 -2
- data/spec/spec/runner/configuration_spec.rb +12 -12
- data/spec/spec/runner/drb_command_line_spec.rb +71 -73
- data/spec/spec/runner/formatter/base_text_formatter_spec.rb +82 -1
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +8 -8
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +4 -4
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +8 -8
- data/spec/spec/runner/formatter/html_formatted-1.8.7.html +38 -26
- data/spec/spec/runner/formatter/html_formatted-1.9.1.html +61 -53
- data/spec/spec/runner/formatter/html_formatter_spec.rb +100 -48
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -34
- data/spec/spec/runner/formatter/profile_formatter_spec.rb +2 -1
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +9 -6
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +20 -20
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +38 -26
- data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +55 -47
- data/spec/spec/runner/formatter/{spec_mate_formatter_spec.rb → text_mate_formatter_spec.rb} +11 -9
- data/spec/spec/runner/heckle_runner_spec.rb +1 -1
- data/spec/spec/runner/heckler_spec.rb +1 -1
- data/spec/spec/runner/option_parser_spec.rb +28 -11
- data/spec/spec/runner/options_spec.rb +34 -0
- data/spec/spec/runner/reporter_spec.rb +66 -62
- data/spec/spec/runner/resources/utf8_encoded.rb +1 -0
- data/spec/spec/runner/spec_drb.opts +1 -0
- data/spec/spec/runner_spec.rb +7 -5
- data/spec/spec_helper.rb +24 -2
- metadata +49 -90
- data/examples/passing/autogenerated_docstrings_example.rb +0 -25
- data/examples/passing/before_and_after_example.rb +0 -40
- data/examples/passing/behave_as_example.rb +0 -45
- data/examples/passing/legacy_spec.rb +0 -11
- data/examples/passing/priority.txt +0 -1
- data/features/support/helpers/story_helper.rb +0 -16
- data/lib/spec/expectations/extensions/string_and_symbol.rb +0 -17
- data/lib/spec/runner/formatter/story/html_formatter.rb +0 -174
- data/lib/spec/runner/formatter/story/plain_text_formatter.rb +0 -194
- data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +0 -42
- data/lib/spec/story.rb +0 -10
- data/lib/spec/story/extensions.rb +0 -3
- data/lib/spec/story/extensions/main.rb +0 -86
- data/lib/spec/story/extensions/regexp.rb +0 -9
- data/lib/spec/story/extensions/string.rb +0 -9
- data/lib/spec/story/given_scenario.rb +0 -14
- data/lib/spec/story/runner.rb +0 -57
- data/lib/spec/story/runner/plain_text_story_runner.rb +0 -48
- data/lib/spec/story/runner/scenario_collector.rb +0 -18
- data/lib/spec/story/runner/scenario_runner.rb +0 -54
- data/lib/spec/story/runner/story_mediator.rb +0 -137
- data/lib/spec/story/runner/story_parser.rb +0 -247
- data/lib/spec/story/runner/story_runner.rb +0 -74
- data/lib/spec/story/scenario.rb +0 -14
- data/lib/spec/story/step.rb +0 -70
- data/lib/spec/story/step_group.rb +0 -89
- data/lib/spec/story/step_mother.rb +0 -38
- data/lib/spec/story/story.rb +0 -39
- data/lib/spec/story/world.rb +0 -124
- data/resources/spec/spec_with_flexmock.rb +0 -19
- data/rspec.gemspec +0 -32
- data/spec/spec/matchers/mock_constraint_matchers_spec.rb +0 -24
- data/spec/spec/runner/formatter/story/html_formatter_spec.rb +0 -135
- data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +0 -600
- data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +0 -82
- data/spec/spec/spec_spec.rb +0 -21
- data/spec/spec/story/builders.rb +0 -46
- data/spec/spec/story/extensions/main_spec.rb +0 -161
- data/spec/spec/story/extensions_spec.rb +0 -14
- data/spec/spec/story/given_scenario_spec.rb +0 -27
- data/spec/spec/story/runner/plain_text_story_runner_spec.rb +0 -90
- data/spec/spec/story/runner/scenario_collector_spec.rb +0 -27
- data/spec/spec/story/runner/scenario_runner_spec.rb +0 -214
- data/spec/spec/story/runner/story_mediator_spec.rb +0 -143
- data/spec/spec/story/runner/story_parser_spec.rb +0 -401
- data/spec/spec/story/runner/story_runner_spec.rb +0 -294
- data/spec/spec/story/runner_spec.rb +0 -93
- data/spec/spec/story/scenario_spec.rb +0 -18
- data/spec/spec/story/step_group_spec.rb +0 -157
- data/spec/spec/story/step_mother_spec.rb +0 -84
- data/spec/spec/story/step_spec.rb +0 -272
- data/spec/spec/story/story_helper.rb +0 -2
- data/spec/spec/story/story_spec.rb +0 -84
- data/spec/spec/story/world_spec.rb +0 -423
- data/story_server/prototype/javascripts/builder.js +0 -136
- data/story_server/prototype/javascripts/controls.js +0 -972
- data/story_server/prototype/javascripts/dragdrop.js +0 -976
- data/story_server/prototype/javascripts/effects.js +0 -1117
- data/story_server/prototype/javascripts/prototype.js +0 -4140
- data/story_server/prototype/javascripts/rspec.js +0 -149
- data/story_server/prototype/javascripts/scriptaculous.js +0 -58
- data/story_server/prototype/javascripts/slider.js +0 -276
- data/story_server/prototype/javascripts/sound.js +0 -55
- data/story_server/prototype/javascripts/unittest.js +0 -568
- data/story_server/prototype/lib/server.rb +0 -24
- data/story_server/prototype/stories.html +0 -176
- data/story_server/prototype/stylesheets/rspec.css +0 -136
- data/story_server/prototype/stylesheets/test.css +0 -90
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec/runner/formatter/story/plain_text_formatter'
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Runner
|
5
|
-
module Formatter
|
6
|
-
module Story
|
7
|
-
class ProgressBarFormatter < PlainTextFormatter
|
8
|
-
|
9
|
-
def story_started(title, narrative) end
|
10
|
-
def story_ended(title, narrative) end
|
11
|
-
|
12
|
-
def run_started(count)
|
13
|
-
@start_time = Time.now
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
def run_ended
|
18
|
-
@output.puts
|
19
|
-
@output.puts
|
20
|
-
@output.puts "Finished in %f seconds" % (Time.now - @start_time)
|
21
|
-
@output.puts
|
22
|
-
super
|
23
|
-
end
|
24
|
-
|
25
|
-
def scenario_ended
|
26
|
-
if @scenario_failed
|
27
|
-
@output.print red('F')
|
28
|
-
@output.flush
|
29
|
-
elsif @scenario_pending
|
30
|
-
@output.print yellow('P')
|
31
|
-
@output.flush
|
32
|
-
else
|
33
|
-
@output.print green('.')
|
34
|
-
@output.flush
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/lib/spec/story.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'spec'
|
2
|
-
require 'spec/story/extensions'
|
3
|
-
require 'spec/story/given_scenario'
|
4
|
-
require 'spec/story/runner'
|
5
|
-
require 'spec/story/scenario'
|
6
|
-
require 'spec/story/step'
|
7
|
-
require 'spec/story/step_group'
|
8
|
-
require 'spec/story/step_mother'
|
9
|
-
require 'spec/story/story'
|
10
|
-
require 'spec/story/world'
|
@@ -1,86 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Story
|
3
|
-
module Extensions
|
4
|
-
module Main
|
5
|
-
def Story(title, narrative, params = {}, &body)
|
6
|
-
::Spec::Story::Runner.story_runner.Story(title, narrative, params, &body)
|
7
|
-
end
|
8
|
-
|
9
|
-
# Calling this deprecated is silly, since it hasn't been released yet. But, for
|
10
|
-
# those who are reading this - this will be deleted before the 1.1 release.
|
11
|
-
def run_story(*args, &block)
|
12
|
-
runner = Spec::Story::Runner::PlainTextStoryRunner.new(*args)
|
13
|
-
runner.instance_eval(&block) if block
|
14
|
-
runner.run
|
15
|
-
end
|
16
|
-
|
17
|
-
# Creates (or appends to an existing) a namespaced group of steps for use in Stories
|
18
|
-
#
|
19
|
-
# == Examples
|
20
|
-
#
|
21
|
-
# # Creating a new group
|
22
|
-
# steps_for :forms do
|
23
|
-
# When("user enters $value in the $field field") do ... end
|
24
|
-
# When("user submits the $form form") do ... end
|
25
|
-
# end
|
26
|
-
def steps_for(tag, &block)
|
27
|
-
steps = rspec_story_steps[tag]
|
28
|
-
steps.instance_eval(&block) if block
|
29
|
-
steps
|
30
|
-
end
|
31
|
-
|
32
|
-
# Creates a context for running a Plain Text Story with specific groups of Steps.
|
33
|
-
# Also supports adding arbitrary steps that will only be accessible to
|
34
|
-
# the Story being run.
|
35
|
-
#
|
36
|
-
# == Examples
|
37
|
-
#
|
38
|
-
# # Run a Story with one group of steps
|
39
|
-
# with_steps_for :checking_accounts do
|
40
|
-
# run File.dirname(__FILE__) + "/withdraw_cash"
|
41
|
-
# end
|
42
|
-
#
|
43
|
-
# # Run a Story, adding steps that are only available for this Story
|
44
|
-
# with_steps_for :accounts do
|
45
|
-
# Given "user is logged in as account administrator"
|
46
|
-
# run File.dirname(__FILE__) + "/reconcile_accounts"
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# # Run a Story with steps from two groups
|
50
|
-
# with_steps_for :checking_accounts, :savings_accounts do
|
51
|
-
# run File.dirname(__FILE__) + "/transfer_money"
|
52
|
-
# end
|
53
|
-
#
|
54
|
-
# # Run a Story with a specific Story extension
|
55
|
-
# with_steps_for :login, :navigation do
|
56
|
-
# run File.dirname(__FILE__) + "/user_changes_password", :type => RailsStory
|
57
|
-
# end
|
58
|
-
def with_steps_for(*tags, &block)
|
59
|
-
steps = Spec::Story::StepGroup.new do
|
60
|
-
extend StoryRunnerStepGroupAdapter
|
61
|
-
end
|
62
|
-
tags.each {|tag| steps << rspec_story_steps[tag]}
|
63
|
-
steps.instance_eval(&block) if block
|
64
|
-
steps
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
module StoryRunnerStepGroupAdapter
|
70
|
-
def run(path, options={})
|
71
|
-
runner = Spec::Story::Runner::PlainTextStoryRunner.new(path, options)
|
72
|
-
runner.steps << self
|
73
|
-
runner.run
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def rspec_story_steps # :nodoc:
|
78
|
-
$rspec_story_steps ||= Spec::Story::StepGroupHash.new
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
include Spec::Story::Extensions::Main
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Story
|
3
|
-
class GivenScenario
|
4
|
-
def initialize(name)
|
5
|
-
@name = name
|
6
|
-
end
|
7
|
-
|
8
|
-
def perform(instance, ignore_name)
|
9
|
-
scenario = Runner::StoryRunner.scenario_from_current_story(@name)
|
10
|
-
Runner::ScenarioRunner.new.run(scenario, instance)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/lib/spec/story/runner.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec/story/runner/scenario_collector.rb'
|
2
|
-
require 'spec/story/runner/scenario_runner.rb'
|
3
|
-
require 'spec/story/runner/story_runner.rb'
|
4
|
-
require 'spec/story/runner/story_parser.rb'
|
5
|
-
require 'spec/story/runner/story_mediator.rb'
|
6
|
-
require 'spec/story/runner/plain_text_story_runner.rb'
|
7
|
-
|
8
|
-
module Spec
|
9
|
-
module Story
|
10
|
-
module Runner
|
11
|
-
def self.run_options # :nodoc:
|
12
|
-
Spec::Runner.options
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.story_runner # :nodoc:
|
16
|
-
unless @story_runner
|
17
|
-
@story_runner = create_story_runner
|
18
|
-
run_options.story_formatters.each do |formatter|
|
19
|
-
register_listener(formatter)
|
20
|
-
end
|
21
|
-
self.register_exit_hook
|
22
|
-
end
|
23
|
-
@story_runner
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.scenario_runner # :nodoc:
|
27
|
-
@scenario_runner ||= ScenarioRunner.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.world_creator # :nodoc:
|
31
|
-
@world_creator ||= World
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.create_story_runner
|
35
|
-
Runner::StoryRunner.new(scenario_runner, world_creator)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Use this to register a customer output formatter.
|
39
|
-
def self.register_listener(listener)
|
40
|
-
story_runner.add_listener(listener) # run_started, story_started, story_ended, #run_ended
|
41
|
-
world_creator.add_listener(listener) # found_scenario, step_succeeded, step_failed, step_failed
|
42
|
-
scenario_runner.add_listener(listener) # scenario_started, scenario_succeeded, scenario_pending, scenario_failed
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.register_exit_hook # :nodoc:
|
46
|
-
at_exit do
|
47
|
-
exit Runner.story_runner.run_stories unless $!
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.dry_run
|
52
|
-
run_options.dry_run
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Story
|
3
|
-
module Runner
|
4
|
-
class PlainTextStoryRunner
|
5
|
-
# You can initialize a PlainTextStoryRunner with the path to the
|
6
|
-
# story file or a block, in which you can define the path using load.
|
7
|
-
#
|
8
|
-
# == Examples
|
9
|
-
#
|
10
|
-
# PlainTextStoryRunner.new('path/to/file')
|
11
|
-
#
|
12
|
-
# PlainTextStoryRunner.new do |runner|
|
13
|
-
# runner.load 'path/to/file'
|
14
|
-
# end
|
15
|
-
def initialize(*args)
|
16
|
-
@options = Hash === args.last ? args.pop : {}
|
17
|
-
@story_file = args.empty? ? nil : args.shift
|
18
|
-
yield self if block_given?
|
19
|
-
end
|
20
|
-
|
21
|
-
def []=(key, value)
|
22
|
-
@options[key] = value
|
23
|
-
end
|
24
|
-
|
25
|
-
def load(path)
|
26
|
-
@story_file = path
|
27
|
-
end
|
28
|
-
|
29
|
-
def run(story_runner=Spec::Story::Runner.story_runner)
|
30
|
-
raise "You must set a path to the file with the story. See the RDoc." if @story_file.nil?
|
31
|
-
mediator = Spec::Story::Runner::StoryMediator.new(steps, story_runner, @options)
|
32
|
-
parser = Spec::Story::Runner::StoryParser.new(mediator)
|
33
|
-
|
34
|
-
story_text = File.read(@story_file)
|
35
|
-
parser.parse(story_text.split("\n"))
|
36
|
-
|
37
|
-
mediator.run_stories
|
38
|
-
end
|
39
|
-
|
40
|
-
def steps
|
41
|
-
@step_group ||= Spec::Story::StepGroup.new
|
42
|
-
yield @step_group if block_given?
|
43
|
-
@step_group
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Story
|
3
|
-
module Runner
|
4
|
-
class ScenarioCollector
|
5
|
-
attr_accessor :scenarios
|
6
|
-
|
7
|
-
def initialize(story)
|
8
|
-
@story = story
|
9
|
-
@scenarios = []
|
10
|
-
end
|
11
|
-
|
12
|
-
def Scenario(name, &body)
|
13
|
-
@scenarios << Scenario.new(@story, name, &body)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Story
|
3
|
-
module Runner
|
4
|
-
class ScenarioRunner
|
5
|
-
def initialize
|
6
|
-
@listeners = []
|
7
|
-
end
|
8
|
-
|
9
|
-
def run(scenario, world)
|
10
|
-
@listeners.each { |l| l.scenario_started(scenario.story.title, scenario.name) }
|
11
|
-
run_story_ignoring_scenarios(scenario.story, world)
|
12
|
-
|
13
|
-
world.start_collecting_errors
|
14
|
-
|
15
|
-
unless scenario.body
|
16
|
-
@listeners.each { |l| l.scenario_pending(scenario.story.title, scenario.name, '') }
|
17
|
-
return true
|
18
|
-
end
|
19
|
-
|
20
|
-
world.instance_eval(&scenario.body)
|
21
|
-
if world.errors.empty?
|
22
|
-
@listeners.each { |l| l.scenario_succeeded(scenario.story.title, scenario.name) }
|
23
|
-
else
|
24
|
-
if Spec::Example::ExamplePendingError === (e = world.errors.first)
|
25
|
-
@listeners.each { |l| l.scenario_pending(scenario.story.title, scenario.name, e.message) }
|
26
|
-
else
|
27
|
-
@listeners.each { |l| l.scenario_failed(scenario.story.title, scenario.name, e) }
|
28
|
-
return false
|
29
|
-
end
|
30
|
-
end
|
31
|
-
true
|
32
|
-
end
|
33
|
-
|
34
|
-
def add_listener(listener)
|
35
|
-
@listeners << listener
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def run_story_ignoring_scenarios(story, world)
|
41
|
-
class << world
|
42
|
-
def Scenario(name, &block)
|
43
|
-
# do nothing
|
44
|
-
end
|
45
|
-
end
|
46
|
-
story.run_in(world)
|
47
|
-
class << world
|
48
|
-
remove_method(:Scenario)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Story
|
3
|
-
module Runner
|
4
|
-
|
5
|
-
class StoryMediator
|
6
|
-
def initialize(step_group, runner, options={})
|
7
|
-
@step_group = step_group
|
8
|
-
@stories = []
|
9
|
-
@runner = runner
|
10
|
-
@options = options
|
11
|
-
end
|
12
|
-
|
13
|
-
def stories
|
14
|
-
@stories.collect { |p| p.to_proc }
|
15
|
-
end
|
16
|
-
|
17
|
-
def create_story(title, narrative)
|
18
|
-
@stories << Story.new(title, narrative, @step_group, @options)
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_scenario(title)
|
22
|
-
current_story.add_scenario Scenario.new(title)
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_given(name)
|
26
|
-
current_scenario.add_step Step.new('Given', name)
|
27
|
-
end
|
28
|
-
|
29
|
-
def create_given_scenario(name)
|
30
|
-
current_scenario.add_step Step.new('GivenScenario', name)
|
31
|
-
end
|
32
|
-
|
33
|
-
def create_when(name)
|
34
|
-
current_scenario.add_step Step.new('When', name)
|
35
|
-
end
|
36
|
-
|
37
|
-
def create_then(name)
|
38
|
-
current_scenario.add_step Step.new('Then', name)
|
39
|
-
end
|
40
|
-
|
41
|
-
def last_step
|
42
|
-
current_scenario.last_step
|
43
|
-
end
|
44
|
-
|
45
|
-
def add_to_last(name)
|
46
|
-
last_step.name << name
|
47
|
-
end
|
48
|
-
|
49
|
-
def run_stories
|
50
|
-
stories.each { |story| @runner.instance_eval(&story) }
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
def current_story
|
55
|
-
@stories.last
|
56
|
-
end
|
57
|
-
|
58
|
-
def current_scenario
|
59
|
-
current_story.current_scenario
|
60
|
-
end
|
61
|
-
|
62
|
-
class Story
|
63
|
-
def initialize(title, narrative, step_group, options)
|
64
|
-
@title = title
|
65
|
-
@narrative = narrative
|
66
|
-
@scenarios = []
|
67
|
-
@step_group = step_group
|
68
|
-
@options = options
|
69
|
-
end
|
70
|
-
|
71
|
-
def to_proc
|
72
|
-
title = @title
|
73
|
-
narrative = @narrative
|
74
|
-
scenarios = @scenarios.collect { |scenario| scenario.to_proc }
|
75
|
-
options = @options.merge(:steps_for => @step_group)
|
76
|
-
lambda do
|
77
|
-
Story title, narrative, options do
|
78
|
-
scenarios.each { |scenario| instance_eval(&scenario) }
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def add_scenario(scenario)
|
84
|
-
@scenarios << scenario
|
85
|
-
end
|
86
|
-
|
87
|
-
def current_scenario
|
88
|
-
@scenarios.last
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class Scenario
|
93
|
-
def initialize(name)
|
94
|
-
@name = name
|
95
|
-
@steps = []
|
96
|
-
end
|
97
|
-
|
98
|
-
def to_proc
|
99
|
-
name = @name
|
100
|
-
steps = @steps.collect { |step| step.to_proc }
|
101
|
-
lambda do
|
102
|
-
Scenario name do
|
103
|
-
steps.each { |step| instance_eval(&step) }
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def add_step(step)
|
109
|
-
@steps << step
|
110
|
-
end
|
111
|
-
|
112
|
-
def last_step
|
113
|
-
@steps.last
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class Step
|
118
|
-
attr_reader :name
|
119
|
-
|
120
|
-
def initialize(type, name)
|
121
|
-
@type = type
|
122
|
-
@name = name
|
123
|
-
end
|
124
|
-
|
125
|
-
def to_proc
|
126
|
-
type = @type
|
127
|
-
name = @name
|
128
|
-
lambda do
|
129
|
-
send(type, name)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|