rspec 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.rdoc +59 -32
  3. data/Manifest.txt +6 -0
  4. data/Rakefile +2 -2
  5. data/examples/passing/options_example.rb +31 -0
  6. data/examples/passing/options_formatter.rb +20 -0
  7. data/features/expectations/expect_change.feature +65 -0
  8. data/features/expectations/expect_error.feature +44 -0
  9. data/lib/spec/example/example_group_factory.rb +4 -2
  10. data/lib/spec/example/example_group_methods.rb +5 -1
  11. data/lib/spec/example/example_group_proxy.rb +8 -0
  12. data/lib/spec/example/example_matcher.rb +2 -3
  13. data/lib/spec/example/example_methods.rb +14 -1
  14. data/lib/spec/example/example_proxy.rb +3 -4
  15. data/lib/spec/example/subject.rb +7 -7
  16. data/lib/spec/interop/test.rb +2 -1
  17. data/lib/spec/matchers/be_close.rb +5 -5
  18. data/lib/spec/matchers/be_instance_of.rb +2 -2
  19. data/lib/spec/matchers/be_kind_of.rb +2 -2
  20. data/lib/spec/matchers/compatibility.rb +2 -2
  21. data/lib/spec/matchers/eql.rb +4 -4
  22. data/lib/spec/matchers/equal.rb +18 -8
  23. data/lib/spec/matchers/extensions/instance_exec.rb +1 -3
  24. data/lib/spec/matchers/include.rb +4 -4
  25. data/lib/spec/matchers/match.rb +2 -2
  26. data/lib/spec/matchers/operator_matcher.rb +3 -2
  27. data/lib/spec/mocks/methods.rb +9 -0
  28. data/lib/spec/mocks/mock.rb +34 -24
  29. data/lib/spec/mocks/proxy.rb +1 -0
  30. data/lib/spec/mocks/spec_methods.rb +5 -5
  31. data/lib/spec/runner.rb +1 -2
  32. data/lib/spec/runner/configuration.rb +0 -0
  33. data/lib/spec/runner/drb_command_line.rb +2 -0
  34. data/lib/spec/runner/formatter/base_text_formatter.rb +1 -1
  35. data/lib/spec/runner/formatter/no_op_method_missing.rb +1 -1
  36. data/lib/spec/version.rb +1 -1
  37. data/spec/spec/example/example_group_proxy_spec.rb +24 -0
  38. data/spec/spec/example/example_methods_spec.rb +12 -0
  39. data/spec/spec/example/predicate_matcher_spec.rb +0 -0
  40. data/spec/spec/example/subject_spec.rb +16 -6
  41. data/spec/spec/matchers/change_spec.rb +85 -85
  42. data/spec/spec/matchers/compatibility_spec.rb +16 -22
  43. data/spec/spec/matchers/equal_spec.rb +33 -9
  44. data/spec/spec/matchers/have_spec.rb +1 -8
  45. data/spec/spec/mocks/mock_ordering_spec.rb +10 -0
  46. data/spec/spec/mocks/mock_spec.rb +106 -93
  47. data/spec/spec/mocks/stub_chain_spec.rb +27 -0
  48. data/spec/spec/mocks/stub_spec.rb +9 -5
  49. data/spec/spec/runner/configuration_spec.rb +0 -0
  50. data/spec/spec/runner/drb_command_line_spec.rb +1 -1
  51. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +31 -46
  52. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +25 -28
  53. data/spec/spec/runner/formatter/html_formatter_spec.rb +3 -19
  54. data/spec/spec/runner/formatter/profile_formatter_spec.rb +3 -18
  55. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +4 -28
  56. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +31 -46
  57. data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +7 -10
  58. data/spec/spec/runner/reporter_spec.rb +1 -1
  59. data/spec/spec_helper.rb +4 -0
  60. data/spec/support/macros.rb +29 -0
  61. metadata +36 -8
  62. metadata.gz.sig +1 -0
