rspec 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/CHANGES +12 -0
  2. data/README +4 -2
  3. data/Rakefile +14 -4
  4. data/bin/spec +7 -7
  5. data/bin/test2spec +13 -8
  6. data/lib/spec/api/helper/diff.rb +53 -0
  7. data/lib/spec/api/helper/instance_helper.rb +11 -11
  8. data/lib/spec/api/helper/instance_negator.rb +11 -11
  9. data/lib/spec/api/helper/kind_helper.rb +11 -11
  10. data/lib/spec/api/helper/kind_negator.rb +11 -11
  11. data/lib/spec/api/helper/respond_helper.rb +11 -11
  12. data/lib/spec/api/helper/respond_negator.rb +11 -11
  13. data/lib/spec/api/helper/should_base.rb +6 -6
  14. data/lib/spec/api/helper/should_helper.rb +35 -35
  15. data/lib/spec/api/helper/should_negator.rb +20 -20
  16. data/lib/spec/rake/spectask.rb +15 -6
  17. data/lib/spec/runner.rb +1 -0
  18. data/lib/spec/runner/backtrace_tweaker.rb +2 -0
  19. data/lib/spec/runner/base_text_formatter.rb +3 -1
  20. data/lib/spec/runner/html_formatter.rb +153 -0
  21. data/lib/spec/runner/option_parser.rb +9 -2
  22. data/lib/spec/runner/progress_bar_formatter.rb +4 -0
  23. data/lib/spec/runner/rdoc_formatter.rb +3 -0
  24. data/lib/spec/runner/reporter.rb +5 -5
  25. data/lib/spec/runner/specdoc_formatter.rb +3 -0
  26. data/lib/spec/test_to_spec/sexp_transformer.rb +1 -0
  27. data/lib/spec/test_to_spec/translation_test_runner.rb +10 -2
  28. data/lib/spec/version.rb +1 -1
  29. data/test/spec/api/helper/arbitrary_predicate_test.rb +49 -73
  30. data/test/spec/api/helper/diff_test.rb +60 -0
  31. data/test/spec/api/helper/equality_test.rb +14 -0
  32. data/test/spec/api/helper/should_have_test.rb +0 -29
  33. data/test/spec/api/helper/typing_test.rb +87 -87
  34. data/test/spec/api/sugar_test.rb +0 -6
  35. data/test/spec/runner/backtrace_tweaker_test.rb +8 -2
  36. data/test/spec/runner/html_formatter_test.rb +47 -0
  37. data/test/spec/runner/option_parser_test.rb +0 -5
  38. data/test/test_classes.rb +73 -0
  39. data/test/test_helper.rb +3 -0
  40. metadata +8 -49
  41. data/doc/README +0 -3
  42. data/doc/config.yaml +0 -2
  43. data/doc/plugin/syntax.rb +0 -60
  44. data/doc/plugin/version.rb +0 -19
  45. data/doc/src/core_team.page +0 -31
  46. data/doc/src/default.css +0 -199
  47. data/doc/src/default.template +0 -31
  48. data/doc/src/documentation/index.page +0 -188
  49. data/doc/src/documentation/meta.info +0 -22
  50. data/doc/src/documentation/mocks.page +0 -287
  51. data/doc/src/documentation/underscores.page +0 -21
  52. data/doc/src/examples.page +0 -9
  53. data/doc/src/images/David_and_Aslak.jpg +0 -0
  54. data/doc/src/images/Whats_That_Dude.jpg +0 -0
  55. data/doc/src/images/ducks1.png +0 -0
  56. data/doc/src/images/ul.gif +0 -0
  57. data/doc/src/index.page +0 -74
  58. data/doc/src/meta.info +0 -33
  59. data/doc/src/tools/index.page +0 -49
  60. data/doc/src/tools/meta.info +0 -18
  61. data/doc/src/tools/rails.page +0 -132
  62. data/doc/src/tools/rake.page +0 -21
  63. data/doc/src/tools/rcov.page +0 -28
  64. data/doc/src/tools/spec.page +0 -129
  65. data/doc/src/tools/test2spec.page +0 -103
  66. data/doc/src/tutorials/index.page +0 -52
  67. data/doc/src/tutorials/meta.info +0 -36
  68. data/doc/src/tutorials/notes.txt +0 -263
  69. data/doc/src/tutorials/stack.rb +0 -11
  70. data/doc/src/tutorials/stack_01.page +0 -226
  71. data/doc/src/tutorials/stack_02.page +0 -182
  72. data/doc/src/tutorials/stack_03.page +0 -283
  73. data/doc/src/tutorials/stack_04.page +0 -164
  74. data/doc/src/tutorials/stack_04.page.orig +0 -123
  75. data/doc/src/tutorials/stack_05.page +0 -90
  76. data/doc/src/tutorials/stack_05.page.orig +0 -124
  77. data/doc/src/tutorials/stack_06.page +0 -359
  78. data/doc/src/tutorials/stack_06.page.orig +0 -359
  79. data/doc/src/tutorials/stack_spec.rb +0 -25
  80. data/doc/src/ul.gif +0 -0
