rspec 1.3.0 → 1.3.1.rc

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,20 @@
1
+ === Version 1.3.1 / (Date TBD)
2
+
3
+ * enhancements
4
+ * Array =~ matcher works with subclasses of Array (Matthew Peychich & Pat Maddox)
5
+ * config.suppress_deprecation_warnings!
6
+
7
+ * bug fixes
8
+ * QuitBacktraceTweaker no longer eats all paths with 'lib'
9
+ (Tim Harper - #912)
10
+ * Fix delegation of stubbed values on superclass class-level methods.
11
+ (Scott Taylor - #496 - #957)
12
+ * Fix pending to work with ruby-1.9
13
+
14
+ * deprecations
15
+ * share_as (will be removed from rspec-core-2.0)
16
+ * simple_matcher (will be removed from rspec-core-2.0)
17
+
1
18
  === Version 1.3.0 / 2010-01-11
2
19
 
3
20
  * enhancements
@@ -1,24 +1,18 @@
1
- = RSpec
1
+ == RSpec
2
2
 
3
- * http://rspec.info
4
- * http://rubyforge.org/projects/rspec
5
- * http://github.com/dchelimsky/rspec/wikis
6
- * mailto:rspec-users@rubyforge.org
7
- * mailto:rspec-devel@rubyforge.org
3
+ http://rspec.info
8
4
 
9
- == DESCRIPTION:
5
+ Behaviour Driven Development for Ruby
10
6
 
11
- RSpec is a Behaviour Driven Development framework for writing executable code
12
- examples.
7
+ This is the repository for rspec-1.x. If you're looking
8
+ for rspec-2 (and if you're not, what are you waiting for?),
9
+ see http://github.com/rspec/rspec
13
10
 
14
- == FEATURES:
11
+ == Install
15
12
 
16
- * Spec::Example provides a framework for organizing executable code examples
17
- * Spec::Expectations adds #should and #should_not to every object
18
- * Spec::Matchers provides Expression Matchers for use with #should and #should_not
19
- * Spec::Mocks is a full featured mock object/stubbing library
13
+ gem install rspec
20
14
 
21
- == SYNOPSIS:
15
+ == Synopsis
22
16
 
23
17
  describe Account do
24
18
  context "transfering money" do
@@ -38,17 +32,10 @@ examples.
38
32
  end
39
33
  end
40
34
 
41
- $ spec spec/account_spec.rb --format nested
35
+ $ spec ./spec/account_spec.rb --format nested
42
36
  Account
43
37
  transfering money
44
38
  deposits transfer amount to the other account
45
39
  reduces its balance by the transfer amount
46
40
 
47
41
  2 examples, 0 failures
48
-
49
- == INSTALL:
50
-
51
- [sudo] gem install rspec
52
-
53
- See http://wiki.github.com/dchelimsky/rspec if you want
54
- to clone/build/install.
@@ -29,18 +29,6 @@ module SharedExampleGroupExample
29
29
  end
30
30
  end
31
31
 
32
- # A SharedExampleGroup is also a module. If you create one like this it gets
33
- # assigned to the constant MostThings
34
- share_as :MostThings do
35
- def helper_method
36
- "helper method"
37
- end
38
-
39
- it "should do what things do" do
40
- @thing.what_things_do.should == "stuff"
41
- end
42
- end
43
-
44
32
  describe OneThing do
45
33
  # Now you can include the shared example group like this, which
46
34
  # feels more like what you might say ...
@@ -52,28 +40,4 @@ module SharedExampleGroupExample
52
40
  helper_method.should == "helper method"
53
41
  end
54
42
  end
55
-
56
- describe AnotherThing do
57
- # ... or you can include the example group like this, which
58
- # feels more like the programming language we love.
59
- it_should_behave_like MostThings
60
-
61
- before(:each) { @thing = AnotherThing.new }
62
-
63
- it "should have access to helper methods defined in the shared example group" do
64
- helper_method.should == "helper method"
65
- end
66
- end
67
-
68
- describe YetAnotherThing do
69
- # ... or you can include the example group like this, which
70
- # feels more like the programming language we love.
71
- include MostThings
72
-
73
- before(:each) { @thing = AnotherThing.new }
74
-
75
- it "should have access to helper methods defined in the shared example group" do
76
- helper_method.should == "helper method"
77
- end
78
- end
79
43
  end
@@ -1,6 +1,6 @@
1
1
  describe "arrays" do
2
- def contain_same_elements_as(expected)
3
- simple_matcher "array with same elements in any order as #{expected.inspect}" do |actual|
2
+ Spec::Matchers.define :contain_same_elements_as do |expected|
3
+ match do |actual|
4
4
  if actual.size == expected.size
5
5
  a, e = actual.dup, expected.dup
6
6
  until e.empty? do
@@ -26,4 +26,4 @@ describe "arrays" do
26
26
  it { should_not contain_same_elements_as([1,2,2,3])}
27
27
  it { should_not contain_same_elements_as([1,2])}
28
28
  end
29
- end
29
+ end
@@ -1,4 +1,4 @@
1
- Story: Test is defined, but not Test::Unit
1
+ Feature: Test is defined, but not Test::Unit
2
2
 
3
3
  As an RSpec user who has my own library named Test (but not Test::Unit)
4
4
  I want to run examples without getting Test::Unit NameErrors
@@ -1,4 +1,4 @@
1
- Story: Test::Unit::TestCase extended by rspec with should methods
1
+ Feature: Test::Unit::TestCase extended by rspec with should methods
2
2
 
3
3
  As an RSpec adopter with existing Test::Unit tests
4
4
  I want to use should_* methods in a Test::Unit::TestCase
@@ -18,11 +18,12 @@ gems:
18
18
  version: '>= 0.9.5'
19
19
  - name: rake
20
20
  version: '>= 0.8.4'
21
- - name: spicycode-rcov
22
- version: '>= 0.8.2.1'
21
+ - name: rcov
22
+ version: '>= 0.9.7.1'
23
23
  - name: syntax
24
24
  version: '>= 1.0.0'
25
25
  - name: rr
26
26
  version: '>= 0.10.0'
27
27
  - name: ruby-debug
28
28
  version: '>= 0.10.3'
29
+ - name: autotest-growl
@@ -1,7 +1,8 @@
1
1
  module Spec
2
2
  class << self
3
3
  def deprecate(method, alternate_method=nil)
4
- message = <<-NOTICE
4
+ return if Spec::Runner.configuration.suppress_deprecation_warnings?
5
+ message = <<-NOTICE
5
6
 
6
7
  *****************************************************************
7
8
  DEPRECATION WARNING: you are using deprecated behaviour that will
@@ -76,6 +76,7 @@ module Spec
76
76
  # end
77
77
  # end
78
78
  def share_as(name, &block)
79
+ Spec.deprecate("share_as","shared_examples_for")
79
80
  begin
80
81
  args = [name]
81
82
  add_options(args)
@@ -77,7 +77,7 @@ module Spec
77
77
  end
78
78
 
79
79
  def pending_implementation
80
- lambda { raise(Spec::Example::NotYetImplementedError) }
80
+ lambda {|*args| raise(Spec::Example::NotYetImplementedError) }
81
81
  end
82
82
 
83
83
  alias_method :it, :example
@@ -172,6 +172,11 @@ module Spec
172
172
  end
173
173
  end
174
174
 
175
+ def let!(name, &block)
176
+ let(name, &block)
177
+ before { __send__(name) }
178
+ end
179
+
175
180
  private
176
181
 
177
182
  def subclass(*args, &example_group_block)
@@ -22,8 +22,14 @@ module Spec
22
22
 
23
23
  def its(attribute, &block)
24
24
  describe(attribute) do
25
- define_method(:subject) { super().send(attribute) }
26
- it(&block)
25
+ example do
26
+ self.class.class_eval do
27
+ define_method(:subject) do
28
+ super().send(attribute)
29
+ end
30
+ end
31
+ instance_eval(&block)
32
+ end
27
33
  end
28
34
  end
29
35
 
@@ -155,7 +155,7 @@ module Spec
155
155
  # This matcher can be used as follows:
156
156
  #
157
157
  # describe Customer do
158
- # it { should tip(10).on(50 }
158
+ # it { should tip(10).on(50) }
159
159
  # end
160
160
  #
161
161
  # === Custom Matcher from scratch
@@ -13,7 +13,12 @@ module Spec
13
13
  end
14
14
 
15
15
  def get(klass, operator)
16
- registry[klass] && registry[klass][operator]
16
+ matcher = registry[klass] && registry[klass][operator]
17
+ unless matcher
18
+ parent_class = registry.keys.detect {|pc| klass <= pc }
19
+ matcher = registry[parent_class] && registry[parent_class][operator]
20
+ end
21
+ matcher
17
22
  end
18
23
  end
19
24
 
@@ -5,7 +5,7 @@ module Spec
5
5
  sym.to_s.gsub(/_/,' ')
6
6
  end
7
7
 
8
- def to_sentence(words)
8
+ def to_sentence(words=[])
9
9
  words = words.map{|w| w.inspect}
10
10
  case words.length
11
11
  when 0
@@ -34,4 +34,4 @@ module Spec
34
34
  end
35
35
  end
36
36
  end
37
- end
37
+ end
@@ -127,7 +127,8 @@ module Spec
127
127
  # failing), will fail when you want it to pass.
128
128
  #
129
129
  def simple_matcher(description=nil, &match_block)
130
+ Spec.deprecate("simple_matcher", "Matcher DSL (http://rspec.rubyforge.org/rspec/1.3.0/classes/Spec/Matchers.html)")
130
131
  SimpleMatcher.new(description, &match_block)
131
132
  end
132
133
  end
133
- end
134
+ end
@@ -93,8 +93,8 @@ module Spec
93
93
  # lambda { do_something_risky }.should_not throw_symbol
94
94
  # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky)
95
95
  # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky, culprit)
96
- def throw_symbol(sym=nil)
97
- Matchers::ThrowSymbol.new(sym)
96
+ def throw_symbol(expected_symbol = nil, expected_arg=nil)
97
+ Matchers::ThrowSymbol.new(expected_symbol, expected_arg)
98
98
  end
99
99
  end
100
100
  end
@@ -111,6 +111,8 @@ module Spec
111
111
  invoke_expectation(expectation, *args, &block)
112
112
  elsif expectation = find_almost_matching_expectation(sym, *args)
113
113
  record_almost_matching_expectation(expectation, sym, *args, &block)
114
+ elsif @target.is_a?(Class)
115
+ @target.superclass.send(sym, *args, &block)
114
116
  else
115
117
  @target.__send__ :method_missing, sym, *args, &block
116
118
  end
@@ -38,8 +38,9 @@ module Spec
38
38
  # Tweaks raised Exceptions to mask noisy (unneeded) parts of the backtrace
39
39
  class QuietBacktraceTweaker < BacktraceTweaker
40
40
  unless defined?(IGNORE_PATTERNS)
41
- spec_files = Dir["lib/*"].map do |path|
42
- subpath = path[1..-1]
41
+ root_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
42
+ spec_files = Dir["#{root_dir}/lib/*"].map do |path|
43
+ subpath = path[root_dir.length..-1]
43
44
  /#{subpath}/
44
45
  end
45
46
  IGNORE_PATTERNS = spec_files + [
@@ -154,6 +154,14 @@ module Spec
154
154
  def ignored_backtrace_patterns # :nodoc:
155
155
  @ignored_backtrace_patterns ||= []
156
156
  end
157
+
158
+ def suppress_deprecation_warnings!
159
+ @suppress_deprecation_warnings = true
160
+ end
161
+
162
+ def suppress_deprecation_warnings?
163
+ @suppress_deprecation_warnings ||= false
164
+ end
157
165
 
158
166
  private
159
167
 
@@ -1,4 +1,5 @@
1
1
  require 'ostruct'
2
+ require 'rbconfig'
2
3
 
3
4
  module Spec
4
5
  module Runner
@@ -184,7 +185,7 @@ module Spec
184
185
 
185
186
  def colour=(colour)
186
187
  @colour = colour
187
- if @colour && RUBY_PLATFORM =~ /mswin|mingw/ ;\
188
+ if @colour && Config::CONFIG['host_os'] =~ /mswin|mingw/ ;\
188
189
  begin ;\
189
190
  replace_output = @output_stream.equal?($stdout) ;\
190
191
  require 'rubygems' unless ENV['NO_RUBYGEMS'] ;\
@@ -3,8 +3,8 @@ module Spec # :nodoc:
3
3
  unless defined? MAJOR
4
4
  MAJOR = 1
5
5
  MINOR = 3
6
- TINY = 0
7
- PRE = nil
6
+ TINY = 1
7
+ PRE = 'rc'
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
10
10
 
@@ -57,7 +57,6 @@ module Spec
57
57
  end
58
58
  end
59
59
 
60
-
61
60
  describe "#share_as" do
62
61
  def self.next_group_name
63
62
  @group_number ||= 0
@@ -68,6 +67,15 @@ module Spec
68
67
  def group_name
69
68
  @group_name ||= self.class.next_group_name
70
69
  end
70
+
71
+ before(:each) do
72
+ Spec.stub(:deprecate)
73
+ end
74
+
75
+ it "is deprecated" do
76
+ Spec.should_receive(:deprecate)
77
+ share_as group_name do; end
78
+ end
71
79
 
72
80
  it "registers a shared ExampleGroup" do
73
81
  block = lambda {|a,b|}
@@ -92,4 +100,4 @@ module Spec
92
100
  end
93
101
  end
94
102
  end
95
-
103
+
@@ -753,6 +753,25 @@ module Spec
753
753
  counter.count.should == 2
754
754
  end
755
755
  end
756
+
757
+ describe "#let!" do
758
+ let!(:creator) do
759
+ class Creator
760
+ @count = 0
761
+ def self.count
762
+ @count += 1
763
+ end
764
+ end
765
+ end
766
+
767
+ it "evaluates the value non-lazily" do
768
+ lambda { Creator.count }.should_not raise_error
769
+ end
770
+
771
+ it "does not interfere between tests" do
772
+ Creator.count.should == 1
773
+ end
774
+ end
756
775
  end
757
776
  end
758
777
  end
@@ -3,10 +3,9 @@ require 'spec_helper'
3
3
  module Spec
4
4
  module Example
5
5
  describe ExampleMatcher, "#matches?" do
6
- def match_examples(examples)
7
- simple_matcher do |actual, matcher|
8
- matcher.failure_message = "expected matcher.matches?(#{description.inspect}) to return true, got false"
9
- matcher.negative_failure_message = "expected matcher.matches?(#{description.inspect}) to return false, got true"
6
+
7
+ Spec::Matchers.define :match_examples do |examples|
8
+ match do |actual|
10
9
  actual.matches?(examples)
11
10
  end
12
11
  end
@@ -86,6 +86,13 @@ module Spec
86
86
 
87
87
  describe ".its (to access subject's attributes)" do
88
88
  with_sandboxed_options do
89
+ it "allows before(:each) blocks on subjects in outer scope" do
90
+ group = Class.new(ExampleGroupDouble).describe(Array)
91
+ group.before(:each) { subject << 1 }
92
+ child = group.its(:length) { should == 1 }
93
+ child.run(options).should == true
94
+ end
95
+
89
96
  it "passes when expectation should pass" do
90
97
  group = Class.new(ExampleGroupDouble).describe(Array)
91
98
  child = group.its(:length) { should == 0 }
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  module Spec
4
4
  module Matchers
5
5
  describe "wrap_expectation" do
6
+ before { Spec.stub(:deprecate) }
6
7
 
7
8
  def stub_matcher
8
9
  @_stub_matcher ||= simple_matcher do
@@ -27,4 +28,4 @@ module Spec
27
28
  end
28
29
  end
29
30
  end
30
- end
31
+ end