Binary file
@@ -1,10 +1,37 @@
1
- === Version 1.2.4
1
+ === Version 1.2.5 / 2009-04-29
2
+
3
+ * enhancements
4
+
5
+ * name argument to mock/stub is now optional (closes #782)
6
+ * you can do mock(:foo => "woo", :bar => "car")
7
+ * expect { this_block }.to change{this.expression}.from(old_value).to(new_value)
8
+ * expect { this_block }.to raise_error
9
+ * better failiure messages for equal matcher (James Byrne). Closes #804.
10
+ * add stub_chain method
11
+ * also alias_method :stub, :stub!, so you can stub with less bang
12
+ * added options to example_group_proxy
13
+
14
+ * bug fixes
15
+
16
+ * ensure correct handling of ordered message expectations with duplicate
17
+ expectations (NigelThorne). Closes #793.
18
+ * get matcher backwards compat working w/ ruby 19
19
+ * don't define instance_exec unless it is not defined
20
+ * was doing a version check, but turns out that didn't cover alternative
21
+ implementations like JRuby
22
+ * fix bug where in some circumstances, loading lib/spec/interop/test.rb
23
+ raised an error (tsechingho). Closes #803.
24
+ * make sure specs only run against spec server when using drb (patch from Chuck Grindel). Closes #797.
25
+ * remove deprecation warning in example_pending when using FailingExamplesFormatter. Closes #794.
26
+ * Access explicit subject from nested groups of arbitrary depth. Closes #756.
27
+
28
+ === Version 1.2.4 / 2009-04-13
2
29
 
3
30
  * bug fix
4
31
 
5
32
  * just one - update the manifest
6
33
 
7
- === Version 1.2.3
34
+ === Version 1.2.3 / 2009-04-13
8
35
 
9
36
  * deprecations
10
37
 
@@ -38,9 +65,9 @@
38
65
 
39
66
  Bug-fix release (fixes regression introduced in 1.2.1)
40
67
 
41
- * bug fixes
68
+ * bug fixes
42
69
 
43
- * fixed bug in which spec_parser raised an error for custom example group
70
+ * fixed bug in which spec_parser raised an error for custom example group
44
71
  base classes
45
72
 
46
73
  === Version 1.2.1 / 2009-03-22
@@ -64,7 +91,7 @@ See Upgrade.rdoc for information about upgrading to rspec-1.2.1
64
91
  * pass ExampleProxy to example_started(). Closes #738, #743
65
92
  * thanks to Tobias Grimm (Eclipse) fort the patch and Roman Chernyatchik
66
93
  (JetBrains, RubyMine) for the assist
67
-
94
+
68
95
  * bug fixes
69
96
 
70
97
  * subject (implicit or explicit) is now properly inherited by nested groups. Closes #744.
@@ -85,19 +112,19 @@ See Upgrade.rdoc for information about upgrading to rspec-1.2.1
85
112
  * you can still use setup and teardown if you're using
86
113
  Test::Unit::TestCase as the base ExampleGroup class (which is implicit
87
114
  in rspec-rails)
88
-
115
+
89
116
  * The matcher protocol has been improved. The old protocol is still
90
117
  supported, so as long as you're not monkey patching rspec's built-in
91
118
  matchers, or using extension libraries that do, this should not affect
92
119
  you. If you run into trouble, you'll just need to change:
93
-
120
+
94
121
  failure_message => failure_message_for_should
95
122
  negative_failure_message => failure_message_for_should_not
96
-
123
+
97
124
  * All references to rubygems have been removed from within rspec's code.
98
-
125
+
99
126
  * NOTE that they have been restored in 1.2.1, above
100
-
127
+
101
128
  * See http://gist.github.com/54177 for rationale and suggestions on
102
129
  alternative approaches to loading rubygems
103
130
 
@@ -110,7 +137,7 @@ See Upgrade.rdoc for information about upgrading to rspec-1.2.1
110
137
 
111
138
  * cleaner integration with with heckle-1.4.2
112
139
  * allow registering example groups with a path-like key (Pat Maddox)
113
- * start DRb service at "druby://localhost:0" (Hongli Lai) - See http://redmine.ruby-lang.org/issues/show/496
140
+ * start DRb service at "druby://localhost:0" (Hongli Lai) - See http://redmine.ruby-lang.org/issues/show/496
114
141
  * consistent reporting of errors as failures
115
142
  * added spec/test/unit as more intuitive path to loading test/unit interop lib
116
143
  * added explicit autorun feature for running specs with ruby command
@@ -120,7 +147,7 @@ See Upgrade.rdoc for information about upgrading to rspec-1.2.1
120
147
  * added --format silent (l) option, which is now the default when running --heckle (Bob Aman)
121
148
  * sexy new custom matcher creation (Corey Haines & David Chelimsky - initial concept by Yehuda Katz)
122
149
  * improved matcher protocol - old one is still supported, but new one is cleaner and prefered
123
-
150
+
124
151
  * bug fixes
125
152
 
126
153
  * support delegating operator matchers to subject with should_not
@@ -137,7 +164,7 @@ not intended:
137
164
  obj.stub!(:msg)
138
165
  obj.msg
139
166
  obj.should_receive(:msg)
140
-
167
+
141
168
  That would pass in 1.1.11, but should not have been allowed to, since the
142
169
  message is received before the expectation is set. This was reported (#637)
143
170
  and fixed for release 1.1.12, but may cause unexpected failures if you had
@@ -171,7 +198,7 @@ WARNING: mock.should_receive(:msg).with(an_instance_of(klass)) now correctly use
171
198
  * config.include now accepts an array of types (config.include(Helpers, :type => [:view, :controller]))
172
199
  * added be_a and be_an expectation matchers
173
200
  * added instance_of and kind_of mock argument matchers
174
-
201
+
175
202
  * 9 bug fixes
176
203
 
177
204
  * fixed bug where {:a => 1, :b => 2}.should include(:a, :b) failed (Yossef Mendelssohn)
@@ -183,7 +210,7 @@ WARNING: mock.should_receive(:msg).with(an_instance_of(klass)) now correctly use
183
210
  * Fix spec_path for shared groups (Zach Dennis). Closes #615.
184
211
  * stubbed message expectation not verified if it has been called *before* the expectation (Matthias Hennemeyer). Closes #637.
185
212
  * stubs calculate return value by executing block passed to #and_return (hint from Aisha Fenton). Closes #642.
186
-
213
+
187
214
  === Version 1.1.11 / 2008-10-24
188
215
 
189
216
  * 1 major enhancement
@@ -314,7 +341,7 @@ metaclass call with (class << self; self; end) and all will be well.
314
341
  * Deprecation warnings for specs that assume auto-inclusion of modules. Closes #326 (patch from Scott Taylor)
315
342
  * mock.should_not_receive(:anything) fails fast (once again)
316
343
  * Patch from Antti Tarvainen to stop files from being loaded repeatedly when running heckle. Closes #333.
317
- * Fixed bug in which session object in example was not the same instance used in the controller. Closes #331.
344
+ * Fixed bug in which session object in example was not the same instance used in the controller. Closes #331.
318
345
  * Applied patch from Antti Tarvainen to fix bug where heckle runs rspec runs heckle runs rspec etc. Closes #280.
319
346
  * Applied patch from Zach Dennis to merge :steps functionality to :steps_for. Closes #324.
320
347
  * Applied patch from Ryan Davis to add eval of block passed to raise_error matcher. Closes #321.
@@ -518,8 +545,8 @@ follow the upgrade instructions and run 'script/generate rspec' you'll be fine,
518
545
  step you need to manually go into spec_helper.rb and remove the call to that method (if present - it
519
546
  might not be if you haven't upgraded in a while).
520
547
 
521
- Warning: Implementors of custom formatters. Formatters will now be sent an Example object instead of just a
522
- String for #example_started, #example_passed and #example_failed. In certain scenarios
548
+ Warning: Implementors of custom formatters. Formatters will now be sent an Example object instead of just a
549
+ String for #example_started, #example_passed and #example_failed. In certain scenarios
523
550
  (Spec::Ui with Spec::Distributed), the formatter must ask the Example for its sequence number instead of
524
551
  keeping track of a sequence number internal to the formatter. Most of you shouldn't need to upgrade
525
552
  your formatters though - the Example#to_s method returns the example name/description, so you should be
@@ -559,7 +586,7 @@ able to use the passed Example instance as if it were a String.
559
586
  * Fixed [#11903] config.include with behaviour_type 'hash' does not work
560
587
  * Examples without blocks and pending is now reported with a P instead of a *
561
588
  * Pending blocks that now pass are rendered blue
562
- * New behaviour for after: If an after block raises an error, the other ones will still run instead of bailing at the first.
589
+ * New behaviour for after: If an after block raises an error, the other ones will still run instead of bailing at the first.
563
590
  * Made it possible to run spec from RSpec.tmbundle with --drb against a Rails spec_server.
564
591
  * Applied [#11868] Add ability for pending to optionally hold a failing block and to fail when it passes (Patch from Bob Cotton)
565
592
  * Fixed [#11843] watir_behaviour missing from spec_ui gem
@@ -683,7 +710,7 @@ This is a bugfix release.
683
710
  * Applied [#10567] Call setup and teardown using before and after callbacks
684
711
 
685
712
  === Version 0.9.2
686
- This is a quick maintenance release.
713
+ This is a quick maintenance release.
687
714
 
688
715
  * Added some website love
689
716
  * Fixed [#10542] reverse predicate matcher syntax
@@ -704,13 +731,13 @@ backwards compatibility). This allows you to express specs like this:
704
731
 
705
732
  The command line features four new options that give you more control over what specs
706
733
  are being run and in what order. This can be used to verify that your specs are
707
- independent (by running in opposite order with --reverse). It can also be used to cut
734
+ independent (by running in opposite order with --reverse). It can also be used to cut
708
735
  down feedback time by running the most recently modified specs first (--loadby mtime --reverse).
709
736
 
710
737
  Further, --example replaces the old --spec option, and it can now take a file name of
711
- spec names as an alternative to just a spec name. The --format failing_examples:file.txt
712
- option allows you to output an --example compatible file, which makes it possible to only
713
- rerun the specs that failed in the last run. Spec::Rails uses all of these four options
738
+ spec names as an alternative to just a spec name. The --format failing_examples:file.txt
739
+ option allows you to output an --example compatible file, which makes it possible to only
740
+ rerun the specs that failed in the last run. Spec::Rails uses all of these four options
714
741
  by default to optimise your RSpec experience.
715
742
 
716
743
  There is now a simple configuration model. For Spec::Rails, you do something like this:
@@ -727,7 +754,7 @@ RSpec's own mock framework. Just put this:
727
754
  Spec::Runner.configure do |config|
728
755
  config.mock_with :mocha
729
756
  end
730
-
757
+
731
758
  or this:
732
759
 
733
760
  Spec::Runner.configure do |config|
@@ -796,7 +823,7 @@ See Spec::DSL::Behaviour for more on predicate_matchers
796
823
  * Moved all of the Spec::Rails specs down to the plugins directory - now you can run the specs after you install.
797
824
  * Updated RSpec.tmbundle to the 0.9 syntax and replaced context/specify with describe/it.
798
825
  * Applied [#9232] ActionController::Base#render is sometimes protected (patch from Dan Manges)
799
- * Added --reverse option, allowing contexts/specs to be run in reverse order.
826
+ * Added --reverse option, allowing contexts/specs to be run in reverse order.
800
827
  * Added --loadby option, allowing better control over load order for spec files. mtime and file.txt supported.
801
828
  * Implemented [#8696] --order option (see --reverse and --loadby)
802
829
  * Added describe/it as aliases for context/specify - suggestion from Dan North.
@@ -824,7 +851,7 @@ This release introduces a new approach to handling expectations using Expression
824
851
  See Upgrade[http://rspec.rubyforge.org/upgrade.html], Spec::Expectations, Spec::Matchers and RELEASE-PLAN for more info.
825
852
 
826
853
  This release also improves the spec command line by adding DRb support and making it possible to
827
- store command line options in a file. This means a more flexible RSpec experience with Rails,
854
+ store command line options in a file. This means a more flexible RSpec experience with Rails,
828
855
  Rake and editor plugins like TextMate.
829
856
 
830
857
  It also sports myriad new features, bug fixes, patches and general goodness:
@@ -976,7 +1003,7 @@ Bug fixes and a couple o' new features.
976
1003
  * Added [#6560] controller.session should be available before the action
977
1004
  * Added support for should_have_rjs :visual_effect
978
1005
  * Different printing and colours for unmet expectations (red) and other exceptions (magenta)
979
- * Simplified method_missing on mock_methods to make it less invasive on partial mocks.
1006
+ * Simplified method_missing on mock_methods to make it less invasive on partial mocks.
980
1007
 
981
1008
  === Version 0.7.0
982
1009
 
@@ -1090,7 +1117,7 @@ RSpec on Rails.
1090
1117
  * Applied [#5065] to support using define_method rather than method_missing to capture expected messages on mocks. Thanks to Eero Saynatkari for the tip that made it work.
1091
1118
  * Restructured directories and Modules in order to separate rspec into three distinct Modules: Spec::Expectations, Spec::Runner and Spec::Mocks. This will allow us to more easily integrate other mock frameworks and/or allow test/unit users to take advantage of the expectation API.
1092
1119
  * Applied [#5620] support any boolean method and arbitrary comparisons (5.should_be < 6) (Patch from Mike Williams)
1093
-
1120
+
1094
1121
  === Version 0.6.3
1095
1122
 
1096
1123
  This release fixes some minor bugs related to RSpec on Rails
@@ -1129,7 +1156,7 @@ This release makes an official commitment to underscore_syntax (with no more sup
1129
1156
  * Fixed bug (5292) that caused mock argument matching to fail
1130
1157
  * Converted ALL tests to use underscore syntax
1131
1158
  * Fixed all remaining problems with underscores revealed by converting all the tests to underscores
1132
- * Enhanced sugar to support combinations of methods (i.e. once.and_return)
1159
+ * Enhanced sugar to support combinations of methods (i.e. once.and_return)
1133
1160
  * Simplified helper structure taking advantage of dot/underscore combos (i.e. should.be.an_instance_of, which can be expressed as should be_an_instance_of)
1134
1161
  * Added support for at_most in mocks
1135
1162
  * Added support for should_not_receive(:msg) (will be removing should_receive(:msg).never some time soon)
@@ -1183,7 +1210,7 @@ minor enhancements.
1183
1210
  * Output of various formatters is now flushed - to get more continuous output.
1184
1211
 
1185
1212
  === Version 0.5.11
1186
- This release makes test2spec usable with Rails (with some manual steps).
1213
+ This release makes test2spec usable with Rails (with some manual steps).
1187
1214
  See http://rspec.rubyforge.org/tools/rails.html for more details
1188
1215
 
1189
1216
  * test2spec now correctly translates bodies of helper methods (non- test_*, setup and teardown ones).
@@ -1378,7 +1405,7 @@ This release adds some shoulds and improves error reporting
1378
1405
 
1379
1406
  === Version 0.1.0
1380
1407
 
1381
- This is the first preview release of RSpec, a Behaviour-Driven Development library for Ruby
1408
+ This is the first preview release of RSpec, a Behaviour-Driven Development library for Ruby
1382
1409
 
1383
1410
  * Added Rake script with tasks for gems, rdoc etc.
1384
1411
  * Added an XForge task to make release go easier.
@@ -43,6 +43,8 @@ examples/passing/io_processor_spec.rb
43
43
  examples/passing/mocking_example.rb
44
44
  examples/passing/multi_threaded_example_group_runner.rb
45
45
  examples/passing/nested_classes_example.rb
46
+ examples/passing/options_example.rb
47
+ examples/passing/options_formatter.rb
46
48
  examples/passing/partial_mock_example.rb
47
49
  examples/passing/pending_example.rb
48
50
  examples/passing/predicate_example.rb
@@ -60,6 +62,8 @@ features/before_and_after_blocks/before_and_after_blocks.feature
60
62
  features/example_groups/example_group_with_should_methods.feature
61
63
  features/example_groups/implicit_docstrings.feature
62
64
  features/example_groups/nested_groups.feature
65
+ features/expectations/expect_change.feature
66
+ features/expectations/expect_error.feature
63
67
  features/extensions/custom_example_group.feature
64
68
  features/formatters/custom_formatter.feature
65
69
  features/heckle/heckle.feature
@@ -302,6 +306,7 @@ spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb
302
306
  spec/spec/mocks/passing_argument_matchers_spec.rb
303
307
  spec/spec/mocks/precise_counts_spec.rb
304
308
  spec/spec/mocks/record_messages_spec.rb
309
+ spec/spec/mocks/stub_chain_spec.rb
305
310
  spec/spec/mocks/stub_spec.rb
306
311
  spec/spec/mocks/stubbed_message_expectations_spec.rb
307
312
  spec/spec/mocks/twice_counts_spec.rb
@@ -359,3 +364,4 @@ spec/spec/runner/spec_spaced.opts
359
364
  spec/spec/runner_spec.rb
360
365
  spec/spec/spec_classes.rb
361
366
  spec/spec_helper.rb
367
+ spec/support/macros.rb
data/Rakefile CHANGED
@@ -57,7 +57,7 @@ namespace :spec do
57
57
  t.spec_opts = ['--options', 'spec/spec.opts']
58
58
  t.rcov = true
59
59
  t.rcov_dir = 'coverage'
60
- t.rcov_opts = ['--exclude', "kernel,load-diff-lcs\.rb,instance_exec\.rb,lib/spec.rb,lib/spec/runner.rb,spec/spec,bin/spec,examples,/gems,/Library/Ruby,\.autotest,#{ENV['GEM_HOME']}"]
60
+ t.rcov_opts = ['--exclude', "kernel,load-diff-lcs\.rb,instance_exec\.rb,lib/spec.rb,lib/spec/runner.rb,^spec/*,bin/spec,examples,/gems,/Library/Ruby,\.autotest,#{ENV['GEM_HOME']}"]
61
61
  end
62
62
  end
63
63
 
@@ -104,7 +104,7 @@ task :verify_committed do
104
104
  end
105
105
 
106
106
  namespace :update do
107
- desc "update the manfest"
107
+ desc "update the manifest"
108
108
  task :manifest do
109
109
  system %q[touch Manifest.txt; rake check_manifest | grep -v "(in " | patch]
110
110
  end
@@ -0,0 +1,31 @@
1
+ # This demonstrates the use of the options hash to support custom reporting.
2
+ # To see the result, run this command from the project root:
3
+ #
4
+ # bin/spec --require examples/passing/options_formatter.rb examples/passing/options_example.rb \
5
+ # --format OptionsFormatter
6
+
7
+ require File.dirname(__FILE__) + '/spec_helper'
8
+
9
+ describe "this group will be reported", :report => true do
10
+ it "this example will be reported", :report => true do
11
+ # no-op
12
+ end
13
+
14
+ it "this example will not be reported", :report => false do
15
+ # no-op
16
+ end
17
+
18
+ it "this example will also not be reported", :foo => 'bar' do
19
+ # no-op
20
+ end
21
+
22
+ it "this example will also also not be reported" do
23
+ # no-op
24
+ end
25
+ end
26
+
27
+ describe "this group will not be reported", :report => false do
28
+ it "though this example will", :report => true do
29
+ # no-op
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ # This is an example of how you can use a custom formatter to do custom
2
+ # reporting. This formatter will only report example groups and examples that
3
+ # have :report => true (or anything truthy) in the declaration. See
4
+ # options_example.rb in this directory.
5
+
6
+ require 'spec/runner/formatter/base_text_formatter'
7
+
8
+ class OptionsFormatter < Spec::Runner::Formatter::BaseTextFormatter
9
+ def example_started(proxy)
10
+ if proxy.options[:report]
11
+ puts proxy.description
12
+ end
13
+ end
14
+
15
+ def example_group_started(proxy)
16
+ if proxy.options[:report]
17
+ puts proxy.description
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,65 @@
1
+ Feature: expect change
2
+
3
+ Expect some code (wrapped in a proc) to change the state of some object.
4
+
5
+ Scenario: expecting change
6
+ Given a file named "expect_change.rb" with:
7
+ """
8
+ class Counter
9
+ class << self
10
+ def increment
11
+ @count ||= 0
12
+ @count += 1
13
+ end
14
+
15
+ def count
16
+ @count ||= 0
17
+ end
18
+ end
19
+ end
20
+
21
+ describe Counter, "#increment" do
22
+ it "should increment the count" do
23
+ expect{Counter.increment}.to change{Counter.count}.from(0).to(1)
24
+ end
25
+
26
+ # deliberate failure
27
+ it "should increment the count by 2" do
28
+ expect{Counter.increment}.to change{Counter.count}.by(2)
29
+ end
30
+ end
31
+ """
32
+ When I run "spec expect_change.rb"
33
+ Then the stdout should match "2 examples, 1 failure"
34
+ Then the stdout should match "should have been changed by 2, but was changed by 1"
35
+
36
+ Scenario: expecting no change
37
+ Given a file named "expect_no_change.rb" with:
38
+ """
39
+ class Counter
40
+ class << self
41
+ def increment
42
+ @count ||= 0
43
+ @count += 1
44
+ end
45
+
46
+ def count
47
+ @count ||= 0
48
+ end
49
+ end
50
+ end
51
+
52
+ describe Counter, "#increment" do
53
+ it "should not increment the count by 2" do
54
+ expect{Counter.increment}.to_not change{Counter.count}.from(0).to(2)
55
+ end
56
+
57
+ # deliberate failure
58
+ it "should not increment the count by 1" do
59
+ expect{Counter.increment}.to_not change{Counter.count}.by(1)
60
+ end
61
+ end
62
+ """
63
+ When I run "spec expect_no_change.rb"
64
+ Then the stdout should match "2 examples, 1 failure"
65
+ Then the stdout should match "should not have changed, but did change from 1 to 2"
@@ -0,0 +1,44 @@
1
+ Feature: expect error
2
+
3
+ Expect a proc to change the state of some object.
4
+
5
+ Scenario: expect error
6
+ Given a file named "expect_error.rb" with:
7
+ """
8
+ describe Object, "#non_existent_message" do
9
+ it "should raise" do
10
+ expect{Object.non_existent_message}.to raise_error(NameError)
11
+ end
12
+ end
13
+
14
+ #deliberate failure
15
+ describe Object, "#public_instance_methods" do
16
+ it "should raise" do
17
+ expect{Object.public_instance_methods}.to raise_error(NameError)
18
+ end
19
+ end
20
+ """
21
+ When I run "spec expect_error.rb"
22
+ Then the stdout should match "2 examples, 1 failure"
23
+ Then the stdout should match "expected NameError but nothing was raised"
24
+
25
+ Scenario: expect no error
26
+ Given a file named "expect_no_error.rb" with:
27
+ """
28
+ describe Object, "#public_instance_methods" do
29
+ it "should not raise" do
30
+ expect{Object.public_instance_methods}.to_not raise_error(NameError)
31
+ end
32
+ end
33
+
34
+ #deliberate failure
35
+ describe Object, "#non_existent_message" do
36
+ it "should not raise" do
37
+ expect{Object.non_existent_message}.to_not raise_error(NameError)
38
+ end
39
+ end
40
+ """
41
+ When I run "spec expect_no_error.rb"
42
+ Then the stdout should match "2 examples, 1 failure"
43
+ Then the stdout should match "undefined method `non_existent_message'"
44
+