rspec-core 2.0.0.a1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. data/.document +5 -0
  2. data/.gitignore +7 -0
  3. data/.treasure_map.rb +23 -0
  4. data/License.txt +22 -0
  5. data/README.markdown +9 -0
  6. data/Rakefile +76 -0
  7. data/TODO.markdown +16 -0
  8. data/VERSION +1 -0
  9. data/VERSION.yml +5 -0
  10. data/bin/rspec +12 -0
  11. data/cucumber.yml +2 -0
  12. data/example_specs/failing/README.txt +7 -0
  13. data/example_specs/failing/diffing_spec.rb +36 -0
  14. data/example_specs/failing/failing_implicit_docstrings_example.rb +19 -0
  15. data/example_specs/failing/failure_in_after.rb +10 -0
  16. data/example_specs/failing/failure_in_before.rb +10 -0
  17. data/example_specs/failing/mocking_example.rb +40 -0
  18. data/example_specs/failing/mocking_with_flexmock.rb +26 -0
  19. data/example_specs/failing/mocking_with_mocha.rb +25 -0
  20. data/example_specs/failing/mocking_with_rr.rb +27 -0
  21. data/example_specs/failing/partial_mock_example.rb +20 -0
  22. data/example_specs/failing/pending_example.rb +9 -0
  23. data/example_specs/failing/predicate_example.rb +34 -0
  24. data/example_specs/failing/raising_example.rb +47 -0
  25. data/example_specs/failing/spec_helper.rb +3 -0
  26. data/example_specs/failing/syntax_error_example.rb +7 -0
  27. data/example_specs/failing/team_spec.rb +44 -0
  28. data/example_specs/failing/timeout_behaviour.rb +7 -0
  29. data/example_specs/passing/custom_formatter.rb +12 -0
  30. data/example_specs/passing/custom_matchers.rb +54 -0
  31. data/example_specs/passing/dynamic_spec.rb +9 -0
  32. data/example_specs/passing/file_accessor.rb +19 -0
  33. data/example_specs/passing/file_accessor_spec.rb +38 -0
  34. data/example_specs/passing/filtered_formatter.rb +18 -0
  35. data/example_specs/passing/filtered_formatter_example.rb +31 -0
  36. data/example_specs/passing/greeter_spec.rb +31 -0
  37. data/example_specs/passing/helper_method_example.rb +14 -0
  38. data/example_specs/passing/implicit_docstrings_example.rb +18 -0
  39. data/example_specs/passing/io_processor.rb +8 -0
  40. data/example_specs/passing/io_processor_spec.rb +21 -0
  41. data/example_specs/passing/mocking_example.rb +27 -0
  42. data/example_specs/passing/multi_threaded_example_group_runner.rb +26 -0
  43. data/example_specs/passing/nested_classes_example.rb +36 -0
  44. data/example_specs/passing/options_example.rb +31 -0
  45. data/example_specs/passing/options_formatter.rb +20 -0
  46. data/example_specs/passing/partial_mock_example.rb +29 -0
  47. data/example_specs/passing/pending_example.rb +20 -0
  48. data/example_specs/passing/predicate_example.rb +27 -0
  49. data/example_specs/passing/shared_example_group_example.rb +81 -0
  50. data/example_specs/passing/shared_stack_examples.rb +36 -0
  51. data/example_specs/passing/simple_matcher_example.rb +31 -0
  52. data/example_specs/passing/spec_helper.rb +14 -0
  53. data/example_specs/passing/stack.rb +36 -0
  54. data/example_specs/passing/stack_spec.rb +64 -0
  55. data/example_specs/passing/stack_spec_with_nested_example_groups.rb +67 -0
  56. data/example_specs/passing/stubbing_example.rb +69 -0
  57. data/example_specs/passing/yielding_example.rb +33 -0
  58. data/example_specs/ruby1.9.compatibility/access_to_constants_spec.rb +85 -0
  59. data/features-pending/command_line/line_number_option.feature +56 -0
  60. data/features-pending/command_line/line_number_option_with_example_with_no_name.feature +22 -0
  61. data/features-pending/example_groups/example_group_with_should_methods.feature +29 -0
  62. data/features-pending/example_groups/implicit_docstrings.feature +59 -0
  63. data/features-pending/example_groups/nested_groups.feature +32 -0
  64. data/features-pending/expectations/expect_change.feature +65 -0
  65. data/features-pending/expectations/expect_error.feature +44 -0
  66. data/features-pending/extensions/custom_example_group.feature +19 -0
  67. data/features-pending/formatters/custom_formatter.feature +30 -0
  68. data/features-pending/heckle/heckle.feature +56 -0
  69. data/features-pending/interop/examples_and_tests_together.feature +80 -0
  70. data/features-pending/interop/rspec_output.feature +25 -0
  71. data/features-pending/interop/test_but_not_test_unit.feature +26 -0
  72. data/features-pending/interop/test_case_with_should_methods.feature +46 -0
  73. data/features-pending/matchers/define_diffable_matcher.feature +26 -0
  74. data/features-pending/matchers/define_matcher.feature +179 -0
  75. data/features-pending/matchers/define_matcher_with_fluent_interface.feature +27 -0
  76. data/features-pending/mocks/mix_stubs_and_mocks.feature +22 -0
  77. data/features-pending/mocks/stub_implementation.feature +26 -0
  78. data/features-pending/pending/pending_examples.feature +81 -0
  79. data/features-pending/runner/specify_line_number.feature +32 -0
  80. data/features/before_and_after_blocks/before_and_after_blocks.feature +169 -0
  81. data/features/expectations/customized_message.feature +54 -0
  82. data/features/matchers/define_matcher_outside_rspec.feature +39 -0
  83. data/features/mock_framework_integration/use_flexmock.feature +23 -0
  84. data/features/mock_framework_integration/use_mocha.feature +23 -0
  85. data/features/mock_framework_integration/use_rr.feature +23 -0
  86. data/features/mock_framework_integration/use_rspec.feature +23 -0
  87. data/features/step_definitions/running_rspec_steps.rb +35 -0
  88. data/features/subject/explicit_subject.feature +31 -0
  89. data/features/subject/implicit_subject.feature +31 -0
  90. data/features/support/env.rb +82 -0
  91. data/features/support/matchers/smart_match.rb +14 -0
  92. data/lib/rspec/autorun.rb +2 -0
  93. data/lib/rspec/core.rb +38 -0
  94. data/lib/rspec/core/backward_compatibility.rb +9 -0
  95. data/lib/rspec/core/command_line_options.rb +60 -0
  96. data/lib/rspec/core/configuration.rb +222 -0
  97. data/lib/rspec/core/deprecation.rb +47 -0
  98. data/lib/rspec/core/example.rb +113 -0
  99. data/lib/rspec/core/example_group.rb +239 -0
  100. data/lib/rspec/core/example_group_subject.rb +77 -0
  101. data/lib/rspec/core/formatters.rb +16 -0
  102. data/lib/rspec/core/formatters/base_formatter.rb +123 -0
  103. data/lib/rspec/core/formatters/base_text_formatter.rb +139 -0
  104. data/lib/rspec/core/formatters/documentation_formatter.rb +84 -0
  105. data/lib/rspec/core/formatters/progress_formatter.rb +36 -0
  106. data/lib/rspec/core/kernel_extensions.rb +15 -0
  107. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +13 -0
  108. data/lib/rspec/core/mocking/with_flexmock.rb +25 -0
  109. data/lib/rspec/core/mocking/with_mocha.rb +22 -0
  110. data/lib/rspec/core/mocking/with_rr.rb +26 -0
  111. data/lib/rspec/core/mocking/with_rspec.rb +21 -0
  112. data/lib/rspec/core/rake_task.rb +88 -0
  113. data/lib/rspec/core/runner.rb +66 -0
  114. data/lib/rspec/core/shared_behaviour.rb +41 -0
  115. data/lib/rspec/core/shared_behaviour_kernel_extensions.rb +31 -0
  116. data/lib/rspec/core/version.rb +16 -0
  117. data/lib/rspec/core/world.rb +105 -0
  118. data/rspec-core.gemspec +204 -0
  119. data/script/console +8 -0
  120. data/spec/resources/example_classes.rb +67 -0
  121. data/spec/rspec/core/command_line_options_spec.rb +63 -0
  122. data/spec/rspec/core/configuration_spec.rb +171 -0
  123. data/spec/rspec/core/example_group_spec.rb +351 -0
  124. data/spec/rspec/core/example_group_subject_spec.rb +67 -0
  125. data/spec/rspec/core/example_spec.rb +67 -0
  126. data/spec/rspec/core/formatters/base_formatter_spec.rb +105 -0
  127. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +5 -0
  128. data/spec/rspec/core/formatters/progress_formatter_spec.rb +29 -0
  129. data/spec/rspec/core/kernel_extensions_spec.rb +13 -0
  130. data/spec/rspec/core/mocha_spec.rb +29 -0
  131. data/spec/rspec/core/resources/a_bar.rb +0 -0
  132. data/spec/rspec/core/resources/a_foo.rb +0 -0
  133. data/spec/rspec/core/resources/a_spec.rb +1 -0
  134. data/spec/rspec/core/resources/custom_example_group_runner.rb +14 -0
  135. data/spec/rspec/core/resources/example_classes.rb +67 -0
  136. data/spec/rspec/core/resources/utf8_encoded.rb +8 -0
  137. data/spec/rspec/core/runner_spec.rb +34 -0
  138. data/spec/rspec/core/shared_behaviour_spec.rb +185 -0
  139. data/spec/rspec/core/world_spec.rb +167 -0
  140. data/spec/rspec/core_spec.rb +35 -0
  141. data/spec/ruby_forker.rb +13 -0
  142. data/spec/spec_helper.rb +72 -0
  143. metadata +219 -0