data/CHANGES CHANGED
@@ -1,5 +1,17 @@
1
1
  = RSpec Changelog
2
2
 
3
+ == Version 0.5.12
4
+ This release adds diff support for failure messages, a HTML formatter plus some other
5
+ minor enhancements.
6
+
7
+ * Added HTML formatter.
8
+ * Added fail_on_error option to spectask.
9
+ * Added support for diffing, using the lcs-diff Rubygem (#2648).
10
+ * Remove RSpec on Rails files from backtrace (#4694).
11
+ * All of RSpec's own tests run successfully after translation with test2spec.
12
+ * Added --verbose mode for test2spec - useful for debugging when classes fail to translate.
13
+ * Output of various formatters is now flushed - to get more continuous output.
14
+
3
15
  == Version 0.5.11
4
16
  This release makes test2spec usable with Rails (with some manual steps).
5
17
  See http://rspec.rubyforge.org/tools/rails.html for more details
data/README CHANGED
@@ -1,4 +1,4 @@
1
- In order to run RSpec's tests and generate the website, you must have RubyGems.
1
+ In order to run RSpec's tests and generate the gem and the website, you must have RubyGems.
2
2
  Then you must install the following gems:
3
3
 
4
4
  * rake
@@ -8,11 +8,13 @@ Then you must install the following gems:
8
8
  * webgen
9
9
  * RedCloth
10
10
  * syntax
11
+ * lcs-diff
11
12
 
12
13
  Note that RSpec itself - once built - doesn't have any dependencies outside the Ruby core
13
14
  and stdlib - with a few exceptions:
14
15
 
15
- * The test2spec command line uses ParseTree and RubyInline
16
+ * The spec command line uses lcs-diff when --diff is specified.
17
+ * The test2spec command line uses ParseTree and RubyInline.
16
18
  * The Spec::Rake::SpecTask needs RCov if RCov is enabled in the task.
17
19
 
18
20
  See http://rspec.rubyforge.org for further documentation.
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ require 'rcov/rcovtask'
12
12
  load File.dirname(__FILE__) + '/test/tasks/examples.rake'
13
13
  load File.dirname(__FILE__) + '/test/tasks/examples_specdoc.rake'
14
14
  load File.dirname(__FILE__) + '/test/tasks/examples_with_rcov.rake'
15
+ load File.dirname(__FILE__) + '/test/tasks/failing_examples_with_html.rake'
15
16
  load File.dirname(__FILE__) + '/test/tasks/rcov_verify.rake'
16
17
 
17
18
  PKG_NAME = "rspec"
@@ -21,8 +22,7 @@ PKG_FILES = FileList[
21
22
  '[A-Z]*',
22
23
  'lib/**/*.rb',
23
24
  'test/**/*.rb',
24
- 'examples/**/*.rb',
25
- 'doc/**/*'
25
+ 'examples/**/*'
26
26
  ]
27
27
 
28
28
  task :default => :test
@@ -45,7 +45,17 @@ end
45
45
 
46
46
  desc 'Translate our own tests to specs'
47
47
  task :test2spec do
48
+ rm_rf 'spec/translated'
48
49
  `bin/test2spec --force --template spec/test2spec.erb --specdir spec/translated test`
50
+ # Remove the spec translations that we don't care about.
51
+ rm 'spec/translated/spec/test_to_spec/sexp_transformer_assertion_spec.rb'
52
+ rm 'spec/translated/spec/test_to_spec/sexp_transformer_spec.rb'
53
+ end
54
+
55
+ desc 'Runs all RSpec specs - translated with test2spec from our own tests'
56
+ Spec::Rake::SpecTask.new('test2spec_test' => :test2spec) do |t|
57
+ t.spec_files = FileList['spec/**/*_spec.rb']
58
+ t.options = ['--diff']
49
59
  end
50
60
 
51
61
  desc 'Generate HTML documentation'
@@ -126,7 +136,7 @@ task :clobber do
126
136
  rm_rf 'spec/translated'
127
137
  end
128
138
 
129
- task :release => [:clobber, :verify_committed, :verify_user, :verify_password, :test, :publish_packages, :tag, :publish_website, :publish_news]
139
+ task :release => [:clobber, :test2spec_test, :verify_committed, :verify_user, :verify_password, :test, :publish_packages, :tag, :publish_website, :publish_news]
130
140
 
131
141
  desc "Verifies that there is no uncommitted code"
132
142
  task :verify_committed do
@@ -145,7 +155,7 @@ task :tag do
145
155
  end
146
156
 
147
157
  desc "Build the website with rdoc and rcov, but do not publish it"
148
- task :website => [:clobber, :rcov_verify, :webgen, :examples_specdoc, :rdoc]
158
+ task :website => [:clobber, :rcov_verify, :webgen, :failing_examples_with_html, :examples_specdoc, :rdoc]
149
159
 
150
160
  task :verify_user do
151
161
  raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
data/bin/spec CHANGED
@@ -5,13 +5,13 @@ $context_runner = ::Spec::Runner::OptionParser.create_context_runner(ARGV, false
5
5
 
6
6
  # If ARGV is a glob, it will actually each over each one of the matching files.
7
7
  ARGV.each do |file_or_dir|
8
- if File.directory?(file_or_dir)
9
- Dir["#{file_or_dir}/**/*.rb"].each do |file|
10
- require "#{file}"
11
- end
12
- else
13
- require file_or_dir
14
- end
8
+ if File.directory?(file_or_dir)
9
+ Dir["#{file_or_dir}/**/*.rb"].each do |file|
10
+ require "#{file}"
11
+ end
12
+ else
13
+ require file_or_dir
14
+ end
15
15
  end
16
16
 
17
17
  $context_runner.run(true)
@@ -14,7 +14,8 @@ require 'spec/test_to_spec/translation_test_runner'
14
14
  require 'spec/version'
15
15
 
16
16
  $test2spec_options = {
17
- :collision => :ask
17
+ :collision => :ask,
18
+ :verbose => false
18
19
  }
19
20
 
20
21
  opts = OptionParser.new do |opts|
@@ -51,6 +52,10 @@ opts = OptionParser.new do |opts|
51
52
  $test2spec_options[:quiet] = true
52
53
  end
53
54
 
55
+ opts.on("--verbose", "Be extra verbose (printing backtraces when classes can't be translated)") do
56
+ $test2spec_options[:verbose] = true
57
+ end
58
+
54
59
  opts.on("-v", "--version", "Show version") do
55
60
  puts "test2spec #{Spec::VERSION::DESCRIPTION}"
56
61
  exit
@@ -97,11 +102,11 @@ end
97
102
 
98
103
  # If ARGV is a glob, it will actually each over each one of the matching files.
99
104
  ARGV.each do |arg|
100
- if File.directory?(arg)
101
- Dir["#{arg}/**/*.rb"].each do |file|
102
- require "#{file}"
103
- end
104
- else
105
- require arg
106
- end
105
+ if File.directory?(arg)
106
+ Dir["#{arg}/**/*.rb"].each do |file|
107
+ require "#{file}"
108
+ end
109
+ else
110
+ require arg
111
+ end
107
112
  end
@@ -0,0 +1,53 @@
1
+ begin
2
+ require 'rubygems'
3
+ require 'diff/lcs/hunk'
4
+ rescue LoadError
5
+ raise "You must gem install diff-lcs to use this feature"
6
+ end
7
+
8
+ module Spec
9
+ class ShouldBase
10
+ unless defined?(RSPEC_TESTING)
11
+ alias old_default_message default_message
12
+ def default_message(expectation, expected=:no_expectation_specified)
13
+ result = old_default_message(expectation, expected)
14
+ if expected.is_a?(String)
15
+ result << "\nDiff:" << diff_as_string(@target.to_s, expected)
16
+ end
17
+ result
18
+ end
19
+ end
20
+
21
+ # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
22
+ def diff_as_string(data_old, data_new, format=:unified, context_lines=3)
23
+ data_old = data_old.split(/\n/).map! { |e| e.chomp }
24
+ data_new = data_new.split(/\n/).map! { |e| e.chomp }
25
+ output = ""
26
+ diffs = Diff::LCS.diff(data_old, data_new)
27
+ return output if diffs.empty?
28
+ oldhunk = hunk = nil
29
+ file_length_difference = 0
30
+ diffs.each do |piece|
31
+ begin
32
+ hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
33
+ file_length_difference)
34
+ file_length_difference = hunk.file_length_difference
35
+ next unless oldhunk
36
+ # Hunks may overlap, which is why we need to be careful when our
37
+ # diff includes lines of context. Otherwise, we might print
38
+ # redundant lines.
39
+ if (context_lines > 0) and hunk.overlaps?(oldhunk)
40
+ hunk.unshift(oldhunk)
41
+ else
42
+ output << oldhunk.diff(format)
43
+ end
44
+ ensure
45
+ oldhunk = hunk
46
+ output << "\n"
47
+ end
48
+ end
49
+ #Handle the last remaining hunk
50
+ output << oldhunk.diff(format) << "\n"
51
+ end
52
+ end
53
+ end
@@ -1,15 +1,15 @@
1
1
  module Spec
2
2
 
3
- class InstanceHelper < ShouldBase
4
-
5
- def initialize(target)
6
- @target = target
7
- end
8
-
9
- def of(expected_class)
10
- fail_with_message(default_message("should be an instance of", expected_class)) unless @target.instance_of? expected_class
11
- end
12
-
13
- end
3
+ class InstanceHelper < ShouldBase
4
+
5
+ def initialize(target)
6
+ @target = target
7
+ end
8
+
9
+ def of(expected_class)
10
+ fail_with_message(default_message("should be an instance of", expected_class)) unless @target.instance_of? expected_class
11
+ end
12
+
13
+ end
14
14
 
15
15
  end
@@ -1,15 +1,15 @@
1
1
  module Spec
2
2
 
3
- class InstanceNegator < ShouldBase
4
-
5
- def initialize(target)
6
- @target = target
7
- end
8
-
9
- def of(expected_class)
10
- fail_with_message(default_message("should not be an instance of", expected_class)) if @target.instance_of? expected_class
11
- end
12
-
13
- end
3
+ class InstanceNegator < ShouldBase
4
+
5
+ def initialize(target)
6
+ @target = target
7
+ end
8
+
9
+ def of(expected_class)
10
+ fail_with_message(default_message("should not be an instance of", expected_class)) if @target.instance_of? expected_class
11
+ end
12
+
13
+ end
14
14
 
15
15
  end
@@ -1,15 +1,15 @@
1
1
  module Spec
2
2
 
3
- class KindHelper < ShouldBase
4
-
5
- def initialize(target)
6
- @target = target
7
- end
8
-
9
- def of(expected_class)
10
- fail_with_message(default_message("should be a kind of", expected_class)) unless @target.kind_of? expected_class
11
- end
12
-
13
- end
3
+ class KindHelper < ShouldBase
4
+
5
+ def initialize(target)
6
+ @target = target
7
+ end
8
+
9
+ def of(expected_class)
10
+ fail_with_message(default_message("should be a kind of", expected_class)) unless @target.kind_of? expected_class
11
+ end
12
+
13
+ end
14
14
 
15
15
  end
@@ -1,15 +1,15 @@
1
1
  module Spec
2
2
 
3
- class KindNegator < ShouldBase
4
-
5
- def initialize(target)
6
- @target = target
7
- end
8
-
9
- def of(expected_class)
10
- fail_with_message(default_message("should not be a kind of", expected_class)) if @target.kind_of? expected_class
11
- end
12
-
13
- end
3
+ class KindNegator < ShouldBase
4
+
5
+ def initialize(target)
6
+ @target = target
7
+ end
8
+
9
+ def of(expected_class)
10
+ fail_with_message(default_message("should not be a kind of", expected_class)) if @target.kind_of? expected_class
11
+ end
12
+
13
+ end
14
14
 
15
15
  end
@@ -1,15 +1,15 @@
1
1
  module Spec
2
2
 
3
- class RespondHelper < ShouldBase
4
-
5
- def initialize(target)
6
- @target = target
7
- end
8
-
9
- def to(expected)
10
- fail_with_message(default_message("should respond to", expected)) unless @target.respond_to? expected
11
- end
12
-
13
- end
3
+ class RespondHelper < ShouldBase
4
+
5
+ def initialize(target)
6
+ @target = target
7
+ end
8
+
9
+ def to(expected)
10
+ fail_with_message(default_message("should respond to", expected)) unless @target.respond_to? expected
11
+ end
12
+
13
+ end
14
14
 
15
15
  end
@@ -1,15 +1,15 @@
1
1
  module Spec
2
2
 
3
- class RespondNegator < ShouldBase
4
-
5
- def initialize(target)
6
- @target = target
7
- end
8
-
9
- def to(expected)
10
- fail_with_message(default_message("should not respond to", expected)) if @target.respond_to? expected
11
- end
12
-
13
- end
3
+ class RespondNegator < ShouldBase
4
+
5
+ def initialize(target)
6
+ @target = target
7
+ end
8
+
9
+ def to(expected)
10
+ fail_with_message(default_message("should not respond to", expected)) if @target.respond_to? expected
11
+ end
12
+
13
+ end
14
14
 
15
15
  end
@@ -16,18 +16,18 @@ module Spec
16
16
 
17
17
  class ShouldBase
18
18
 
19
- def default_message(expectation, expected=:no_expectation_specified)
19
+ def default_message(expectation, expected=:no_expectation_specified)
20
20
  message = "#{@target.inspect_for_expectation_not_met_error} #{expectation}"
21
21
  if (expected != :no_expectation_specified)
22
22
  message << " " << expected.inspect_for_expectation_not_met_error
23
23
  end
24
24
  message
25
- end
25
+ end
26
26
 
27
- def fail_with_message(message)
28
- Kernel::raise(Spec::Api::ExpectationNotMetError.new(message))
29
- end
30
-
27
+ def fail_with_message(message)
28
+ Kernel::raise(Spec::Api::ExpectationNotMetError.new(message))
29
+ end
30
+
31
31
  end
32
32
 
33
33
  end
@@ -2,63 +2,63 @@ module Spec
2
2
 
3
3
  class ShouldHelper < ShouldBase
4
4
 
5
- def initialize(target)
6
- @target = target
7
- end
8
-
9
- def not
10
- ShouldNegator.new(@target)
11
- end
5
+ def initialize(target)
6
+ @target = target
7
+ end
8
+
9
+ def not
10
+ ShouldNegator.new(@target)
11
+ end
12
12
 
13
13
  def have(expected_number=nil)
14
14
  HaveHelper.new(@target, expected_number)
15
15
  end
16
-
17
- def satisfy(&block)
18
- return if block.call(@target)
16
+
17
+ def satisfy(&block)
18
+ return if block.call(@target)
19
19
  fail_with_message "Supplied expectation was not satisfied"
20
20
  end
21
-
22
- def equal(expected)
23
- fail_with_message(default_message("should equal", expected)) unless (@target == expected)
21
+
22
+ def equal(expected)
23
+ fail_with_message(default_message("should equal", expected)) unless (@target == expected)
24
24
  end
25
25
 
26
26
  def be(expected = :___no_arg)
27
27
  return self if (expected == :___no_arg)
28
28
  return if (expected == false and @target.nil?)
29
- return if (expected == true and (!@target.nil?) and (@target != false))
30
- fail_with_message(default_message("should be", expected)) unless (@target.equal?(expected))
29
+ return if (expected == true and (!@target.nil?) and (@target != false))
30
+ fail_with_message(default_message("should be", expected)) unless (@target.equal?(expected))
31
31
  end
32
32
 
33
- def a
34
- self
35
- end
36
-
37
- alias an a
38
-
39
- def instance
40
- InstanceHelper.new(@target)
41
- end
42
-
43
- def kind
44
- KindHelper.new(@target)
45
- end
46
-
47
- def respond
48
- RespondHelper.new(@target)
49
- end
50
-
33
+ def a
34
+ self
35
+ end
36
+
37
+ alias an a
38
+
39
+ def instance
40
+ InstanceHelper.new(@target)
41
+ end
42
+
43
+ def kind
44
+ KindHelper.new(@target)
45
+ end
46
+
47
+ def respond
48
+ RespondHelper.new(@target)
49
+ end
50
+
51
51
  def method_missing(sym, *args)
52
52
  return if @target.send("#{sym}?", *args)
53
53
  fail_with_message(default_message("should be #{sym}" + (args.empty? ? '' : (' ' + args.join(', ')))))
54
54
  end
55
55
 
56
56
  def match(expected)
57
- fail_with_message(default_message("should match", expected)) unless (@target =~ expected)
57
+ fail_with_message(default_message("should match", expected)) unless (@target =~ expected)
58
58
  end
59
59
 
60
60
  def include(sub)
61
- fail_with_message(default_message("should include", sub)) unless (@target.include? sub)
61
+ fail_with_message(default_message("should include", sub)) unless (@target.include? sub)
62
62
  end
63
63
 
64
64
  def raise(exception=Exception)