rspec-core 2.0.0.beta.22 → 2.6.0
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.
- data/.gitignore +1 -0
- data/.rspec +0 -1
- data/.travis.yml +7 -0
- data/Gemfile +46 -20
- data/Guardfile +5 -0
- data/License.txt +2 -1
- data/{README.markdown → README.md} +23 -5
- data/Rakefile +58 -31
- data/bin/autospec +13 -0
- data/bin/rspec +24 -2
- data/cucumber.yml +1 -1
- data/features/.nav +57 -0
- data/features/Autotest.md +38 -0
- data/features/Changelog.md +269 -0
- data/features/README.md +17 -0
- data/features/Upgrade.md +320 -0
- data/features/command_line/README.md +28 -0
- data/features/command_line/configure.feature +18 -15
- data/features/command_line/example_name_option.feature +37 -23
- data/features/command_line/exit_status.feature +16 -31
- data/features/command_line/format_option.feature +73 -0
- data/features/command_line/line_number_appended_to_path.feature +25 -27
- data/features/command_line/line_number_option.feature +11 -10
- data/features/command_line/rake_task.feature +68 -0
- data/features/command_line/tag.feature +90 -0
- data/features/configuration/alias_example_to.feature +48 -0
- data/features/configuration/custom_settings.feature +8 -10
- data/features/configuration/fail_fast.feature +77 -0
- data/features/configuration/read_options_from_file.feature +42 -26
- data/features/example_groups/basic_structure.feature +55 -0
- data/features/example_groups/shared_context.feature +74 -0
- data/features/example_groups/shared_example_group.feature +56 -41
- data/features/expectation_framework_integration/configure_expectation_framework.feature +73 -0
- data/features/filtering/exclusion_filters.feature +69 -9
- data/features/filtering/if_and_unless.feature +168 -0
- data/features/filtering/inclusion_filters.feature +58 -26
- data/features/filtering/run_all_when_everything_filtered.feature +46 -0
- data/features/formatters/custom_formatter.feature +17 -13
- data/features/formatters/text_formatter.feature +43 -0
- data/features/helper_methods/arbitrary_methods.feature +40 -0
- data/features/helper_methods/let.feature +50 -0
- data/features/helper_methods/modules.feature +149 -0
- data/features/hooks/around_hooks.feature +99 -69
- data/features/hooks/before_and_after_hooks.feature +74 -40
- data/features/hooks/filtering.feature +227 -0
- data/features/metadata/current_example.feature +17 -0
- data/features/metadata/described_class.feature +17 -0
- data/features/metadata/user_defined.feature +111 -0
- data/features/mock_framework_integration/use_any_framework.feature +106 -0
- data/features/mock_framework_integration/use_flexmock.feature +84 -11
- data/features/mock_framework_integration/use_mocha.feature +85 -11
- data/features/mock_framework_integration/use_rr.feature +86 -11
- data/features/mock_framework_integration/use_rspec.feature +85 -11
- data/features/pending/pending_examples.feature +143 -5
- data/features/spec_files/arbitrary_file_suffix.feature +2 -2
- data/features/step_definitions/additional_cli_steps.rb +30 -0
- data/features/subject/attribute_of_subject.feature +93 -15
- data/features/subject/explicit_subject.feature +28 -17
- data/features/subject/implicit_receiver.feature +29 -0
- data/features/subject/implicit_subject.feature +9 -10
- data/features/support/env.rb +6 -1
- data/lib/autotest/discover.rb +1 -0
- data/lib/autotest/rspec2.rb +15 -11
- data/lib/rspec/autorun.rb +2 -0
- data/lib/rspec/core/backward_compatibility.rb +33 -4
- data/lib/rspec/core/command_line.rb +4 -28
- data/lib/rspec/core/command_line_configuration.rb +16 -16
- data/lib/rspec/core/configuration.rb +279 -89
- data/lib/rspec/core/configuration_options.rb +46 -35
- data/lib/rspec/core/deprecation.rb +1 -1
- data/lib/rspec/core/drb_command_line.rb +5 -11
- data/lib/rspec/core/example.rb +63 -39
- data/lib/rspec/core/example_group.rb +109 -59
- data/lib/rspec/core/expecting/with_rspec.rb +11 -0
- data/lib/rspec/core/expecting/with_stdlib.rb +9 -0
- data/lib/rspec/core/extensions/kernel.rb +1 -1
- data/lib/rspec/core/extensions/object.rb +1 -3
- data/lib/rspec/core/formatters/base_formatter.rb +22 -11
- data/lib/rspec/core/formatters/base_text_formatter.rb +46 -30
- data/lib/rspec/core/formatters/documentation_formatter.rb +4 -2
- data/lib/rspec/core/formatters/helpers.rb +0 -4
- data/lib/rspec/core/formatters/html_formatter.rb +146 -41
- data/lib/rspec/core/formatters/progress_formatter.rb +1 -0
- data/lib/rspec/core/formatters/snippet_extractor.rb +1 -1
- data/lib/rspec/core/formatters/text_mate_formatter.rb +3 -1
- data/lib/rspec/core/hooks.rb +55 -17
- data/lib/rspec/core/metadata.rb +75 -64
- data/lib/rspec/core/metadata_hash_builder.rb +93 -0
- data/lib/rspec/core/mocking/with_flexmock.rb +2 -0
- data/lib/rspec/core/mocking/with_mocha.rb +2 -0
- data/lib/rspec/core/mocking/with_rr.rb +2 -0
- data/lib/rspec/core/mocking/with_rspec.rb +3 -1
- data/lib/rspec/core/option_parser.rb +48 -5
- data/lib/rspec/core/pending.rb +22 -4
- data/lib/rspec/core/rake_task.rb +64 -28
- data/lib/rspec/core/reporter.rb +3 -2
- data/lib/rspec/core/ruby_project.rb +2 -2
- data/lib/rspec/core/runner.rb +50 -6
- data/lib/rspec/core/shared_context.rb +16 -0
- data/lib/rspec/core/shared_example_group.rb +19 -4
- data/lib/rspec/core/subject.rb +92 -65
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +83 -25
- data/lib/rspec/core.rb +40 -24
- data/lib/rspec/monkey/spork/test_framework/rspec.rb +1 -0
- data/rspec-core.gemspec +4 -25
- data/script/FullBuildRakeFile +63 -0
- data/script/cucumber +1 -0
- data/script/full_build +1 -0
- data/script/spec +1 -0
- data/spec/autotest/discover_spec.rb +19 -0
- data/spec/autotest/failed_results_re_spec.rb +25 -9
- data/spec/autotest/rspec_spec.rb +32 -41
- data/spec/rspec/core/command_line_spec.rb +62 -7
- data/spec/rspec/core/configuration_options_spec.rb +184 -148
- data/spec/rspec/core/configuration_spec.rb +406 -108
- data/spec/rspec/core/deprecations_spec.rb +38 -1
- data/spec/rspec/core/drb_command_line_spec.rb +21 -56
- data/spec/rspec/core/example_group_spec.rb +366 -127
- data/spec/rspec/core/example_spec.rb +125 -45
- data/spec/rspec/core/formatters/base_formatter_spec.rb +61 -1
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +39 -5
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +7 -6
- data/spec/rspec/core/formatters/helpers_spec.rb +1 -1
- data/spec/rspec/core/formatters/html_formatted-1.8.6.html +199 -81
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +199 -83
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +199 -81
- data/spec/rspec/core/formatters/html_formatted-1.9.1.html +206 -81
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +206 -61
- data/spec/rspec/core/formatters/html_formatter_spec.rb +17 -9
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +1 -1
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +199 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +199 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +199 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +206 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +206 -81
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +22 -7
- data/spec/rspec/core/hooks_filtering_spec.rb +128 -5
- data/spec/rspec/core/hooks_spec.rb +90 -4
- data/spec/rspec/core/metadata_spec.rb +176 -163
- data/spec/rspec/core/option_parser_spec.rb +73 -6
- data/spec/rspec/core/pending_example_spec.rb +137 -35
- data/spec/rspec/core/rake_task_spec.rb +62 -29
- data/spec/rspec/core/reporter_spec.rb +20 -4
- data/spec/rspec/core/resources/formatter_specs.rb +25 -1
- data/spec/rspec/core/rspec_matchers_spec.rb +45 -0
- data/spec/rspec/core/runner_spec.rb +60 -10
- data/spec/rspec/core/shared_context_spec.rb +30 -0
- data/spec/rspec/core/shared_example_group_spec.rb +59 -23
- data/spec/rspec/core/subject_spec.rb +136 -0
- data/spec/rspec/core/world_spec.rb +211 -68
- data/spec/rspec/core_spec.rb +28 -0
- data/spec/spec_helper.rb +41 -23
- data/spec/support/matchers.rb +44 -13
- data/spec/support/shared_example_groups.rb +41 -0
- data/spec/support/spec_files.rb +44 -0
- data/spec.txt +1126 -0
- metadata +99 -168
- data/.treasure_map.rb +0 -23
- data/History.md +0 -30
- data/Upgrade.markdown +0 -150
- data/autotest/discover.rb +0 -2
- data/features/README.markdown +0 -12
- data/features/example_groups/describe_aliases.feature +0 -25
- data/features/example_groups/nested_groups.feature +0 -44
- data/features/hooks/described_class.feature +0 -14
- data/features/hooks/halt.feature +0 -26
- data/lib/rspec/core/around_proxy.rb +0 -14
- data/lib/rspec/core/formatters.rb +0 -8
- data/spec/ruby_forker.rb +0 -13
- data/specs.watchr +0 -59
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'rspec/core/formatters/base_formatter'
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Core
|
|
3
5
|
module Formatters
|
|
@@ -13,32 +15,9 @@ module RSpec
|
|
|
13
15
|
output.puts
|
|
14
16
|
output.puts "Failures:"
|
|
15
17
|
failed_examples.each_with_index do |example, index|
|
|
16
|
-
output.puts
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
padding = ' '
|
|
20
|
-
if exception.is_a?(RSpec::Core::PendingExampleFixedError)
|
|
21
|
-
output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
|
|
22
|
-
output.puts "#{padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised."
|
|
23
|
-
else
|
|
24
|
-
output.puts "#{short_padding}#{index.next}) #{example.full_description}"
|
|
25
|
-
output.puts "#{padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
|
|
26
|
-
exception.message.split("\n").each do |line|
|
|
27
|
-
output.puts "#{padding}#{red(line)}"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
example.example_group.ancestors.push(example.example_group).each do |group|
|
|
31
|
-
if group.metadata[:shared_group_name]
|
|
32
|
-
output.puts "#{padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
|
|
33
|
-
"#{backtrace_line(group.metadata[:example_group][:location])}"
|
|
34
|
-
break
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
format_backtrace(exception.backtrace, example).each do |backtrace_info|
|
|
40
|
-
output.puts grey("#{padding}# #{backtrace_info}")
|
|
41
|
-
end
|
|
18
|
+
output.puts
|
|
19
|
+
dump_pending_example_fixed(example, index) || dump_failure(example, index)
|
|
20
|
+
dump_backtrace(example)
|
|
42
21
|
end
|
|
43
22
|
end
|
|
44
23
|
|
|
@@ -67,7 +46,7 @@ module RSpec
|
|
|
67
46
|
output.puts "\nTop #{sorted_examples.size} slowest examples:\n"
|
|
68
47
|
sorted_examples.each do |example|
|
|
69
48
|
output.puts " #{example.full_description}"
|
|
70
|
-
output.puts grey(" #{red(format_seconds(example.execution_result[:run_time]))} #{red("seconds")} #{format_caller(example.
|
|
49
|
+
output.puts grey(" #{red(format_seconds(example.execution_result[:run_time]))} #{red("seconds")} #{format_caller(example.location)}")
|
|
71
50
|
end
|
|
72
51
|
end
|
|
73
52
|
|
|
@@ -84,8 +63,8 @@ module RSpec
|
|
|
84
63
|
output.puts "Pending:"
|
|
85
64
|
pending_examples.each do |pending_example|
|
|
86
65
|
output.puts yellow(" #{pending_example.full_description}")
|
|
87
|
-
output.puts grey(" # #{pending_example.
|
|
88
|
-
output.puts grey(" # #{format_caller(pending_example.
|
|
66
|
+
output.puts grey(" # #{pending_example.execution_result[:pending_message]}")
|
|
67
|
+
output.puts grey(" # #{format_caller(pending_example.location)}")
|
|
89
68
|
end
|
|
90
69
|
end
|
|
91
70
|
end
|
|
@@ -132,6 +111,14 @@ module RSpec
|
|
|
132
111
|
color(text, "\e[90m")
|
|
133
112
|
end
|
|
134
113
|
|
|
114
|
+
def short_padding
|
|
115
|
+
' '
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def long_padding
|
|
119
|
+
' '
|
|
120
|
+
end
|
|
121
|
+
|
|
135
122
|
private
|
|
136
123
|
|
|
137
124
|
def pluralize(count, string)
|
|
@@ -142,8 +129,37 @@ module RSpec
|
|
|
142
129
|
backtrace_line(caller_info.to_s.split(':in `block').first)
|
|
143
130
|
end
|
|
144
131
|
|
|
145
|
-
|
|
132
|
+
def dump_backtrace(example)
|
|
133
|
+
format_backtrace(example.execution_result[:exception].backtrace, example).each do |backtrace_info|
|
|
134
|
+
output.puts grey("#{long_padding}# #{backtrace_info}")
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def dump_pending_example_fixed(example, index)
|
|
139
|
+
if RSpec::Core::PendingExampleFixedError === example.execution_result[:exception]
|
|
140
|
+
output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
|
|
141
|
+
output.puts blue("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
|
|
142
|
+
true
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def dump_failure(example, index)
|
|
147
|
+
exception = example.execution_result[:exception]
|
|
148
|
+
output.puts "#{short_padding}#{index.next}) #{example.full_description}"
|
|
149
|
+
output.puts "#{long_padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
|
|
150
|
+
output.puts "#{long_padding}#{red(exception.class.name << ":")}" unless exception.class.name =~ /RSpec/
|
|
151
|
+
exception.message.split("\n").each { |line| output.puts "#{long_padding} #{red(line)}" } if exception.message
|
|
146
152
|
|
|
153
|
+
example.example_group.ancestors.push(example.example_group).each do |group|
|
|
154
|
+
if group.metadata[:shared_group_name]
|
|
155
|
+
output.puts "#{long_padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
|
|
156
|
+
"#{backtrace_line(group.metadata[:example_group][:location])}"
|
|
157
|
+
break
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
end
|
|
147
163
|
end
|
|
148
164
|
end
|
|
149
165
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'rspec/core/formatters/base_text_formatter'
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Core
|
|
3
5
|
module Formatters
|
|
@@ -13,7 +15,7 @@ module RSpec
|
|
|
13
15
|
super(example_group)
|
|
14
16
|
|
|
15
17
|
output.puts if @group_level == 0
|
|
16
|
-
output.puts "#{
|
|
18
|
+
output.puts "#{current_indentation}#{example_group.description}"
|
|
17
19
|
|
|
18
20
|
@group_level += 1
|
|
19
21
|
end
|
|
@@ -34,7 +36,7 @@ module RSpec
|
|
|
34
36
|
|
|
35
37
|
def example_failed(example)
|
|
36
38
|
super(example)
|
|
37
|
-
output.puts failure_output(example, example.execution_result[:
|
|
39
|
+
output.puts failure_output(example, example.execution_result[:exception])
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
def failure_output(example, exception)
|
|
@@ -7,13 +7,6 @@ module RSpec
|
|
|
7
7
|
class HtmlFormatter < BaseTextFormatter
|
|
8
8
|
include ERB::Util # for the #h method
|
|
9
9
|
|
|
10
|
-
def method_missing(m, *a, &b)
|
|
11
|
-
# no-op
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def message(message)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
10
|
def initialize(output)
|
|
18
11
|
super(output)
|
|
19
12
|
@example_group_number = 0
|
|
@@ -21,6 +14,15 @@ module RSpec
|
|
|
21
14
|
@header_red = nil
|
|
22
15
|
end
|
|
23
16
|
|
|
17
|
+
private
|
|
18
|
+
def method_missing(m, *a, &b)
|
|
19
|
+
# no-op
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
public
|
|
23
|
+
def message(message)
|
|
24
|
+
end
|
|
25
|
+
|
|
24
26
|
# The number of the currently running example_group
|
|
25
27
|
def example_group_number
|
|
26
28
|
@example_group_number
|
|
@@ -46,9 +48,9 @@ module RSpec
|
|
|
46
48
|
@output.puts " </dl>"
|
|
47
49
|
@output.puts "</div>"
|
|
48
50
|
end
|
|
49
|
-
@output.puts "<div class=\"example_group\">"
|
|
50
|
-
@output.puts " <dl>"
|
|
51
|
-
@output.puts " <dt id=\"example_group_#{example_group_number}\">#{h(example_group.description)}</dt>"
|
|
51
|
+
@output.puts "<div id=\"div_group_#{example_group_number}\" class=\"example_group passed\">"
|
|
52
|
+
@output.puts " <dl #{current_indentation}>"
|
|
53
|
+
@output.puts " <dt id=\"example_group_#{example_group_number}\" class=\"passed\">#{h(example_group.description)}</dt>"
|
|
52
54
|
@output.flush
|
|
53
55
|
end
|
|
54
56
|
|
|
@@ -65,24 +67,24 @@ module RSpec
|
|
|
65
67
|
|
|
66
68
|
def example_passed(example)
|
|
67
69
|
move_progress
|
|
68
|
-
@output.puts " <dd class=\"
|
|
70
|
+
@output.puts " <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span></dd>"
|
|
69
71
|
@output.flush
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
def example_failed(example)
|
|
73
|
-
|
|
74
|
-
exception = example.metadata[:execution_result][:
|
|
75
|
+
super(example)
|
|
76
|
+
exception = example.metadata[:execution_result][:exception]
|
|
75
77
|
extra = extra_failure_content(exception)
|
|
76
|
-
failure_style = 'failed'
|
|
77
78
|
failure_style = RSpec::Core::PendingExampleFixedError === exception ? 'pending_fixed' : 'failed'
|
|
78
79
|
@output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>" unless @header_red
|
|
79
80
|
@header_red = true
|
|
81
|
+
@output.puts " <script type=\"text/javascript\">makeRed('div_group_#{example_group_number}');</script>" unless @example_group_red
|
|
80
82
|
@output.puts " <script type=\"text/javascript\">makeRed('example_group_#{example_group_number}');</script>" unless @example_group_red
|
|
81
83
|
@example_group_red = true
|
|
82
84
|
move_progress
|
|
83
|
-
@output.puts " <dd class=\"
|
|
85
|
+
@output.puts " <dd class=\"example #{failure_style}\">"
|
|
84
86
|
@output.puts " <span class=\"failed_spec_name\">#{h(example.description)}</span>"
|
|
85
|
-
@output.puts " <div class=\"failure\" id=\"failure_#{
|
|
87
|
+
@output.puts " <div class=\"failure\" id=\"failure_#{@failed_examples.size}\">"
|
|
86
88
|
@output.puts " <div class=\"message\"><pre>#{h(exception.message)}</pre></div>" unless exception.nil?
|
|
87
89
|
@output.puts " <div class=\"backtrace\"><pre>#{format_backtrace(exception.backtrace, example).join("\n")}</pre></div>" if exception
|
|
88
90
|
@output.puts extra unless extra == ""
|
|
@@ -94,9 +96,10 @@ module RSpec
|
|
|
94
96
|
def example_pending(example)
|
|
95
97
|
message = example.metadata[:execution_result][:pending_message]
|
|
96
98
|
@output.puts " <script type=\"text/javascript\">makeYellow('rspec-header');</script>" unless @header_red
|
|
99
|
+
@output.puts " <script type=\"text/javascript\">makeYellow('div_group_#{example_group_number}');</script>" unless @example_group_red
|
|
97
100
|
@output.puts " <script type=\"text/javascript\">makeYellow('example_group_#{example_group_number}');</script>" unless @example_group_red
|
|
98
101
|
move_progress
|
|
99
|
-
@output.puts " <dd class=\"
|
|
102
|
+
@output.puts " <dd class=\"example not_implemented\"><span class=\"not_implemented_spec_name\">#{h(example.description)} (PENDING: #{h(message)})</span></dd>"
|
|
100
103
|
@output.flush
|
|
101
104
|
end
|
|
102
105
|
|
|
@@ -133,7 +136,8 @@ module RSpec
|
|
|
133
136
|
if dry_run?
|
|
134
137
|
totals = "This was a dry-run"
|
|
135
138
|
else
|
|
136
|
-
totals =
|
|
139
|
+
totals = "#{example_count} example#{'s' unless example_count == 1}, "
|
|
140
|
+
totals << "#{failure_count} failure#{'s' unless failure_count == 1}"
|
|
137
141
|
totals << ", #{pending_count} pending" if pending_count > 0
|
|
138
142
|
end
|
|
139
143
|
@output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{duration} seconds</strong>\";</script>"
|
|
@@ -144,6 +148,10 @@ module RSpec
|
|
|
144
148
|
@output.puts "</html>"
|
|
145
149
|
@output.flush
|
|
146
150
|
end
|
|
151
|
+
|
|
152
|
+
def current_indentation
|
|
153
|
+
"style=\"margin-left: #{(example_group.ancestors.size - 1) * 15}px;\""
|
|
154
|
+
end
|
|
147
155
|
|
|
148
156
|
def html_header
|
|
149
157
|
<<-EOF
|
|
@@ -187,36 +195,97 @@ EOF
|
|
|
187
195
|
<h1>RSpec Code Examples</h1>
|
|
188
196
|
</div>
|
|
189
197
|
|
|
198
|
+
<div id="display-filters">
|
|
199
|
+
<input id="passed_checkbox" name="passed_checkbox" type="checkbox" checked onchange="apply_filters()" value="1"> <label for="passed_checkbox">Passed</label>
|
|
200
|
+
<input id="failed_checkbox" name="failed_checkbox" type="checkbox" checked onchange="apply_filters()" value="2"> <label for="failed_checkbox">Failed</label>
|
|
201
|
+
<input id="pending_checkbox" name="pending_checkbox" type="checkbox" checked onchange="apply_filters()" value="3"> <label for="pending_checkbox">Pending</label>
|
|
202
|
+
</div>
|
|
203
|
+
|
|
190
204
|
<div id="summary">
|
|
191
205
|
<p id="totals"> </p>
|
|
192
206
|
<p id="duration"> </p>
|
|
193
207
|
</div>
|
|
194
208
|
</div>
|
|
195
209
|
|
|
210
|
+
|
|
196
211
|
<div class="results">
|
|
197
212
|
EOF
|
|
198
213
|
end
|
|
199
214
|
|
|
200
215
|
def global_scripts
|
|
201
216
|
<<-EOF
|
|
217
|
+
|
|
218
|
+
function addClass(element_id, classname) {
|
|
219
|
+
document.getElementById(element_id).className += (" " + classname);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function removeClass(element_id, classname) {
|
|
223
|
+
var elem = document.getElementById(element_id);
|
|
224
|
+
var classlist = elem.className.replace(classname,'');
|
|
225
|
+
elem.className = classlist;
|
|
226
|
+
}
|
|
227
|
+
|
|
202
228
|
function moveProgressBar(percentDone) {
|
|
203
229
|
document.getElementById("rspec-header").style.width = percentDone +"%";
|
|
204
230
|
}
|
|
231
|
+
|
|
205
232
|
function makeRed(element_id) {
|
|
206
|
-
|
|
207
|
-
|
|
233
|
+
removeClass(element_id, 'passed');
|
|
234
|
+
removeClass(element_id, 'not_implemented');
|
|
235
|
+
addClass(element_id,'failed');
|
|
208
236
|
}
|
|
209
237
|
|
|
210
238
|
function makeYellow(element_id) {
|
|
211
|
-
|
|
212
|
-
{
|
|
213
|
-
|
|
214
|
-
|
|
239
|
+
var elem = document.getElementById(element_id);
|
|
240
|
+
if (elem.className.indexOf("failed") == -1) { // class doesn't includes failed
|
|
241
|
+
if (elem.className.indexOf("not_implemented") == -1) { // class doesn't include not_implemented
|
|
242
|
+
removeClass(element_id, 'passed');
|
|
243
|
+
addClass(element_id,'not_implemented');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function apply_filters() {
|
|
249
|
+
var passed_filter = document.getElementById('passed_checkbox').checked;
|
|
250
|
+
var failed_filter = document.getElementById('failed_checkbox').checked;
|
|
251
|
+
var pending_filter = document.getElementById('pending_checkbox').checked;
|
|
252
|
+
|
|
253
|
+
assign_display_style("example passed", passed_filter);
|
|
254
|
+
assign_display_style("example failed", failed_filter);
|
|
255
|
+
assign_display_style("example not_implemented", pending_filter);
|
|
256
|
+
|
|
257
|
+
assign_display_style_for_group("example_group passed", passed_filter);
|
|
258
|
+
assign_display_style_for_group("example_group not_implemented", pending_filter, pending_filter || passed_filter);
|
|
259
|
+
assign_display_style_for_group("example_group failed", failed_filter, failed_filter || pending_filter || passed_filter);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function get_display_style(display_flag) {
|
|
263
|
+
var style_mode = 'none';
|
|
264
|
+
if (display_flag == true) {
|
|
265
|
+
style_mode = 'block';
|
|
266
|
+
}
|
|
267
|
+
return style_mode;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function assign_display_style(classname, display_flag) {
|
|
271
|
+
var style_mode = get_display_style(display_flag);
|
|
272
|
+
var elems = document.getElementsByClassName(classname)
|
|
273
|
+
for (var i=0; i<elems.length;i++) {
|
|
274
|
+
elems[i].style.display = style_mode;
|
|
215
275
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function assign_display_style_for_group(classname, display_flag, subgroup_flag) {
|
|
279
|
+
var display_style_mode = get_display_style(display_flag);
|
|
280
|
+
var subgroup_style_mode = get_display_style(subgroup_flag);
|
|
281
|
+
var elems = document.getElementsByClassName(classname)
|
|
282
|
+
for (var i=0; i<elems.length;i++) {
|
|
283
|
+
var style_mode = display_style_mode;
|
|
284
|
+
if ((display_flag != subgroup_flag) && (elems[i].getElementsByTagName('dt')[0].innerHTML.indexOf(", ") != -1)) {
|
|
285
|
+
elems[i].style.display = subgroup_style_mode;
|
|
286
|
+
} else {
|
|
287
|
+
elems[i].style.display = display_style_mode;
|
|
288
|
+
}
|
|
220
289
|
}
|
|
221
290
|
}
|
|
222
291
|
EOF
|
|
@@ -236,13 +305,21 @@ EOF
|
|
|
236
305
|
position: absolute;
|
|
237
306
|
}
|
|
238
307
|
|
|
308
|
+
#label {
|
|
309
|
+
float:left;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
#display-filters {
|
|
313
|
+
float:left;
|
|
314
|
+
padding: 28px 0 0 40%;
|
|
315
|
+
font-family: "Lucida Grande", Helvetica, sans-serif;
|
|
316
|
+
}
|
|
317
|
+
|
|
239
318
|
#summary {
|
|
240
|
-
|
|
319
|
+
float:right;
|
|
320
|
+
padding: 5px 10px;
|
|
241
321
|
font-family: "Lucida Grande", Helvetica, sans-serif;
|
|
242
322
|
text-align: right;
|
|
243
|
-
top: 0px;
|
|
244
|
-
right: 0px;
|
|
245
|
-
float:right;
|
|
246
323
|
}
|
|
247
324
|
|
|
248
325
|
#summary p {
|
|
@@ -275,30 +352,58 @@ dd {
|
|
|
275
352
|
padding: 3px 3px 3px 18px;
|
|
276
353
|
}
|
|
277
354
|
|
|
278
|
-
|
|
355
|
+
|
|
356
|
+
dd.example.passed {
|
|
279
357
|
border-left: 5px solid #65C400;
|
|
280
358
|
border-bottom: 1px solid #65C400;
|
|
281
359
|
background: #DBFFB4; color: #3D7700;
|
|
282
360
|
}
|
|
283
361
|
|
|
284
|
-
dd.
|
|
285
|
-
border-left: 5px solid #C20000;
|
|
286
|
-
border-bottom: 1px solid #C20000;
|
|
287
|
-
color: #C20000; background: #FFFBD3;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
dd.spec.not_implemented {
|
|
362
|
+
dd.example.not_implemented {
|
|
291
363
|
border-left: 5px solid #FAF834;
|
|
292
364
|
border-bottom: 1px solid #FAF834;
|
|
293
365
|
background: #FCFB98; color: #131313;
|
|
294
366
|
}
|
|
295
367
|
|
|
296
|
-
dd.
|
|
368
|
+
dd.example.pending_fixed {
|
|
297
369
|
border-left: 5px solid #0000C2;
|
|
298
370
|
border-bottom: 1px solid #0000C2;
|
|
299
371
|
color: #0000C2; background: #D3FBFF;
|
|
300
372
|
}
|
|
301
373
|
|
|
374
|
+
dd.example.failed {
|
|
375
|
+
border-left: 5px solid #C20000;
|
|
376
|
+
border-bottom: 1px solid #C20000;
|
|
377
|
+
color: #C20000; background: #FFFBD3;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
dt.not_implemented {
|
|
382
|
+
color: #000000; background: #FAF834;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
dt.pending_fixed {
|
|
386
|
+
color: #FFFFFF; background: #C40D0D;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
dt.failed {
|
|
390
|
+
color: #FFFFFF; background: #C40D0D;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
#rspec-header.not_implemented {
|
|
395
|
+
color: #000000; background: #FAF834;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
#rspec-header.pending_fixed {
|
|
399
|
+
color: #FFFFFF; background: #C40D0D;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
#rspec-header.failed {
|
|
403
|
+
color: #FFFFFF; background: #C40D0D;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
|
|
302
407
|
.backtrace {
|
|
303
408
|
color: #000;
|
|
304
409
|
font-size: 12px;
|
|
@@ -7,9 +7,11 @@ module RSpec
|
|
|
7
7
|
class TextMateFormatter < HtmlFormatter
|
|
8
8
|
def backtrace_line(line)
|
|
9
9
|
if line = super(line)
|
|
10
|
-
line.sub!(/([^:]*\.rb):(\d*)/) do
|
|
10
|
+
line.sub!(/([^:]*\.e?rb):(\d*)/) do
|
|
11
11
|
"<a href=\"txmt://open?url=file://#{File.expand_path($1)}&line=#{$2}\">#{$1}:#{$2}</a> "
|
|
12
12
|
end
|
|
13
|
+
|
|
14
|
+
line
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
end
|
data/lib/rspec/core/hooks.rb
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
module RSpec
|
|
2
2
|
module Core
|
|
3
3
|
module Hooks
|
|
4
|
+
include MetadataHashBuilder::WithConfigWarning
|
|
4
5
|
|
|
5
6
|
class Hook
|
|
6
7
|
attr_reader :options
|
|
7
8
|
|
|
8
|
-
def initialize(options, block)
|
|
9
|
+
def initialize(options, &block)
|
|
9
10
|
@options = options
|
|
11
|
+
raise "no block given for #{self.class::TYPE} hook" unless block
|
|
10
12
|
@block = block
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
def options_apply?(
|
|
14
|
-
!
|
|
15
|
+
def options_apply?(example_or_group)
|
|
16
|
+
!example_or_group || example_or_group.apply?(:all?, options)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def to_proc
|
|
@@ -24,6 +26,7 @@ module RSpec
|
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
class BeforeHook < Hook
|
|
29
|
+
TYPE = 'before'
|
|
27
30
|
def run_in(example_group_instance)
|
|
28
31
|
if example_group_instance
|
|
29
32
|
example_group_instance.instance_eval(&self)
|
|
@@ -34,6 +37,7 @@ module RSpec
|
|
|
34
37
|
end
|
|
35
38
|
|
|
36
39
|
class AfterHook < Hook
|
|
40
|
+
TYPE = 'after'
|
|
37
41
|
def run_in(example_group_instance)
|
|
38
42
|
if example_group_instance
|
|
39
43
|
example_group_instance.instance_eval_with_rescue(&self)
|
|
@@ -44,20 +48,25 @@ module RSpec
|
|
|
44
48
|
end
|
|
45
49
|
|
|
46
50
|
class AroundHook < Hook
|
|
51
|
+
TYPE = 'around'
|
|
47
52
|
def call(wrapped_example)
|
|
48
53
|
@block.call(wrapped_example)
|
|
49
54
|
end
|
|
50
55
|
end
|
|
51
56
|
|
|
52
57
|
class HookCollection < Array
|
|
53
|
-
def find_hooks_for(
|
|
54
|
-
|
|
58
|
+
def find_hooks_for(example_or_group)
|
|
59
|
+
self.class.new(select {|hook| hook.options_apply?(example_or_group)})
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def without_hooks_for(example_or_group)
|
|
63
|
+
self.class.new(reject {|hook| hook.options_apply?(example_or_group)})
|
|
55
64
|
end
|
|
56
65
|
end
|
|
57
66
|
|
|
58
67
|
class BeforeHooks < HookCollection
|
|
59
68
|
def run_all(example_group_instance)
|
|
60
|
-
each {|h| h.run_in(example_group_instance) }
|
|
69
|
+
each {|h| h.run_in(example_group_instance) } unless empty?
|
|
61
70
|
end
|
|
62
71
|
|
|
63
72
|
def run_all!(example_group_instance)
|
|
@@ -67,7 +76,7 @@ module RSpec
|
|
|
67
76
|
|
|
68
77
|
class AfterHooks < HookCollection
|
|
69
78
|
def run_all(example_group_instance)
|
|
70
|
-
reverse.each {|h| h.run_in(example_group_instance) }
|
|
79
|
+
reverse.each {|h| h.run_in(example_group_instance) } unless empty?
|
|
71
80
|
end
|
|
72
81
|
|
|
73
82
|
def run_all!(example_group_instance)
|
|
@@ -85,16 +94,19 @@ module RSpec
|
|
|
85
94
|
}
|
|
86
95
|
end
|
|
87
96
|
|
|
88
|
-
def before(
|
|
89
|
-
|
|
97
|
+
def before(*args, &block)
|
|
98
|
+
scope, options = scope_and_options_from(*args)
|
|
99
|
+
hooks[:before][scope] << BeforeHook.new(options, &block)
|
|
90
100
|
end
|
|
91
101
|
|
|
92
|
-
def after(
|
|
93
|
-
|
|
102
|
+
def after(*args, &block)
|
|
103
|
+
scope, options = scope_and_options_from(*args)
|
|
104
|
+
hooks[:after][scope] << AfterHook.new(options, &block)
|
|
94
105
|
end
|
|
95
106
|
|
|
96
|
-
def around(
|
|
97
|
-
|
|
107
|
+
def around(*args, &block)
|
|
108
|
+
scope, options = scope_and_options_from(*args)
|
|
109
|
+
hooks[:around][scope] << AroundHook.new(options, &block)
|
|
98
110
|
end
|
|
99
111
|
|
|
100
112
|
# Runs all of the blocks stored with the hook in the context of the
|
|
@@ -109,12 +121,38 @@ module RSpec
|
|
|
109
121
|
hooks[hook][scope].run_all!(example_group_instance)
|
|
110
122
|
end
|
|
111
123
|
|
|
112
|
-
def run_hook_filtered(hook, scope, group, example_group_instance)
|
|
113
|
-
find_hook(hook, scope, group).run_all(example_group_instance)
|
|
124
|
+
def run_hook_filtered(hook, scope, group, example_group_instance, example = nil)
|
|
125
|
+
find_hook(hook, scope, group, example).run_all(example_group_instance)
|
|
114
126
|
end
|
|
115
127
|
|
|
116
|
-
def find_hook(hook, scope, example_group_class)
|
|
117
|
-
hooks[hook][scope].find_hooks_for(example_group_class)
|
|
128
|
+
def find_hook(hook, scope, example_group_class, example = nil)
|
|
129
|
+
found_hooks = hooks[hook][scope].find_hooks_for(example || example_group_class)
|
|
130
|
+
|
|
131
|
+
# ensure we don't re-run :all hooks that were applied to any of the parent groups
|
|
132
|
+
if scope == :all
|
|
133
|
+
super_klass = example_group_class.superclass
|
|
134
|
+
while super_klass != RSpec::Core::ExampleGroup
|
|
135
|
+
found_hooks = found_hooks.without_hooks_for(super_klass)
|
|
136
|
+
super_klass = super_klass.superclass
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
found_hooks
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
private
|
|
144
|
+
|
|
145
|
+
def scope_and_options_from(*args)
|
|
146
|
+
scope = if [:each, :all, :suite].include?(args.first)
|
|
147
|
+
args.shift
|
|
148
|
+
elsif args.any? { |a| a.is_a?(Symbol) }
|
|
149
|
+
raise ArgumentError.new("You must explicitly give a scope (:each, :all, or :suite) when using symbols as metadata for a hook.")
|
|
150
|
+
else
|
|
151
|
+
:each
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
options = build_metadata_hash_from(args)
|
|
155
|
+
return scope, options
|
|
118
156
|
end
|
|
119
157
|
end
|
|
120
158
|
end
|