@@ -0,0 +1,16 @@
1
+ require 'rspec/core/formatters/base_formatter'
2
+ require 'rspec/core/formatters/base_text_formatter'
3
+ require 'rspec/core/formatters/documentation_formatter'
4
+ require 'rspec/core/formatters/progress_formatter'
5
+
6
+ module Rspec
7
+
8
+ module Core
9
+
10
+ module Formatters
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,123 @@
1
+ module Rspec
2
+
3
+ module Core
4
+
5
+ module Formatters
6
+
7
+ class BaseFormatter
8
+ attr_accessor :behaviour
9
+ attr_reader :example_count, :duration, :examples
10
+
11
+ def initialize
12
+ @example_count = 0
13
+ @examples = []
14
+ @behaviour = nil
15
+ end
16
+
17
+ def configuration
18
+ Rspec::Core.configuration
19
+ end
20
+
21
+ def output
22
+ Rspec::Core.configuration.output
23
+ end
24
+
25
+ def profile_examples?
26
+ Rspec::Core.configuration.profile_examples
27
+ end
28
+
29
+ def color_enabled?
30
+ configuration.color_enabled?
31
+ end
32
+
33
+ def pending_examples
34
+ @pending_examples ||= ::Rspec::Core.world.find(examples, :positive, :execution_result => { :status => 'pending' })
35
+ end
36
+
37
+ def failed_examples
38
+ @failed_examples ||= ::Rspec::Core.world.find(examples, :positive, :execution_result => { :status => 'failed' })
39
+ end
40
+
41
+ # This method is invoked before any examples are run, right after
42
+ # they have all been collected. This can be useful for special
43
+ # formatters that need to provide progress on feedback (graphical ones)
44
+ #
45
+ # This method will only be invoked once, and the next one to be invoked
46
+ # is #add_behaviour
47
+ def start(example_count)
48
+ @example_count = example_count
49
+ end
50
+
51
+ def example_finished(example)
52
+ examples << example
53
+ end
54
+
55
+ # This method is invoked at the beginning of the execution of each behaviour.
56
+ # +behaviour+ is the behaviour.
57
+ #
58
+ # The next method to be invoked after this is #example_failed or #example_finished
59
+ def add_behaviour(behaviour)
60
+ @behaviour = behaviour
61
+ end
62
+
63
+ # This method is invoked after all of the examples have executed. The next method
64
+ # to be invoked after this one is #dump_failure (once for each failed example),
65
+ def start_dump(duration)
66
+ @duration = duration
67
+ end
68
+
69
+ # Dumps detailed information about each example failure.
70
+ def dump_failures
71
+ end
72
+
73
+ # This method is invoked after the dumping of examples and failures.
74
+ def dump_summary
75
+ end
76
+
77
+ # This gets invoked after the summary if option is set to do so.
78
+ def dump_pending
79
+ end
80
+
81
+ # This method is invoked at the very end. Allows the formatter to clean up, like closing open streams.
82
+ def close
83
+ end
84
+
85
+ def format_backtrace(backtrace, example)
86
+ return "" unless backtrace
87
+ return backtrace if example.metadata[:full_backtrace] == true
88
+
89
+ cleansed = backtrace.select { |line| backtrace_line(line) }
90
+ # Kick the describe stack info off the list, just keep the line the problem happened on from that file
91
+ # cleansed = [cleansed.detect { |line| line.split(':').first == example.metadata[:caller].split(':').first }] if cleansed.size > 1
92
+ cleansed.empty? ? backtrace : cleansed
93
+ end
94
+
95
+ protected
96
+
97
+ def backtrace_line(line)
98
+ return nil if configuration.cleaned_from_backtrace?(line)
99
+ line.sub!(/\A([^:]+:\d+)$/, '\\1')
100
+ return nil if line == '-e:1'
101
+ line
102
+ end
103
+
104
+ def read_failed_line(exception, example)
105
+ original_file = example.file_path.to_s.downcase
106
+ matching_line = exception.backtrace.detect { |line| line.split(':').first.downcase == original_file.downcase }
107
+
108
+ return "Unable to find matching line from backtrace" if matching_line.nil?
109
+
110
+ file_path, line_number = matching_line.split(':')
111
+ if File.exist?(file_path)
112
+ open(file_path, 'r') { |f| f.readlines[line_number.to_i - 1] }
113
+ else
114
+ "Unable to find #{file_path} to read failed line"
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+ end
122
+
123
+ end
@@ -0,0 +1,139 @@
1
+ module Rspec
2
+
3
+ module Core
4
+
5
+ module Formatters
6
+
7
+ class BaseTextFormatter < BaseFormatter
8
+
9
+ def dump_failures
10
+ output.puts
11
+ failed_examples.each_with_index do |failed_example, index|
12
+ exception = failed_example.execution_result[:exception_encountered]
13
+ padding = ' '
14
+
15
+ output.puts "#{index.next}) #{failed_example}"
16
+ output.puts "#{padding}Failure/Error: #{read_failed_line(exception, failed_example).strip}"
17
+
18
+ exception.message.split("\n").each do |line|
19
+ output.puts "#{padding}#{colorise(line, exception).strip}"
20
+ end
21
+
22
+ format_backtrace(exception.backtrace, failed_example).each do |backtrace_info|
23
+ output.puts grey("#{padding}# #{backtrace_info}")
24
+ end
25
+
26
+ output.puts
27
+ output.flush
28
+ end
29
+ end
30
+
31
+ def colorise(s, failure)
32
+ red(s)
33
+ end
34
+
35
+ def dump_summary
36
+ failure_count = failed_examples.size
37
+ pending_count = pending_examples.size
38
+
39
+ output.puts "\nFinished in #{duration} seconds\n"
40
+
41
+ summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failures"
42
+ summary << ", #{pending_count} pending" if pending_count > 0
43
+
44
+ if failure_count == 0
45
+ if pending_count > 0
46
+ output.puts yellow(summary)
47
+ else
48
+ output.puts green(summary)
49
+ end
50
+ else
51
+ output.puts red(summary)
52
+ end
53
+
54
+ # Don't print out profiled info if there are failures, it just clutters the output
55
+ if profile_examples? && failure_count == 0
56
+ sorted_examples = examples.sort_by { |example| example.execution_result[:run_time] }.reverse.first(10)
57
+ output.puts "\nTop #{sorted_examples.size} slowest examples:\n"
58
+ sorted_examples.each do |example|
59
+ output.puts " (#{sprintf("%.7f", example.execution_result[:run_time])} seconds) #{example}"
60
+ output.puts grey(" # #{format_caller(example.metadata[:caller])}")
61
+ end
62
+ end
63
+
64
+ output.flush
65
+ end
66
+
67
+ # def textmate_link_backtrace(path)
68
+ # file, line = path.split(':')
69
+ # "txmt://open/?url=file://#{File.expand_path(file)}&line=#{line}"
70
+ # end
71
+
72
+ def format_caller(caller_info)
73
+ caller_info.to_s.split(':in `block').first
74
+ end
75
+
76
+ def dump_pending
77
+ unless pending_examples.empty?
78
+ output.puts
79
+ output.puts "Pending:"
80
+ pending_examples.each do |pending_example, message|
81
+ output.puts " #{pending_example}"
82
+ output.puts grey(" # #{format_caller(pending_example.metadata[:caller])}")
83
+ end
84
+ end
85
+ output.flush
86
+ end
87
+
88
+ def close
89
+ if IO === output && output != $stdout
90
+ output.close
91
+ end
92
+ end
93
+
94
+ protected
95
+
96
+ def color(text, color_code)
97
+ return text unless color_enabled?
98
+ "#{color_code}#{text}\e[0m"
99
+ end
100
+
101
+ def bold(text)
102
+ color(text, "\e[1m")
103
+ end
104
+
105
+ def white(text)
106
+ color(text, "\e[37m")
107
+ end
108
+
109
+ def green(text)
110
+ color(text, "\e[32m")
111
+ end
112
+
113
+ def red(text)
114
+ color(text, "\e[31m")
115
+ end
116
+
117
+ def magenta(text)
118
+ color(text, "\e[35m")
119
+ end
120
+
121
+ def yellow(text)
122
+ color(text, "\e[33m")
123
+ end
124
+
125
+ def blue(text)
126
+ color(text, "\e[34m")
127
+ end
128
+
129
+ def grey(text)
130
+ color(text, "\e[90m")
131
+ end
132
+
133
+ end
134
+
135
+ end
136
+
137
+ end
138
+
139
+ end
@@ -0,0 +1,84 @@
1
+ module Rspec
2
+
3
+ module Core
4
+
5
+ module Formatters
6
+
7
+ class DocumentationFormatter < BaseTextFormatter
8
+
9
+ attr_reader :previous_nested_behaviours
10
+
11
+ def initialize
12
+ super
13
+ @previous_nested_behaviours = []
14
+ end
15
+
16
+ def add_behaviour(behaviour)
17
+ super
18
+
19
+ described_behaviour_chain.each_with_index do |nested_behaviour, i|
20
+ unless nested_behaviour == previous_nested_behaviours[i]
21
+ at_root_level = (i == 0)
22
+ desc_or_name = at_root_level ? nested_behaviour.name : nested_behaviour.description
23
+ output.puts if at_root_level
24
+ output.puts "#{' ' * i}#{desc_or_name}"
25
+ end
26
+ end
27
+
28
+ @previous_nested_behaviours = described_behaviour_chain
29
+ end
30
+
31
+ def output_for(example)
32
+ case example.execution_result[:status]
33
+ when 'failed'
34
+ failure_output(example, example.execution_result[:exception_encountered])
35
+ when 'pending'
36
+ pending_output(example, example.execution_result[:pending_message])
37
+ when 'passed'
38
+ passed_output(example)
39
+ else
40
+ red(example.execution_result[:status])
41
+ end
42
+ end
43
+
44
+ def example_finished(example)
45
+ super
46
+ output.puts output_for(example)
47
+ output.flush
48
+ end
49
+
50
+ def failure_output(example, exception)
51
+ expectation_not_met = exception.is_a?(::Rspec::Expectations::ExpectationNotMetError)
52
+
53
+ message = if expectation_not_met
54
+ "#{current_indentation}#{example.description} (FAILED)"
55
+ else
56
+ "#{current_indentation}#{example.description} (ERROR)"
57
+ end
58
+
59
+ expectation_not_met ? red(message) : magenta(message)
60
+ end
61
+
62
+ def passed_output(example)
63
+ green("#{current_indentation}#{example.description}")
64
+ end
65
+
66
+ def pending_output(example, message)
67
+ yellow("#{current_indentation}#{example.description} (PENDING: #{message})")
68
+ end
69
+
70
+ def current_indentation
71
+ ' ' * previous_nested_behaviours.size
72
+ end
73
+
74
+ def described_behaviour_chain
75
+ behaviour.ancestors
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,36 @@
1
+ module Rspec
2
+
3
+ module Core
4
+
5
+ module Formatters
6
+
7
+ class ProgressFormatter < BaseTextFormatter
8
+
9
+ def output_for(example)
10
+ case example.execution_result[:status]
11
+ when 'failed' then colorise('F', example.execution_result[:exception_encountered])
12
+ when 'pending' then yellow('*')
13
+ when 'passed' then green('.')
14
+ else
15
+ red(example.execution_result[:status])
16
+ end
17
+ end
18
+
19
+ def example_finished(example)
20
+ super
21
+ output.print output_for(example)
22
+ end
23
+
24
+ def start_dump(duration)
25
+ super
26
+ output.puts
27
+ output.flush
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,15 @@
1
+ module Rspec
2
+ module Core
3
+ module KernelExtensions
4
+
5
+ def describe(*args, &behaviour_block)
6
+ Rspec::Core::ExampleGroup.describe(*args, &behaviour_block)
7
+ end
8
+
9
+ alias :context :describe
10
+
11
+ end
12
+ end
13
+ end
14
+
15
+ include Rspec::Core::KernelExtensions
@@ -0,0 +1,13 @@
1
+ module Rspec
2
+ module Core
3
+ module Mocking
4
+ module WithAbsolutelyNothing
5
+
6
+ def _setup_mocks; end
7
+ def _verify_mocks; end
8
+ def _teardown_mocks; end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Jim Weirich on 2007-04-10.
4
+ # Copyright (c) 2007. All rights reserved.
5
+
6
+ require 'flexmock/rspec'
7
+
8
+ module Rspec
9
+ module Core
10
+ module Mocking
11
+ module WithFlexmock
12
+ include FlexMock::MockContainer
13
+ def setup_mocks_for_rspec
14
+ # No setup required
15
+ end
16
+ def verify_mocks_for_rspec
17
+ flexmock_verify
18
+ end
19
+ def teardown_mocks_for_rspec
20
+ flexmock_close
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end