+++ /dev/null
-require File.dirname(__FILE__) + '/../spec_helper'
-
-module ApiMapHelpers
- def self.included(klass)
- klass.extend(ClassMethods)
- end
-
- def boundary_params(key)
- case key
- when :valid
- '-0.3565352711206896,51.464740877658045,-0.2686446461206896,51.508686190158045'
- when :min_lat_more_than_max_lat
- '-0.3565352711206896,51.508686190158045,-0.2686446461206896,51.464740877658045'
- when :min_lon_more_than_max_lon
- '51.464740877658045,-0.2686446461206896,51.508686190158045,-0.3565352711206896'
- end
- end
-
- module ClassMethods
- def otherasdfa
- end
- end
-end
-
-describe "When accessing /api/0.5/map" do
- controller_name :api
- include ApiMapHelpers
-
- before(:each) do
- end
-
- it "should _return success_ with _correct boundary longitudes/latitudes_" do
- get :map, :bbox => boundary_params(:valid)
- response.should be_success
- end
-
- it "should return an _error_ when _minimum longitude more than or equal to maximum longitude_" do
- get :map, :bbox => boundary_params(:min_lat_more_than_max_lat)
- response.should_not be_success
- end
-
- it "should return an error unless minimum latitude less than maximum latitude" do
- get :map, :bbox => boundary_params(:min_lon_more_than_max_lon)
- response.should_not be_success
- end
-
- it "should return an error unless latitudes are between -90 and 90 degrees" do
- pending
- end
-
- it "should return an error unless longitudes are between -180 and 180 degrees" do
- pending
- end
-
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/../spec_helper'
-
-describe ApiHelper do
-
- #Delete this example and add some real ones or delete this file
- it "should include the ApiHelper" do
- included_modules = self.metaclass.send :included_modules
- included_modules.should include(ApiHelper)
- end
-
-end
+++ /dev/null
---exclude "spec/*,gems/*"
---rails
\ No newline at end of file
+++ /dev/null
---colour
---format
-progress
---loadby
-mtime
---reverse
---backtrace
\ No newline at end of file
+++ /dev/null
-# This file is copied to ~/spec when you run 'ruby script/generate rspec'
-# from the project root directory.
-ENV["RAILS_ENV"] = "test"
-require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
-require 'spec'
-require 'spec/rails'
-
-require 'ruby-debug'
-
-Spec::Runner.configure do |config|
- # If you're not using ActiveRecord you should remove these
- # lines, delete config/database.yml and disable :active_record
- # in your config/boot.rb
- config.use_transactional_fixtures = true
- config.use_instantiated_fixtures = false
- config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
-
- # == Fixtures
- #
- # You can declare fixtures for each example_group like this:
- # describe "...." do
- # fixtures :table_a, :table_b
- #
- # Alternatively, if you prefer to declare them only once, you can
- # do so right here. Just uncomment the next line and replace the fixture
- # names with your fixtures.
- #
- # config.global_fixtures = :table_a, :table_b
- #
- # If you declare global fixtures, be aware that they will be declared
- # for all of your examples, even those that don't use them.
- #
- # == Mock Framework
- #
- # RSpec uses it's own mocking framework by default. If you prefer to
- # use mocha, flexmock or RR, uncomment the appropriate line:
- #
- # config.mock_with :mocha
- # config.mock_with :flexmock
- # config.mock_with :rr
-end
+++ /dev/null
-dir = File.dirname(__FILE__)
-Dir[File.expand_path("#{dir}/**/*.rb")].uniq.each do |file|
- require file
-end
\ No newline at end of file
+++ /dev/null
-ENV["RAILS_ENV"] = "test"
-require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
-require 'spec/rails/story_adapter'
\ No newline at end of file
+++ /dev/null
-== Version 1.1.2
-
-Minor bug fixes/enhancements.
-
-* RSpec's Autotest subclasses compatible with ZenTest-3.8.0 (thanks to Ryan Davis for making it easier on Autotest subs).
-* Applied patch from idl to add spec/lib to rake stats. Closes #226.
-* calling setup_fixtures and teardown_fixtures for Rails >= r8570. Closes #219.
-* Applied patch from Josh Knowles using ActiveSupport's Inflector (when available) to make 'should have' read a bit better. Closes #197.
-* Fixed regression in 1.1 that caused failing examples to fail to generate their own names. Closes #209.
-* Applied doc patch from Jens Krämer for capturing content_for
-* Applied patch from Alexander Lang to clean up story steps after each story. Closes #198.
-* Applied patch from Josh Knowles to support 'string_or_response.should have_text(...)'. Closes #193.
-* Applied patch from Ian Dees to quiet the Story Runner backtrace. Closes #183.
-* Complete support for defining steps with regexp 'names'.
-
-== Version 1.1.1
-
-Bug fix release.
-
-* Fix regression in 1.1.0 that caused transactions to not get rolled back between examples.
-* Applied patch from Bob Cotton to reintroduce ExampleGroup.description_options. Closes LH[#186]
-
-== Version 1.1.0
-
-The "tell me a story and go nest yourself" release.
-
-* Applied patch from Mike Vincent to handle generators rails > 2.0.1. Closes LH[#181]
-* Formatter.pending signature changed so it gets passed an ExampleGroup instance instead of the name ( LH[#180])
-* Fixed LH[#180] Spec::Rails::Example::ModelExampleGroup and friends show up in rspec/rails output
-* Spec::Rails no longer loads ActiveRecord extensions if it's disabled in config/boot.rb
-* Applied LH[#178] small annoyances running specs with warnings enabled (Patch from Mikko Lehtonen)
-* Tighter integration with Rails fixtures. Take advantage of fixture caching to get performance improvements (Thanks to Pat Maddox, Nick Kallen, Jonathan Barnes, and Curtis)
-
-== Version 1.1.0-RC1
-
-Textmate Bundle users - this release adds a new RSpec bundle that highlights describe, it, before and after and
-provides navigation to descriptions and examples (rather than classes and methods). When you first install this,
-it is going to try to hijack all of your .rb files. All you need to do is open a .rb file that does not end with
-'spec.rb' and change the bundle selection from RSpec to Ruby. TextMate will do the right thing from then on.
-
-Shortcuts for tab-activated snippets all follow the TextMate convention of 2 or 3 letters of the first word, followed by the first letter of each subsequent word. So "should have_at_least" would be triggered by shhal.
-
-We reduced the scope for running spec directories, files, a single file or individual spec in TextMate to source.ruby.rspec. This allowed us to restore the standard Ruby shortcuts:
-
-CMD-R runs all the specs in one file
-CMD-SHIFT-R runs an individual spec
-CMD-OPT-R runs any files or directories selected in the TextMate drawer
-
-rspec_on_rails users - don't forget to run script/generate rspec
-
-* Added shared_examples_for method, which you can (should) use instead of describe Foo, :shared => true
-* Applied LH[#168] Fix describe Object, "description contains a # in it" (Patch from Martin Emde)
-* Applied LH[#15] Reverse loading of ActionView::Base helper modules (Patch from Mark Van Holstyn)
-* Applied LH[#149] Update contribute page to point towards lighthouse (Patch from Josh Knowles)
-* Applied LH[#142] verify_rcov fails with latest rcov (Patch from Kyle Hargraves)
-* Applied LH[#10] Allow stubs to yield and return values (Patch from Pat Maddox)
-* Fixed LH[#139] version.rb in trunk missing svn last changed number
-* Applied LH[#14] Adding support for by_at_least/by_at_most in Change matcher (Patch from Saimon Moore)
-* Applied LH[#12] Fix for TM when switching to alternate file (Patch from Trevor Squires)
-* Applied LH[#133] ExampleMatcher should match against before(:all) (Patch from Bob Cotton)
-* Applied LH[#134] Only load spec inside spec_helper.rb (Patch from Mark Van Holstyn)
-* RSpec now bails immediately if there are examples with identical names.
-* Applied LH[#132] Plain Text stories should support Given and Given: (Patch from Jarkko Laine)
-* Applied patch from Pat Maddox: Story Mediator - the glue that binds the plain text story parser with the rest of the system
-* Applied LH[#16] Have SimpleMatchers expose their description for specdocs (Patch from Bryan Helmkamp)
-* Stories now support --colour
-* Changed the DSL modules to Example (i.e. Spec::Example instead of Spec::DSL)
-* Applied [#15608] Story problem if parenthesis used in Given, When, Then or And (Patch from Sinclair Bain)
-* Applied [#15659] GivenScenario fails when it is a RailsStory (Patch from Nathan Sutton)
-* Fixed [#15639] rcov exclusion configuration. (Spec::Rails projects can configure rcov with spec/rcov.opts)
-* The rdoc formatter (--format rdoc) is gone. It was buggy and noone was using it.
-* Changed Spec::DSL::Behaviour to Spec::DSL::ExampleGroup
-* Changed Spec::DSL::SharedBehaviour to Spec::DSL::SharedExampleGroup
-* Applied [#14023] Small optimization for heavily proxied objects. (Patch from Ian Leitch)
-* Applied [#13943] ProfileFormatter (Top 10 slowest examples) (Patch from Ian Leitch)
-* Fixed [#15232] heckle is not working correctly in trunk (as of r2801)
-* Applied [#14399] Show pending reasons in HTML report (Patch from Bryan Helmkamp)
-* Discovered fixed: [#10263] mock "leak" when setting an expectation in a block passed to mock#should_receive
-* Fixed [#14671] Spec::DSL::ExampleRunner gives "NO NAME because of --dry-run" for every example for 'rake spec:doc'
-* Fixed [#14543] rspec_scaffold broken with Rails 2.0
-* Removed Patch [#10577] Rails with Oracle breaks 0.9.2 - was no longer necessary since we moved describe to the Main object (instead of Object)
-* Fixed [#14527] specs run twice on rails 1.2.4 and rspec/rspec_on_rails trunk
-* Applied [#14043] Change output ordering to show pending before errors (Patch from Mike Mangino)
-* Applied [#14095] Don't have ./script/generate rspec create previous_failures.txt (Patch from Bryan Helmkamp)
-* Applied [#14254] Improved error handling for Object#should and Object#should_not (Patch from Antti Tarvainen)
-* Applied [#14186] Remove dead code from message_expecation.rb (Patch from Antti Tarvainen)
-* Applied [#14183] Tiny improvement on mock_spec.rb (Patch from Antti Tarvainen)
-* Applied [#14208] Fix to Mock#method_missing raising NameErrors instead of MockExpectationErrors (Patch from Antti Tarvainen)
-* Applied [#14255] Fixed examples in mock_spec.rb and shared_behaviour_spec.rb (Patch from Antti Tarvainen)
-* Applied [#14362] partially mocking objects that define == can blow up (Patch from Pat Maddox)
-* test_ methods with an arity of 0 defined in a describe block or Example object will be run as an Example, providing a seamless transition from Test::Unit
-* Removed BehaviourRunner
-* Fixed [#13969] Spec Failures on Trunk w/ Autotest
-* Applied [#14156] False positives with should_not (Patch from Antti Tarvainen)
-* Applied [#14170] route_for and params_from internal specs fixed (Patch from Antti Tarvainen)
-* Fixed [#14166] Cannot build trunk
-* Applied [#14142] Fix for bug #11602: Nested #have_tag specifications fails on the wrong line number (Patch from Antti Tarvainen)
-* Removed warn_if_no_files argument and feature
-* Steps (Given/When/Then) with no blocks are treated as pending
-* Applied [#13913] Scenario should treat no code block as pending (Patch from Evan Light)
-* Fixed [#13370] Weird mock expectation error (Patch from Mike Mangino)
-* Applied [#13952] Fix for performance regression introduced in r2096 (Patch from Ian Leitch)
-* Applied [#13881] Dynamically include Helpers that are included on ActionView::Base (Patch from Brandon Keepers)
-* Applied [#13833] ActionView::Helpers::JavaScriptMacrosHelper removed after 1.2.3 (Patch from Yurii Rashkovskii)
-* Applied [#13814] RSpec on Rails w/ fixture-scenarios (Patch from Shintaro Kakutani)
-* Add ability to define Example subclass instead of using describe
-* Applied Patch from James Edward Gray II to improve syntax highlighting in TextMate
-* Fixed [#13579] NoMethodError not raised for missing helper methods
-* Fixed [#13713] form helper method 'select' can not be called when calling custom helper methods from specs
-* Example subclasses Test::Unit::TestCase
-* Added stub_everything method to create a stub that will return itself for any message it doesn't understand
-* Added stories directory with stories/all.rb and stories/helper.rb when you script/generate rspec
-* Applied [#13554] Add "And" so you can say Given... And... When... Then... And...
-* Applied [#11254] RSpec syntax coloring and function pop-up integration in TextMate (Patch from Wincent Colaiuta)
-* Applied [#13143] ActionView::Helpers::RecordIdentificationHelper should be included if present (Patch from Jay Levitt)
-* Applied [#13567] patch to allow stubs to yield consecutive values (Patch from Rupert Voelcker)
-* Applied [#13559] reverse version of route_for (Patch from Rupert Voelcker)
-* Added [#13532] /lib specs should get base EvalContext
-* Applied [#13451] Add a null_object option to mock_model (Patch from James Deville)
-* Applied [#11919] Making non-implemented specs easy in textmate (Patch from Scott Taylor)
-* Applied [#13274] ThrowSymbol recognized a NameError triggered by Kernel#method_missing as a thrown Symbol
-* Applied [#12722] the alternate file command does not work in rails views due to scope (Patch from Carl Porth)
-* Behaviour is now a Module that is used by Example class methods and SharedBehaviour
-* Added ExampleDefinition
-* Added story runner framework based on rbehave [#12628]
-* Applied [#13336] Helper directory incorrect for rake stats in statsetup task (Patch from Curtis Miller)
-* Applied [#13339] Add the ability for spec_parser to parse describes with :behaviour_type set (Patch from Will Leinweber and Dav Yaginuma)
-* Fixed [#13271] incorrect behaviour with expect_render and stub_render
-* Applied [#13129] Fix failing specs in spec_distributed (Patch from Bob Cotton)
-* Applied [#13118] Rinda support for Spec::Distributed (Patch from Bob Cotton)
-* Removed BehaviourEval
-* Removed Behaviour#inherit
-* Moved implementation of install_dependencies to example_rails_app
-* Renamed RSPEC_DEPS to VENDOR_DEPS
-* Added Example#not_implemented?
-* You can now stub!(:msg).with(specific args)
-* describe("A", Hash, "with one element") will generate description "A Hash with one element" (Tip from Ola Bini)
-* Applied [#13016] [DOC] Point out that view specs render, well, a view (Patch from Jay Levitt)
-* Applied [#13078] Develop rspec with autotest (Patch from Scott Taylor)
-* Fixed [#13065] Named routes throw a NoMethodError in Helper specs (Patches from James Deville and Mike Mangino)
-* Added (back) the verbose attribute in Spec::Rake::SpecTask
-* Changed documentation to point at the new http svn URL, which is more accessible.
-
-== Version 1.0.8
-
-Another bugfix release - this time to resolve the version mismatch
-
-== Version 1.0.7
-
-Quick bugfix release to ensure that you don't have to have the rspec gem installed
-in order to use autotest with rspec_on_rails.
-
-* Fixed [#13015] autotest gives failure in 'spec_command' after upgrade 1.0.5 to 1.0.6
-
-== Version 1.0.6
-
-The "holy cow, batman, it's been a long time since we released and there are a ton of bug
-fixes, patches and even new features" release.
-
-Warning: Spec::Rails users: In fixing 11508, we've removed the raise_controller_errors method. As long as you
-follow the upgrade instructions and run 'script/generate rspec' you'll be fine, but if you skip this
-step you need to manually go into spec_helper.rb and remove the call to that method (if present - it
-might not be if you haven't upgraded in a while).
-
-Warning: Implementors of custom formatters. Formatters will now be sent an Example object instead of just a
-String for #example_started, #example_passed and #example_failed. In certain scenarios
-(Spec::Ui with Spec::Distributed), the formatter must ask the Example for its sequence number instead of
-keeping track of a sequence number internal to the formatter. Most of you shouldn't need to upgrade
-your formatters though - the Example#to_s method returns the example name/description, so you should be
-able to use the passed Example instance as if it were a String.
-
-* Applied [#12986] Autotest Specs + Refactoring (Patch from Scott Tayler)
-* Added a #close method to formatters, which allows them to gracefully close streams.
-* Applied [#12935] Remove requirement that mocha must be installed as a gem when used as mocking framework. (Patch from Ryan Kinderman).
-* Fixed [#12893] RSpec's Autotest should work with rspec's trunk
-* Fixed [#12865] Partial mock error when object has an @options instance var
-* Applied [#12701] Allow checking of content captured with content_for in view specs (Patch from Jens Kr�mer)
-* Applied [#12817] Cannot include same shared behaviour when required with absolute paths (Patch from Ian Leitch)
-* Applied [#12719] rspec_on_rails should not include pagination helper (Patch from Matthijs Langenberg)
-* Fixed [#12714] helper spec not finding rails core helpers
-* Applied [#12611] should_not redirect_to implementation (Patch from Yurii Rashkovskii)
-* Applied [#12682] Not correctly aliasing original 'stub!' and 'should_receive' methods for ApplicationController (Patch from Matthijs Langenberg)
-* Disabled controller.should_receive(:render) and controller.stub!(:render). Use expect_render or stub_render instead.
-* Applied [#12484] Allow a Behaviour's Description to flow through to the Formatter (Patch from Bob Cotton)
-* Fixed [#12448] The spec:plugins rake task from rspec_on_rails should ignore specs from the rspec_on_rails plugin
-* Applied [#12300] rr integration (patch from Kyle Hargraves)
-* Implemented [#12284] mock_with :rr (integration with RR mock framework: http://rubyforge.org/projects/pivotalrb/)
-* Applied [#12237] (tiny) added full path to mate in switch_command (Patch from Carl Porth)
-* Formatters will now be sent an Example object instead of just a String for certain methods
-* All Spec::Rake::SpecTask attributes can now be procs, which allows for lazy evaluation.
-* Changed the Spec::Ui interfaces slightly. See examples.
-* Applied [#12174] mishandling of paths with spaces in spec_mate switch_command (Patch from Carl Porth)
-* Implemented [#8315] File "Go to..." functionality
-* Applied [#11917] Cleaner Spec::Ui error for failed Selenium connection (Patch from Ian Dees)
-* Applied [#11888] rspec_on_rails spews out warnings when assert_select is used with an XML response (Patch from Ian Leitch)
-* Applied [#12010] Nicer failure message formatting (Patch from Wincent Colaiuta)
-* Applied [#12156] smooth open mate patch (Patch from Ienaga Eiji)
-* Applied [#10577] Rails with Oracle breaks 0.9.2. (Patch from Sinclair Bain)
-* Fixed [#12079] auto-generated example name incomplete: should have 1 error on ....]
-* Applied [#12066] Docfix for mocks/mocks.page (Patch from Kyle Hargraves)
-* Fixed [#11891] script/generate rspec_controller fails to create appropriate views (from templates) on edge rails
-* Applied [#11921] Adds the correct controller_name from derived_controller_name() to the ViewExampleGroupController (Patch from Eloy Duran)
-* Fixed [#11903] config.include with behaviour_type 'hash' does not work
-* Examples without blocks and pending is now reported with a P instead of a *
-* Pending blocks that now pass are rendered blue
-* New behaviour for after: If an after block raises an error, the other ones will still run instead of bailing at the first.
-* Made it possible to run spec from RSpec.tmbundle with --drb against a Rails spec_server.
-* Applied [#11868] Add ability for pending to optionally hold a failing block and to fail when it passes (Patch from Bob Cotton)
-* Fixed [#11843] watir_behaviour missing from spec_ui gem
-* Added 'switch between source and spec file' command in Spec::Mate (based on code from Ruy Asan)
-* Applied [#11509] Documentation - RSpec requires hpricot
-* Applied [#11807] Daemonize spec_server and rake tasks to manage them. (patch from Kyosuke MOROHASHI)
-* Added pending(message) method
-* Fixed [#11777] should render_template doesn't check paths correctly
-* Fixed [#11749] Use of 'rescue => e' does not catch all exceptions
-* Fixed [#11793] should raise_error('with a message') does not work correctly
-* Fixed [#11774] Mocks should respond to :kind_of? in the same way they respond to :is_a?
-* Fixed [#11508] Exceptions are not raised for Controller Specs (removed experimental raise_controller_errors)
-* Applied [#11615] Partial mock methods give ambiguous failures when given a method name as a String (Patch from Jay Phillips)
-* Fixed [#11545] Rspec doesn't handle should_receive on ActiveRecord associations (Patch from Ian White)
-* Fixed [#11514] configuration.use_transactional_fixtures is ALWAYS true, regardless of assignment
-* Improved generated RESTful controller examples to cover both successful and unsuccessful POST and PUT
-* Changed TextMate snippets for controllers to pass controller class names to #describe rather than controller_name.
-* Changed TextMate snippets for mocks to use no_args() and any_args() instead of the deprecated Symbols.
-* Applied [#11500] Documentation: no rails integration specs in 1.0
-* Renamed SpecMate's shortcuts for running all examples and focused examples to avoid conflicts (CMD-d and CMD-i)
-* Added a TextMate snippet for custom matchers, lifted from Geoffrey Grosenbach's RSpec peepcode show.
-* The translator translates mock constraints to the new matchers that were introduced in 1.0.4
-* Documented environment variables for Spec::Rake::SpecTask. Renamed SPECOPTS and RCOVOPTS to SPEC_OPTS and RCOV_OPTS.
-* Fixed [#10534] Windows: undefined method 'controller_name'
-
-== Version 1.0.5
-Bug fixes. Autotest plugin tweaks.
-
-* Fixed [#11378] fix to 10814 broke drb (re-opened #10814)
-* Fixed [#11223] Unable to access flash from rails helper specs
-* Fixed [#11337] autotest runs specs redundantly
-* Fixed [#11258] windows: autotest won't run
-* Applied [#11253] Tweaks to autotest file mappings (Patch from Wincent Colaiuta)
-* Applied [#11252] Should be able to re-load file containing shared behaviours without raising an exception (Patch from Wincent Colaiuta)
-* Fixed [#11247] standalone autotest doesn't work because of unneeded autotest.rb
-* Applied [#11221] Autotest support does not work w/o Rails Gem installed (Patch from Josh Knowles)
-
-== Version 1.0.4
-The getting ready for JRuby release.
-
-* Fixed [#11181] behaviour_type scoping of config.before(:each) is not working
-* added mock argument constraint matchers (anything(), boolean(), an_instance_of(Type)) which work with rspec or mocha
-* added mock argument constraint matchers (any_args(), no_args()) which only work with rspec
-* deprecated rspec's symbol mock argument constraint matchers (:any_args, :no_args, :anything, :boolean, :numeric, :string)
-* Added tarball of rspec_on_rails to the release build to support folks working behind a firewall that blocks svn access.
-* Fixed [#11137] rspec incorrectly handles flash after resetting the session
-* Fixed [#11143] Views code for ActionController::Base#render broke between 1.0.0 and 1.0.3 on Rails Edge r6731
-* Added raise_controller_errors for controller examples in Spec::Rails
-
-== Version 1.0.3
-Bug fixes.
-
-* Fixed [#11104] Website uses old specify notation
-* Applied [#11101] StringHelpers.starts_with?(prefix) assumes a string parameter for _prefix_
-* Removed 'rescue nil' which was hiding errors in controller examples.
-* Fixed [#11075] controller specs fail when using mocha without integrated_views
-* Fixed problem with redirect_to failing incorrectly against edge rails.
-* Fixed [#11082] RspecResourceGenerator should be RspecScaffoldGenerator
-* Fixed [#10959] Focused Examples do not work for Behaviour defined with constant with modules
-
-== Version 1.0.2
-This is just to align the version numbers in rspec and rspec_on_rails.
-
-== Version 1.0.1
-This is a maintenance release with mostly cleaning up, and one minor enhancement -
-Modules are automatically included when described directly.
-
-* Renamed Spec::Rails' rspec_resource generator to rspec_scaffold.
-* Removed Spec::Rails' be_feed matcher since it's based on assert_select_feed which is not part of Rails (despite that docs for assert_select_encoded says it is).
-* describe(SomeModule) will include that module in the examples. Like for Spec::Rails helpers, but now also in core.
-* Header in HTML report will be yellow instead of red if there is one failed example
-* Applied [#10951] Odd instance variable name in rspec_model template (patch from Kyle Hargraves)
-* Improved integration with autotest (Patches from Ryan Davis and David Goodland)
-* Some small fixes to make all specs run on JRuby.
-
-== Version 1.0.0
-The stake in the ground release. This represents a commitment to the API as it is. No significant
-backwards compatibility changes in the API are expected after this release.
-
-* Fixed [#10923] have_text matcher does not support should_not
-* Fixed [#10673] should > and should >= broken
-* Applied [#10921] Allow verify_rcov to accept greater than threshold coverage %'s via configuration
-* Applied [#10920] Added support for not implemented examples (Patch from Chad Humphries and Ken Barker)
-* Patch to allow not implemented examples. This works by not providing a block to the example. (Patch from Chad Humphries, Ken Barker)
-* Yanked support for Rails 1.1.6 in Spec::Rails
-* RSpec.tmbundle uses CMD-SHIFT-R to run focused examples now.
-* Spec::Rails now bundles a spec:rcov task by default (suggestion from Kurt Schrader)
-* Fixed [#10814] Runner loads shared code, test cases require them again
-* Fixed [#10753] Global before and after
-* Fixed [#10774] Allow before and after to be specified in config II
-* Refactored Spec::Ui examples to use new global before and after blocks.
-* Added instructions about how to get Selenium working with Spec::Ui (spec_ui/examples/selenium/README.txt)
-* Fixed [#10805] selenium.rb missing from gem?
-* Added rdocs explaining how to deal with errors in Rails' controller actions
-* Applied [#10770] Finer grained includes.
-* Fixed [#10747] Helper methods defined in shared specs are not visible when shared spec is used
-* Fixed [#10748] Shared descriptions in separate files causes 'already exists' error
-* Applied [#10698] Running with --drb executes specs twice (patch from Ruy Asan)
-* Fixed [#10871] 0.9.4 - Focussed spec runner fails to run specs in descriptions with type and string when there is no leading space in the string
-
-== Version 0.9.4
-This release introduces massive improvements to Spec::Ui - the user interface functional testing
-extension to RSpec. There are also some minor bug fixes to the RSpec core.
-
-* Massive improvements to Spec::Ui. Complete support for all Watir's ie.xxx(how, what) methods. Inline screenshots and HTML.
-* Reactivated --timeout, which had mysteriously been deactivated in a recent release.
-* Fixed [#10669] Kernel#describe override does not cover Kernel#context
-* Applied [#10636] Added spec for OptionParser in Runner (Patch from Scott Taylor)
-* Added [#10516] should_include should be able to accept multiple items
-* Applied [#10631] redirect_to matcher doesn't respect request.host (Patch from Tim Lucas)
-* Each formatter now flushes their own IO. This is to avoid buffering of output.
-* Fixed [#10670] IVarProxy#delete raises exception when instance variable does not exist
-
-== Version 0.9.3
-This is a bugfix release.
-
-* Fixed [#10594] Failing Custom Matcher show NAME NOT GENERATED description
-* describe(SomeType, "#message") will not add a space: "SomeType#message" (likewise for '.')
-* describe(SomeType, "message") will have a decription with a space: "SomeType message"
-* Applied [#10566] prepend_before and prepend_after callbacks
-* Applied [#10567] Call setup and teardown using before and after callbacks
-
-== Version 0.9.2
-This is a quick maintenance release.
-
-* Added some website love
-* Fixed [#10542] reverse predicate matcher syntax
-* Added a spec:translate Rake task to make 0.9 translation easier with Spec:Rails
-* Better translation of should_redirect_to
-* Fixed --colour support for Windows. This is a regression that was introduced in 0.9.1
-* Applied [#10460] Make SpecRunner easier to instantiate without using commandline args
-
-== Version 0.9.1
-
-This release introduces #describe and #it (aliased as #context and #specify for
-backwards compatibility). This allows you to express specs like this:
-
- describe SomeClass do # Creates a Behaviour
- it "should do something" do # Creates an Example
- end
- end
-
-The command line features four new options that give you more control over what specs
-are being run and in what order. This can be used to verify that your specs are
-independent (by running in opposite order with --reverse). It can also be used to cut
-down feedback time by running the most recently modified specs first (--loadby mtime --reverse).
-
-Further, --example replaces the old --spec option, and it can now take a file name of
-spec names as an alternative to just a spec name. The --format failing_examples:file.txt
-option allows you to output an --example compatible file, which makes it possible to only
-rerun the specs that failed in the last run. Spec::Rails uses all of these four options
-by default to optimise your RSpec experience.
-
-There is now a simple configuration model. For Spec::Rails, you do something like this:
-
- Spec::Runner.configure do |config|
- config.use_transactional_fixtures = true
- config.use_instantiated_fixtures = false
- config.fixture_path = RAILS_ROOT + '/spec/fixtures'
- end
-
-You can now use mocha or flexmock with RSpec if you prefer either to
-RSpec's own mock framework. Just put this:
-
- Spec::Runner.configure do |config|
- config.mock_with :mocha
- end
-
-or this:
-
- Spec::Runner.configure do |config|
- config.mock_with :flexmock
- end
-
-in a file that is loaded before your specs. You can also
-configure included modules and predicate_matchers:
-
- Spec::Runner.configure do |config|
- config.include SomeModule
- config.predicate_matchers[:does_something?] = :do_something
- end
-
-See Spec::DSL::Behaviour for more on predicate_matchers
-
-* Sugar FREE!
-* Added [10434 ] Please Make -s synonymous with -e for autotest compat. This is temporary until autotest uses -e instead of -s.
-* Fixed [#10133] custom predicate matchers
-* Applied [#10473] Add should exist (new matcher) - Patch from Bret Pettichord
-* Added another formatter: failing_behaviours. Writes the names of the failing behaviours for use with --example.
-* Applied [#10315] Patch to fix pre_commit bug 10313 - pre_commit_rails: doesn't always build correctly (Patch from Antii Tarvainen)
-* Applied [#10245] Patch to HTML escape the behavior name when using HTML Formatter (Patch from Josh Knowles)
-* Applied [#10410] redirect_to does not behave consistently with regards to query string parameter ordering (Patch from Nicholas Evans)
-* Applied [#9605] Patch for ER 9472, shared behaviour (Patch by Bob Cotton)
-* The '--format rdoc' option no longer causes a dry-run by default. --dry-run must be used explicitly.
-* It's possible to specify the output file in the --format option (See explanation in --help)
-* Several --format options may be specified to output several formats in one run.
-* The --out option is gone. Use --format html:path/to/my.html instead (or similar).
-* Spec::Runner::Formatter::BaseTextFormatter#initialize only takes one argument - an IO. dry_run and color are setters.
-* Made Spec::Ui *much* easier to install. It will be released separately. Check out trunk/spec_ui/examples
-* HTML reports now include a syntax highlighted snippet of the source code where the spec failed (needs the syntax gem)
-* Added [#10262] Better Helper testing of Erb evaluation block helpers
-* Added [#9735] support flexmock (thanks to Jim Weirich for his modifications to flexmock to support this)
-* Spec::Rails controller specs will no longer let mock exception ripple through to the response.
-* Fixed [#9260] IvarProxy does not act like a hash.
-* Applied [#9458] The rspec_scaffold generator does not take into account class nesting (Patch from Steve Tendon)
-* Applied [#9132] Rakefile spec:doc can fail without preparing database (Patch from Steve Ross)
-* Applied [#9678] Custom runner command line switch, and multi-threaded runner (Patch from Bob Cotton)
-* Applied [#9926] Rakefile - RSPEC_DEPS constant as an Array of Hashes instead of an Array of Arrays (Patch from Scott Taylor)
-* Applied [#9925] Changed ".rhtml" to "template" in REST spec generator (Patch from Scott Taylor)
-* Applied [#9852] Patch for RSpec's Website using Webgen 0.4.2 (Patch from Scott Taylor)
-* Fixed [#6523] Run rspec on rails without a db
-* Fixed [#9295] rake spec should run anything in the spec directory (not just rspec's standard dirs)
-* Added [#9786] infer controller and helper names from the described type
-* Fixed [#7795] form_tag renders action='/view_spec' in view specs
-* Fixed [#9767] rspec_on_rails should not define rescue_action on controllers
-* Fixed [#9421] --line doesn't work with behaviours that use class names
-* Fixed [#9760] rspec generators incompatible with changes to edge rails
-* Added [#9786] infer controller and helper names from the described type
-* Applied a simplified version of [#9282] Change to allow running specs from textmate with rspec installed as a rails plugin (and no rspec gem installed)
-* Applied [#9700] Make Spec::DSL::Example#name public / Add a --timeout switch. A great way to prevent specs from getting slow.
-* In Rails, script/generate rspec will generate a spec.opts file that optimises faster/more efficient running of specs.
-* Added [#9522] support using rspec's expectations with test/unit
-* Moved rspec_on_rails up to the project root, simplifying the download url
-* Fixed [#8103] RSpec not installing spec script correctly.
-* The --spec option is replaced by the --example option.
-* The --loadby option no longer supports a file argument. Use --example file_name instead.
-* The --example option can now take a file name as an argument. The file should contain example names.
-* Internal classes are named Behaviour/Example (rather than Context/Specification).
-* You can now use mocha by saying config.mock_with :mocha in a spec_helper
-* before_context_eval is replaced by before_eval.
-* Applied [#9509] allow spaced options in spec.opts
-* Applied [#9510] Added File for Ruby 1.8.6
-* Applied [#9511] Clarification to README file in spec/
-* Moved all of the Spec::Rails specs down to the plugins directory - now you can run the specs after you install.
-* Updated RSpec.tmbundle to the 0.9 syntax and replaced context/specify with describe/it.
-* Applied [#9232] ActionController::Base#render is sometimes protected (patch from Dan Manges)
-* Added --reverse option, allowing contexts/specs to be run in reverse order.
-* Added --loadby option, allowing better control over load order for spec files. mtime and file.txt supported.
-* Implemented [#8696] --order option (see --reverse and --loadby)
-* Added describe/it as aliases for context/specify - suggestion from Dan North.
-* Applied [#7637] [PATCH] add skip-migration option to rspec_scaffold generator
-* Added [#9167] string.should have_tag
-* Changed script/rails_spec_server to script/spec_server and added script/spec (w/ path to vendor/plugins/rspec)
-* Fixed [#8897] Error when mixing controller spec with/without integrated views and using template system other than rhtml
-* Updated sample app specs to 0.9 syntax
-* Updated generated specs to 0.9 syntax
-* Applied [#8994] trunk: generated names for be_ specs (Multiple patches from Yurii Rashkovskii)
-* Applied [#9983]: Allow before and after to be called in BehaviourEval. This is useful for shared examples.
-
-== Version 0.8.2
-
-Replaced assert_select fork with an assert_select wrapper for have_tag. This means that "should have_rjs" no longer supports :hide or :effect, but you can still use should_have_rjs for those.
-
-== Version 0.8.1
-
-Quick "in house" bug-fix
-
-== Version 0.8.0
-
-This release introduces a new approach to handling expectations using Expression Matchers.
-
-See Upgrade[http://rspec.rubyforge.org/upgrade.html], Spec::Expectations, Spec::Matchers and RELEASE-PLAN for more info.
-
-This release also improves the spec command line by adding DRb support and making it possible to
-store command line options in a file. This means a more flexible RSpec experience with Rails,
-Rake and editor plugins like TextMate.
-
-It also sports myriad new features, bug fixes, patches and general goodness:
-
-* Fixed [#8928] rspec_on_rails 0.8.0-RC1 controller tests make double call to setup_with_fixtures
-* Fixed [#8925] Documentation bug in 0.8.0RC1 rspec website
-* Applied [#8132] [PATCH] RSpec breaks "rake db:sessions:create" in a rails project that has the rspec_on_rails plugin (Patch from Erik Kastner)
-* Fixed [#8789] --line and --spec not working when the context has parenhesis in the name
-* Added [#8783] auto generate spec names from last expectation
-* --heckle now fails if the heckled class or module is not found.
-* Fixed [#8771] Spec::Mocks::BaseExpectation#with converts hash params to array of arrays with #collect
-* Fixed [#8750] should[_not]_include backwards compatibility between 0.8.0-RC1 and 0.7.5.1 broken
-* Fixed [#8646] Context Runner does not report on Non standard exceptions and return a 0 return code
-* RSpec on Rails' spec_helper.rb will only force RAILS_ENV to test if it was not specified on the command line.
-* Fixed [#5485] proc#should_raise and proc#should_not_raise output
-* Added [#8484] should_receive with blocks
-* Applied [#8218] heckle_runner.rb doesn't work with heckle >= 1.2.0 (Patch from Michal Kwiatkowski)
-* Fixed [#8240] Cryptic error message when no controller_name
-* Applied [#7461] [PATCH] Contexts don't call Module::included when they include a module
-* Removed unintended block of test/unit assertions in rspec_on_rails - they should all, in theory, now be accessible
-* Added mock_model method to RSpec on Rails, which stubs common methods. Based on http://metaclass.org/2006/12/22/making-a-mockery-of-activerecord
-* Fixed [#8165] Partial Mock Errors when respond_to? is true but the method is not in the object
-* Fixed [#7611] Partial Mocks override Subclass methods
-* Fixed [#8302] Strange side effect when mocking a class method
-* Applied [#8316] to_param should return a stringified key in resource generator's controller spec (Patch from Chris Anderson)
-* Applied [#8216] shortcut for creating object stub
-* Applied [#8008] Correct generated specs for view when calling resource generator (Patch from Jonathan Tron)
-* Fixed [#7754] Command-R fails to run spec in TextMate (added instruction from Luke Redpath to the website)
-* Fixed [#7826] RSpect.tmbundle web page out of date.
-* RSpec on Rails specs are now running against RoR 1.2.1 and 1.2.2
-* rspec_scaffold now generates specs for views
-* In a Rails app, RSpec core is only loaded when RAILS_ENV==test (init.rb)
-* Added support for target.should arbitrary_expectation_handler and target.should_not arbitrary_expectation_handler
-* Fixed [#7533] Spec suite fails and the process exits with a code 0
-* Fixed [#7565] Subsequent stub! calls for method fail to override the first call to method
-* Applied [#7524] Incorrect Documentation for 'pattern' in Rake task (patch from Stephen Duncan)
-* Fixed [#7409] default fixtures do not appear to run.
-* Fixed [#7507] "render..and return" doesn't return
-* Fixed [#7509] rcov/rspec incorrectly includes boot.rb (Patch from Courtenay)
-* Fixed [#7506] unnecessary complex output on failure of response.should be_redirect
-* Applied [#6098] Make scaffold_resource generator. Based on code from Pat Maddox.
-* The drbspec command is gone. Use spec --drb instead.
-* The drb option is gone from the Rake task. Pass --drb to spec_opts instead.
-* New -X/--drb option for running specs against a server like spec/rails' script/rails_spec_server
-* New -O/--options and -G/--generate flags for file-based options (handy for spec/rails)
-* Applied [#7339] Turn off caching in HTML reports
-* Applied [#7419] "c option for colorizing output does not work with rails_spec" (Patch from Shintaro Kakutani)
-* Applied [#7406] [PATCH] 0.7.5 rspec_on_rails loads fixtures into development database (Patch from Wilson Bilkovich)
-* Applied [#7387] Allow stubs to return consecutive values (Patch from Pat Maddox)
-* Applied [#7393] Fix for rake task (Patch from Pat Maddox)
-* Reinstated support for response.should_render (in addition to controller.should_render)
-
-== Version 0.7.5.1
-
-Bug fix release to allow downloads of rspec gem using rubygems 0.9.1.
-
-== Version 0.7.5
-This release adds support for Heckle - Seattle'rb's code mutation tool.
-There are also several bug fixes to the RSpec core and the RSpec on Rails plugin.
-
-* Removed svn:externals on rails versions and plugins
-* Applied [#7345] Adding context_setup and context_teardown, with specs and 100% rcov
-* Applied [#7320] [PATCH] Allow XHR requests in controller specs to render RJS templates
-* Applied [#7319] Migration code uses drop_column when it should use remove_column (patch from Pat Maddox)
-* Added support for Heckle
-* Applied [#7282] dump results even if spec is interrupted (patch from Kouhei Sutou)
-* Applied [#7277] model.should_have(n).errors_on(:attribute) (patch from Wilson Bilkovich)
-* Applied [#7270] RSpec render_partial colliding with simply_helpful (patch from David Goodlad)
-* Added [#7250] stubs should support throwing
-* Added [#7249] stubs should support yielding
-* Fixed [#6760] fatal error when accessing nested finders in rspec
-* Fixed [#7179] script/generate rspec_scaffold generates incorrect helper name
-* Added preliminary support for assert_select (response.should_have)
-* Fixed [#6971] and_yield does not work when the arity is -1
-* Fixed [#6898] Can we separate rspec from the plugins?
-* Added [#7025] should_change should accept a block
-* Applied [#6989] partials with locals (patch from Micah Martin)
-* Applied [#7023] Typo in team.page
-
-== Version 0.7.4
-
-This release features a complete redesign of the reports generated with --format html.
-As usual there are many bug fixes - mostly related to spec/rails.
-
-* Applied [#7010] Fixes :spacer_template does not work w/ view spec (patch from Shintaro Kakutani)
-* Applied [#6798] ensure two ':' in the first backtrace line for Emacs's 'next-error' command (patch from Kouhei Sutou)
-* Added Much nicer reports to generated website
-* Much nicer reports with --format --html (patch from Luke Redpath)
-* Applied [#6959] Calls to render and redirect in controllers should return true
-* Fixed [#6981] helper method is not available in partial template.
-* Added [#6978] mock should tell you the expected and actual args when receiving the right message with the wrong args
-* Added the possibility to tweak the output of the HtmlFormatter (by overriding extra_failure_content).
-* Fixed [#6936] View specs don't include ApplicationHelper by default
-* Fixed [#6903] Rendering a partial in a view makes the view spec blow up
-* Added callback library from Brian Takita
-* Added [#6925] support controller.should_render :action_name
-* Fixed [#6884] intermittent errors related to method binding
-* Fixed [#6870] rspec on edge rails spec:controller fixture loading fails
-* Using obj.inspect for all messages
-* Improved performance by getting rid of instance_exec (instance_eval is good enough because we never need to pass it args)
-
-== Version 0.7.3
-
-Almost normal bug fix/new feature release.
-
-A couple of things you need to change in your rails specs:
-# spec_helper.rb is a little different (see http://rspec.rubyforge.org/upgrade.html)
-# use controller.should_render before OR after the action (controller.should_have_rendered is deprecated)
-
-* Applied [#6577] messy mock backtrace when frozen to edge rails (patch from Jay Levitt)
-* Fixed [#6674] rspec_on_rails fails on @session deprecation warning
-* Fixed [#6780] routing() was failing...fix included - works for 1.1.6 and edge (1.2)
-* Fixed [#6835] bad message with arbitrary predicate
-* Added [#6731] Partial templates rendered
-* Fixed [#6713] helper methods not rendered in view tests?
-* Fixed [#6707] cannot run controller / helper tests via rails_spec or spec only works with rake
-* Applied [#6417] lambda {...}.should_change(receiver, :message) (patch from Wilson Bilkovich)
-* Eliminated dependency on ZenTest
-* Fixed [#6650] Reserved characters in the TextMate bundle break svn on Win32
-* Fixed [#6643] script/generate rspec_controller: invalid symbol generation for 'controller_name' for *modularized* controllers
-* The script/rails_spec command has been moved to bin/drbspec in RSpec core (installed by the gem)
-
-== Version 0.7.2
-
-This release introduces a brand new RSpec bundle for TextMate, plus some small bugfixes.
-
-* Packaged RSpec.tmbundle.tgz as part of the distro
-* Fixed [#6593] Add moving progress bar to HtmlFormatter using Javascript
-* Applied [#6265] should_raise should accept an Exception object
-* Fixed [#6616] Can't run Rails specs with RSpec.tmbundle
-* Fixed [#6411] Can't run Rails specs with ruby
-* Added [#6589] New -l --line option. This is useful for IDE/editor runners/extensions.
-* Fixed [#6615] controller.should_render_rjs should support :partial => 'path/to/template'
-
-== Version 0.7.1
-
-Bug fixes and a couple o' new features.
-
-* Fixed [#6575] Parse error in aliasing the partial mock original method (patch by Brian Takita)
-* Fixed [#6277] debris left by stubbing (trunk) [submitted by dastels] (fixed by fix to [#6575])
-* Fixed [#6575] Parse error in aliasing the partial mock original method
-* Fixed [#6555] should_have_tag does not match documentation
-* Fixed [#6567] SyntaxError should not stop entire run
-* Fixed [#6558] integrated views look for template even when redirected
-* Fixed [#6547] response.should be_redirect broken in 0.7.0
-* Applied [#6471] Easy way to spec routes
-* Applied [#6587] Rspec on Rails displays "Spec::Rails::ContextFactory" as context name
-* Applied [#6514] Document has trivial typos.
-* Added [#6560] controller.session should be available before the action
-* Added support for should_have_rjs :visual_effect
-* Different printing and colours for unmet expectations (red) and other exceptions (magenta)
-* Simplified method_missing on mock_methods to make it less invasive on partial mocks.
-
-== Version 0.7.0
-
-This is the "Grow up and eat your own dog food release". RSpec is now used on itself and
-we're no longer using Test::Unit to test it. Although, we are still extending Test::Unit
-for the rails plugin (indirectly - through ZenTest)
-
-IMPORTANT NOTE: THIS RELEASE IS NOT 100% BACKWARDS COMPATIBLE TO 0.6.x
-
-There are a few changes that will require that you change your existing specs.
-
-RSpec now handles equality exactly like ruby does:
-
-# actual.should_equal(expected) will pass if actual.equal?(expected) returns true
-# actual.should eql(expected) will pass if actual.eql?(expected) returns true
-# actual.should == expected will pass if actual == expected) returns true
-
-At the high level, eql? implies equivalence, while equal? implies object identity. For more
-information on how ruby deals w/ equality, you should do this:
-
-ri equal?
-
-or look at this:
-
-http://www.ruby-doc.org/core/classes/Object.html#M001057
-
-Also, we left in should_be as a synonym for should_equal, so the only specs that should break are the
-ones using should_equal (which used to use <code>==</code> instead of <code>.equal?</code>).
-
-Lastly, should_be used to handle true and false differently from any other values. We've removed
-this special handling, so now actual.should_be true will fail for any value other than true (it
-used to pass for any non-nil, non-false value), and actual.should_be false will fail for any
-value other than false (it used to pass for nil or false).
-
-Here's what you'll need to do to update your specs:
-# search for "should_equal" and replace with "should_eql"
-# run specs
-
-If any specs still fail, they are probably related to should be_true or should_be_false using
-non-boolean values. Those you'll just have to inspect manually and adjust appropriately (sorry!).
-
---------------------------------------------------
-Specifying multiple return values in mocks now works like this:
-
-mock.should_receive(:message).and_return(1,2,3)
-
-It used to work like this:
-
-mock.should_receive(:message).and_return([1,2,3])
-
-but we decided that was counter intuitive and otherwise lame.
-
-Here's what you'll need to do to update your specs:
-# search for "and_return(["
-# get rid of the "[" and "]"
-
---------------------------------------------------
-RSpec on Rails now supports the following (thanks to ZenTest upon which it is built):
-
-# Separate specs for models, views, controllers and helpers
-# Controller specs are completely decoupled from the views by default (though you can tell them to couple themselves if you prefer)
-# View specs are completely decoupled from app-specific controllers
-
-See http://rspec.rubyforge.org/documentation/rails/index.html for more information
---------------------------------------------------
-As usual, there are also other new features and bug fixes:
-
-* Added lots of documentation on mocks/stubs and the rails plugin.
-* Added support for assigns[key] syntax for controller specs (to align w/ pre-existing syntax for view specs)
-* Added support for controller.should_redirect_to
-* RSpec on Rails automatically checks whether it's compatible with the installed RSpec
-* Applied [#6393] rspec_on_rails uses deprecated '@response' instead of the accessor
-* RSpec now has 100% spec coverage(!)
-* Added support for stubbing and partial mocking
-* Progress (....F..F.) is now coloured. Tweaked patch from KAKUTANI Shintaro.
-* Backtrace now excludes the rcov runner (/usr/local/bin/rcov)
-* Fixed [#5539] predicates do not work w/ rails
-* Added [#6091] support for Regexp matching messages sent to should_raise
-* Added [#6333] support for Regexp matching in mock arguments
-* Applied [#6283] refactoring of diff support to allow selectable formats and custom differs
-* Fixed [#5564] "ruby spec_file.rb" doesn't work the same way as "spec spec_file.rb"
-* Fixed [#6056] Multiple output of failing-spec notice
-* Fixed [#6233] Colours in specdoc
-* Applied [#6207] Allows --diff option to diff target and expected's #inspect output (Patch by Lachie Cox)
-* Fixed [#6203] Failure messages are misleading - consider using inspect.
-* Added [#6334] subject.should_have_xyz will try to call subject.has_xyz? - use this for hash.should_have_key(key)
-* Fixed [#6017] Rake task should ignore empty or non-existent spec-dirs
-
-== Version 0.6.4
-
-In addition to a number of bug fixes and patches, this release begins to formalize the support for
-RSpec on Rails.
-
-* Added Christopher Petrilli's TextMate bundle to vendor/textmate/RSpec.tmbundle
-* Fixed [#5909], once again supporting multi_word_predicates
-* Applied [#5873] - response.should_have_rjs (initial patch from Jake Howerton, based on ARTS by Kevin Clark)
-* Added generation of view specs for rspec_on_rails
-* Applied [#5815] active_record_subclass.should_have(3).records
-* Added support in "rake stats" for view specs (in spec/views)
-* Applied [#5801] QuickRef.pdf should say RSpec, not rSpec
-* Applied [#5728] rails_spec_runner fails on Windows (Patch from Lindsay Evans).
-* Applied [#5708] RSpec Rails plugin rspec_controller generator makes specs that do not parse.
-* Cleaned up RSpec on Rails so it doesn't pollute as much during bootstrapping.
-* Added support for response.should_have_tag and response.should_not_have_tag (works just like assert_tag in rails)
-* Added new -c, --colour, --color option for colourful (red/green) output. Inspired from Pat Eyler's Redgreen gem.
-* Added examples for Watir and Selenium under the gem's vendor directory.
-* Renamed rails_spec_runner to rails_spec_server (as referred to in the docs)
-* Added support for trying a plural for arbitrary predicates. E.g. Album.should_exist(:name => "Hey Jude") will call Album.exists?(:name => "Hey Jude")
-* Added support for should_have to work with methods taking args returning a collection. E.g. @dave.should_have(3).albums_i_have_that_this_guy_doesnt(@aslak)
-* Added [#5570] should_not_receive(:msg).with(:specific, "args")
-* 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.
-* 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.
-* Applied [#5620] support any boolean method and arbitrary comparisons (5.should_be < 6) (Patch from Mike Williams)
-
-== Version 0.6.3
-
-This release fixes some minor bugs related to RSpec on Rails
-Note that if you upgrade a rails app with this version of the rspec_on_rails plugin
-you should remove your lib/tasks/rspec.rake if it exists.
-
-* Backtraces from drb (and other standard ruby libraries) are now stripped from backtraces.
-* Applied [#5557] Put rspec.rake into the task directory of the RSpec on Rails plugin (Patch from Daniel Siemssen)
-* Applied [#5556] rails_spec_server loads environment.rb twice (Patch from Daniel Siemssen)
-
-== Version 0.6.2
-This release fixes a couple of regressions with the rake task that were introduced in the previous version (0.6.1)
-
-* Fixed [#5518] ruby -w: warnings in 0.6.1
-* Applied [#5525] fix rake task path to spec tool for gem-installed rspec (patch from Riley Lynch)
-* Fixed a teensey regression with the rake task - introduced in 0.6.1. The spec command is now quoted so it works on windows.
-
-== Version 0.6.1
-This is the "fix the most annoying bugs release" of RSpec. There are 9 bugfixes this time.
-Things that may break backwards compatibility:
-1) Spec::Rake::SpecTask no longer has the options attribute. Use ruby_opts, spec_opts and rcov_opts instead.
-
-* Fixed [#4891] RCOV task failing on windows
-* Fixed [#4896] Shouldn't modify user's $LOAD_PATH (Tip from Gavin Sinclair)
-* Fixed [#5369] ruby -w: warnings in RSpec 0.5.16 (Tip from Suraj Kurapati)
-* Applied [#5141] ExampleMatcher doesn't escape strings before matching (Patch from Nikolai Weibull).
-* Fixed [#5224] Move 'require diff-lcs' from test_helper.rb to diff_test.rb (Tip from Chris Roos)
-* Applied [#5449] Rake stats for specs (Patch from Nick Sieger)
-* Applied [#5468, #5058] Fix spec runner to correctly run controller specs (Patch from Daniel Siemssen)
-* Applied fixes to rails_spec_server to improve its ability to run several times. (Patch from Daniel Siemssen)
-* Changed RCov::VerifyTask to fail if the coverage is above the threshold. This is to ensure it gets bumped when coverage improves.
-
-== Version 0.6.0
-This release makes an official commitment to underscore_syntax (with no more support for dot.syntax)
-
-* Fixed bug (5292) that caused mock argument matching to fail
-* Converted ALL tests to use underscore syntax
-* Fixed all remaining problems with underscores revealed by converting all the tests to underscores
-* Enhanced sugar to support combinations of methods (i.e. once.and_return)
-* 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)
-* Added support for at_most in mocks
-* Added support for should_not_receive(:msg) (will be removing should_receive(:msg).never some time soon)
-* Added support for should_have_exactly(5).items_in_collection
-
-== Version 0.5.16
-This release improves Rails support and test2spec translation.
-
-* Fixed underscore problems that occurred when RSpec was used in Rails
-* Simplified the Rails support by packaging it as a plugin instead of a generator gem.
-* Fixed [#5063] 'rspec_on_rails' require line in spec_helper.rb
-* Added pre_commit rake task to reduce risk of regressions. Useful for RSpec developers and patchers.
-* Added failure_message to RSpec Rake task
-* test2spec now defines converted helper methods outside of the setup block (bug #5057).
-
-== Version 0.5.15
-This release removes a prematurely added feature that shouldn't have been added.
-
-* Removed support for differences that was added in 0.5.14. The functionality is not aligned with RSpec's vision.
-
-== Version 0.5.14
-This release introduces better ways to extend specs, improves some of the core API and
-a experimental support for faster rails specs.
-
-* Added proc methods for specifying differences (increments and decrements). See difference_test.rb
-* Methods can now be defined alongside specs. This obsoletes the need for defining methods in setup. (Patch #5002 from Brian Takita)
-* Sugar (underscores) now works correctly with should be_a_kind_of and should be_an_instance_of
-* Added support for include and inherit in contexts. (Patch #4971 from Brian Takita)
-* Added rails_spec and rails_spec_server for faster specs on rails (still buggy - help needed)
-* Fixed bug that caused should_render to break if given a :symbol (in Rails)
-* Added support for comparing exception message in should_raise and should_not_raise
-
-== Version 0.5.13
-This release fixes some subtle bugs in the mock API.
-
-* Use fully-qualified class name of Exceptions in failure message. Easier to debug that way.
-* Fixed a bug that caused mocks to yield a one-element array (rather than the element) when one yield arg specified.
-* Mocks not raise AmbiguousReturnError if an explicit return is used at the same time as an expectation block.
-* Blocks passed to yielding mocks can now raise without causing mock verification to fail.
-
-== Version 0.5.12
-This release adds diff support for failure messages, a HTML formatter plus some other
-minor enhancements.
-
-* Added HTML formatter.
-* Added fail_on_error option to spectask.
-* Added support for diffing, using the diff-lcs Rubygem (#2648).
-* Remove RSpec on Rails files from backtrace (#4694).
-* All of RSpec's own tests run successfully after translation with test2spec.
-* Added --verbose mode for test2spec - useful for debugging when classes fail to translate.
-* Output of various formatters is now flushed - to get more continuous output.
-
-== Version 0.5.11
-This release makes test2spec usable with Rails (with some manual steps).
-See http://rspec.rubyforge.org/tools/rails.html for more details
-
-* test2spec now correctly translates bodies of helper methods (non- test_*, setup and teardown ones).
-* Added more documentation about how to get test2spec to work with Rails.
-
-== Version 0.5.10
-This version features a second rewrite of test2spec - hopefully better than the previous one.
-
-* Improved test2spec's internals. It now transforms the syntax tree before writing out the code.
-
-== Version 0.5.9
-This release improves test2spec by allowing more control over the output
-
-* Added --template option to test2spec, which allows for custom output driven by ERB
-* Added --quiet option to test2spec
-* Removed unnecessary dependency on RubyToC
-
-== Version 0.5.8
-This release features a new Test::Unit to RSpec translation tool.
-Also note that the RubyGem of the previous release (0.5.7) was corrupt.
-We're close to being able to translate all of RSpec's own Test::Unit
-tests and have them run successfully!
-
-* Updated test2spec documentation.
-* Replaced old test2rspec with a new test2spec, which is based on ParseTree and RubyInline.
-
-== Version 0.5.7
-This release changes examples and documentation to recommend underscores rather than dots,
-and addresses some bugfixes and changes to the spec commandline.
-
-* spec DIR now works correctly, recursing down and slurping all *.rb files
-* All documentation and examples are now using '_' instead of '.'
-* Custom external formatters can now be specified via --require and --format.
-
-== Version 0.5.6
-This release fixes a bug in the Rails controller generator
-
-* The controller generator did not write correct source code (missing 'do'). Fixed.
-
-== Version 0.5.5
-This release adds initial support for Ruby on Rails in the rspec_generator gem.
-
-* [Rails] Reorganised Lachie's original code to be a generator packaged as a gem rather than a plugin.
-* [Rails] Imported code from http://lachie.info/svn/projects/rails_plugins/rspec_on_rails (Written by Lachie Cox)
-* Remove stack trace lines from TextMate's Ruby bundle
-* Better error message from spectask when no spec files are found.
-
-== Version 0.5.4
-The "the tutorial is ahead of the gem" release
-
-* Support for running a single spec with --spec
-* Exitcode is now 1 unless all specs pass, in which case it's 0.
-* -v, --version now both mean the same thing
-* For what was verbose output (-v), use --format specdoc or -f s
-* --format rdoc always runs in dry-run mode
-* Removed --doc and added --format and --dry-run
-* Refactored towards more pluggable formatters
-* Use webgen's execute tag when generating website (more accurate)
-* Fixed incorrect quoting of spec_opts in SpecTask
-* Added patch to enable underscored shoulds like 1.should_equal(1) - patch from Rich Kilmer
-* Removed most inherited instance method from Mock, making more methods mockable.
-* Made the RCovVerify task part of the standard toolset.
-* Documented Rake task and how to use it with Rcov
-* Implemented <ruby></ruby> tags for website (hooking into ERB, RedCloth and syntax)
-* RSpec Rake task now takes spec_opts and out params so it can be used for doc generation
-* RCov integration for RSpec Rake task (#4058)
-* Group all results instead of printing them several times (#4057)
-* Mocks can now yield
-* Various improvements to error reporting (including #4191)
-* backtrace excludes rspec code - use -b to include it
-* split examples into examples (passing) and failing_examples
-
-== Version 0.5.3
-The "hurry up, CoR is in two days" release.
-
-* Don't run rcov by default
-* Make separate task for running tests with RCov
-* Added Rake task to fail build if coverage drops below a certain threshold
-* Even more failure output cleanup (simplification)
-* Added duck_type constraint for mocks
-
-== Version 0.5.2
-This release has minor improvements to the commandline and fixes some gem warnings
-
-* Readded README to avoid RDoc warnings
-* Added --version switch to commandline
-* More changes to the mock API
-
-== Version 0.5.1
-This release is the first release of RSpec with a new website. It will look better soon.
-
-* Added initial documentation for API
-* Added website based on webgen
-* Modified test task to use rcov
-* Deleted unused code (thanks, rcov!)
-* Various changes to the mock API,
-* Various improvements to failure reporting
-
-== Version 0.5.0
-This release introduces a new API and obsolesces previous versions.
-
-* Moved source code to separate subfolders
-* Added new DSL runner based on instance_exec
-* Added spike for testdox/rdoc generation
-* merge Astels' and Chelimsky's work on ShouldHelper
-* this would be 0.5.0 if I updated the documentation
-* it breaks all of your existing specifications. We're not sorry.
-
-== Version 0.3.2
-
-The "srbaker is an idiot" release.
-
-* also forgot to update the path to the actual Subversion repository
-* this should be it
-
-== Version 0.3.1
-
-This is just 0.3.0, but with the TUTORIAL added to the documentation list.
-
-* forgot to include TUTORIAL in the documentation
-
-== Version 0.3.0
-
-It's been a while since last release, lots of new stuff is available. For instance:
-
-* improvements to the runners
-* addition of should_raise expectation (thanks to Brian Takita)
-* some documentation improvements
-* RSpec usable as a DSL
-
-== Version 0.2.0
-
-This release provides a tutorial for new users wishing to get started with
-RSpec, and many improvements.
-
-* improved reporting in the spec runner output
-* update the examples to the new mock api
-* added TUTORIAL, a getting started document for new users of RSpec
-
-== Version 0.1.7
-
-This release improves installation and documentation, mock integration and error reporting.
-
-* Comparison errors now print the class name too.
-* Mocks now take an optional +options+ parameter to specify behaviour.
-* Removed __expects in favour of should_receive
-* Added line number reporting in mock error messages for unreceived message expectations.
-* Added should_match and should_not_match.
-* Added a +mock+ method to Spec::Context which will create mocks that autoverify (no need to call __verify).
-* Mocks now require names in the constructor to ensure sensible error messages.
-* Made 'spec' executable and updated usage instructions in README accordingly.
-* Made more parts of the Spec::Context API private to avoid accidental usage.
-* Added more RDoc to Spec::Context.
-
-== Version 0.1.6
-
-More should methods.
-
-* Added should_match and should_not_match.
-
-== Version 0.1.5
-
-Included examples and tests in gem.
-
-== Version 0.1.4
-
-More tests on block based Mock expectations.
-
-== Version 0.1.3
-
-Improved mocking:
-
-* block based Mock expectations.
-
-== Version 0.1.2
-
-This release adds some improvements to the mock API and minor syntax improvements
-
-* Added Mock.should_expect for a more consistent DSL.
-* Added MockExpectation.and_returns for a better DSL.
-* Made Mock behave as a null object after a call to Mock.ignore_missing
-* Internal syntax improvements.
-* Improved exception trace by adding exception class name to error message.
-* Renamed some tests for better consistency.
-
-== Version 0.1.1
-
-This release adds some shoulds and improves error reporting
-
-* Added should be_same_as and should_not be_same_as.
-* Improved error reporting for comparison expectations.
-
-== Version 0.1.0
-
-This is the first preview release of RSpec, a Behaviour-Driven Development library for Ruby
-
-* Added Rake script with tasks for gems, rdoc etc.
-* Added an XForge task to make release go easier.
+++ /dev/null
-Copyright (c) 2005-2007 The RSpec Development Team
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+++ /dev/null
-== RSpec
-
-RSpec is a Behaviour Driven Development framework with tools to express User Stories
-with Executable Scenarios and Executable Examples at the code level.
-
-RSpec ships with several modules:
-
-Spec::Story provides a framework for expressing User Stories
-
-Spec::Example provides a framework for expressing code Examples
-
-Spec::Matchers provides Expression Matchers for use with Spec::Expectations
-and Spec::Mocks.
-
-Spec::Expectations supports setting expectations on your objects so you
-can do things like:
-
- result.should equal(expected_result)
-
-Spec::Mocks supports creating Mock Objects, Stubs, and adding Mock/Stub
-behaviour to your existing objects.
-
-== Installation
-
-The simplest approach is to install the gem:
-
- gem install -r rspec #mac users must sudo
-
-== Building the RSpec gem
-If you prefer to build the gem locally, check out source from svn://rubyforge.org/var/svn/rspec/trunk. Then
-do the following:
-
- rake gem
- gem install pkg/rspec-0.x.x.gem (you may have to sudo)
-
-== Running RSpec's specs
-In order to run RSpec's full suite of specs (rake pre_commit) you must install the following gems:
-
-* rake # Runs the build script
-* rcov # Verifies that the code is 100% covered by specs
-* webby # Generates the static HTML website
-* syntax # Required to highlight ruby code
-* diff-lcs # Required if you use the --diff switch
-* win32console # Required by the --colour switch if you're on Windows
-* meta_project # Required in order to make releases at RubyForge
-* heckle # Required if you use the --heckle switch
-* hpricot # Used for parsing HTML from the HTML output formatter in RSpec's own specs
-
-Once those are all installed, you should be able to run the suite with the following steps:
-
-* svn co svn://rubyforge.org/var/svn/rspec/trunk rspec
-* cd rspec
-* rake install_dependencies
-* cd example_rails_app
-* export RSPEC_RAILS_VERSION=1.2.3
-* rake rspec:generate_mysql_config
-* mysql -u root < db/mysql_setup.sql
-* cd ..
-* rake pre_commit
-
-Note that RSpec itself - once built - doesn't have any dependencies outside the Ruby core
-and stdlib - with a few exceptions:
-
-* The spec command line uses diff-lcs when --diff is specified.
-* The spec command line uses heckle when --heckle is specified.
-* The Spec::Rake::SpecTask needs RCov if RCov is enabled in the task.
-
-See http://rspec.rubyforge.org for further documentation.
-
-== Contributing
-
+++ /dev/null
-$:.unshift('lib')
-require 'rubygems'
-require 'rake/gempackagetask'
-require 'rake/contrib/rubyforgepublisher'
-require 'rake/clean'
-require 'rake/rdoctask'
-require 'rake/testtask'
-require 'spec/version'
-dir = File.dirname(__FILE__)
-$LOAD_PATH.unshift(File.expand_path("#{dir}/../pre_commit/lib"))
-require "pre_commit"
-
-# Some of the tasks are in separate files since they are also part of the website documentation
-load File.dirname(__FILE__) + '/rake_tasks/examples.rake'
-load File.dirname(__FILE__) + '/rake_tasks/examples_with_rcov.rake'
-load File.dirname(__FILE__) + '/rake_tasks/failing_examples_with_html.rake'
-load File.dirname(__FILE__) + '/rake_tasks/verify_rcov.rake'
-
-PKG_NAME = "rspec"
-PKG_VERSION = Spec::VERSION::STRING
-PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
-PKG_FILES = FileList[
- '[A-Z]*',
- 'lib/**/*.rb',
- 'spec/**/*.rb',
- 'examples/**/*',
- 'plugins/**/*',
- 'stories/**/*'
-]
-
-task :default => [:verify_rcov]
-task :verify_rcov => [:spec, :stories]
-
-desc "Run all specs"
-Spec::Rake::SpecTask.new do |t|
- t.spec_files = FileList['spec/**/*_spec.rb']
- t.spec_opts = ['--options', 'spec.opts']
- unless ENV['NO_RCOV']
- t.rcov = true
- t.rcov_dir = '../doc/output/coverage'
- t.rcov_opts = ['--exclude', 'spec\/spec,bin\/spec,examples,\/var\/lib\/gems,\/Library\/Ruby,\.autotest']
- end
-end
-
-desc "Run all stories"
-task :stories do
- html = 'story_server/prototype/rspec_stories.html'
- ruby "stories/all.rb --colour --format plain --format html:#{html}"
- unless IO.read(html) =~ /<span class="param">/m
- raise 'highlighted parameters are broken in story HTML'
- end
-end
-
-desc "Run all specs and store html output in doc/output/report.html"
-Spec::Rake::SpecTask.new('spec_html') do |t|
- t.spec_files = FileList['spec/**/*_spec.rb', '../../RSpec.tmbundle/Support/spec/*_spec.rb']
- t.spec_opts = ['--format html:../doc/output/report.html','--backtrace']
-end
-
-desc "Run all failing examples"
-Spec::Rake::SpecTask.new('failing_examples') do |t|
- t.spec_files = FileList['failing_examples/**/*_spec.rb']
-end
-
-desc 'Generate RDoc'
-rd = Rake::RDocTask.new do |rdoc|
- rdoc.rdoc_dir = '../doc/output/rdoc'
- rdoc.options << '--title' << 'RSpec' << '--line-numbers' << '--inline-source' << '--main' << 'README'
- rdoc.rdoc_files.include('README', 'CHANGES', 'MIT-LICENSE', 'UPGRADE', 'lib/**/*.rb')
-end
-
-spec = Gem::Specification.new do |s|
- s.name = PKG_NAME
- s.version = PKG_VERSION
- s.summary = Spec::VERSION::DESCRIPTION
- s.description = <<-EOF
- RSpec is a behaviour driven development (BDD) framework for Ruby. RSpec was
- created in response to Dave Astels' article _A New Look at Test Driven Development_
- which can be read at: http://daveastels.com/index.php?p=5 RSpec is intended to
- provide the features discussed in Dave's article.
- EOF
-
- s.files = PKG_FILES.to_a
- s.require_path = 'lib'
-
- s.has_rdoc = true
- s.rdoc_options = rd.options
- s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$|^EXAMPLES.rd$/ }.to_a
-
- s.bindir = 'bin'
- s.executables = ['spec', 'spec_translator']
- s.default_executable = 'spec'
- s.author = "RSpec Development Team"
- s.email = "rspec-devel@rubyforge.org"
- s.homepage = "http://rspec.rubyforge.org"
- s.platform = Gem::Platform::RUBY
- s.rubyforge_project = "rspec"
-end
-
-Rake::GemPackageTask.new(spec) do |pkg|
- pkg.need_zip = true
- pkg.need_tar = true
-end
-
-def egrep(pattern)
- Dir['**/*.rb'].each do |fn|
- count = 0
- open(fn) do |f|
- while line = f.gets
- count += 1
- if line =~ pattern
- puts "#{fn}:#{count}:#{line}"
- end
- end
- end
- end
-end
-
-desc "Look for TODO and FIXME tags in the code"
-task :todo do
- egrep /(FIXME|TODO|TBD)/
-end
-
-task :clobber do
- core.clobber
-end
-
-task :release => [:clobber, :verify_committed, :verify_user, :spec, :publish_packages, :tag, :publish_news]
-
-desc "Verifies that there is no uncommitted code"
-task :verify_committed do
- IO.popen('svn stat') do |io|
- io.each_line do |line|
- raise "\n!!! Do a svn commit first !!!\n\n" if line =~ /^\s*M\s*/
- end
- end
-end
-
-desc "Creates a tag in svn"
-task :tag do
- from = `svn info #{File.dirname(__FILE__)}`.match(/URL: (.*)\/rspec/n)[1]
- to = from.gsub(/trunk/, "tags/#{Spec::VERSION::TAG}")
- current = from.gsub(/trunk/, "tags/CURRENT")
-
- puts "Creating tag in SVN"
- tag_cmd = "svn cp #{from} #{to} -m \"Tag release #{Spec::VERSION::FULL_VERSION}\""
- `#{tag_cmd}` ; raise "ERROR: #{tag_cmd}" unless $? == 0
-
- puts "Removing CURRENT"
- remove_current_cmd = "svn rm #{current} -m \"Remove tags/CURRENT\""
- `#{remove_current_cmd}` ; raise "ERROR: #{remove_current_cmd}" unless $? == 0
-
- puts "Re-Creating CURRENT"
- create_current_cmd = "svn cp #{to} #{current} -m \"Copy #{Spec::VERSION::TAG} to tags/CURRENT\""
- `#{create_current_cmd}` ; "ERROR: #{create_current_cmd}" unless $? == 0
-end
-
-desc "Run this task before you commit. You should see 'OK TO COMMIT'"
-task(:pre_commit) {core.pre_commit}
-
-desc "Build the website, but do not publish it"
-task(:website) {core.website}
-
-task(:rdoc_rails) {core.rdoc_rails}
-
-task :verify_user do
- raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
-end
-
-desc "Upload Website to RubyForge"
-task :publish_website => [:verify_user, :website] do
- unless Spec::VERSION::RELEASE_CANDIDATE
- publisher = Rake::SshDirPublisher.new(
- "rspec-website@rubyforge.org",
- "/var/www/gforge-projects/#{PKG_NAME}",
- "../doc/output"
- )
- publisher.upload
- else
- puts "** Not publishing packages to RubyForge - this is a prerelease"
- end
-end
-
-desc "Upload Website archive to RubyForge"
-task :archive_website => [:verify_user, :website] do
- publisher = Rake::SshDirPublisher.new(
- "rspec-website@rubyforge.org",
- "/var/www/gforge-projects/#{PKG_NAME}/#{Spec::VERSION::TAG}",
- "../doc/output"
- )
- publisher.upload
-end
-
-desc "Package the Rails plugin"
-task :package_rspec_on_rails do
- mkdir 'pkg' rescue nil
- rm_rf 'pkg/rspec_on_rails' rescue nil
- `svn export ../rspec_on_rails pkg/rspec_on_rails-#{PKG_VERSION}`
- Dir.chdir 'pkg' do
- `tar cvzf rspec_on_rails-#{PKG_VERSION}.tgz rspec_on_rails-#{PKG_VERSION}`
- end
-end
-task :pkg => :package_rspec_on_rails
-
-desc "Package the RSpec.tmbundle"
-task :package_tmbundle do
- mkdir 'pkg' rescue nil
- rm_rf 'pkg/RSpec.tmbundle' rescue nil
- `svn export ../RSpec.tmbundle pkg/RSpec.tmbundle`
- Dir.chdir 'pkg' do
- `tar cvzf RSpec-#{PKG_VERSION}.tmbundle.tgz RSpec.tmbundle`
- end
-end
-task :pkg => :package_tmbundle
-
-desc "Publish gem+tgz+zip on RubyForge. You must make sure lib/version.rb is aligned with the CHANGELOG file"
-task :publish_packages => [:verify_user, :package] do
- release_files = FileList[
- "pkg/#{PKG_FILE_NAME}.gem",
- "pkg/#{PKG_FILE_NAME}.tgz",
- "pkg/rspec_on_rails-#{PKG_VERSION}.tgz",
- "pkg/#{PKG_FILE_NAME}.zip",
- "pkg/RSpec-#{PKG_VERSION}.tmbundle.tgz"
- ]
- unless Spec::VERSION::RELEASE_CANDIDATE
- require 'meta_project'
- require 'rake/contrib/xforge'
-
- Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new(PKG_NAME)) do |xf|
- # Never hardcode user name and password in the Rakefile!
- xf.user_name = ENV['RUBYFORGE_USER']
- xf.files = release_files.to_a
- xf.release_name = "RSpec #{PKG_VERSION}"
- end
- else
- puts "SINCE THIS IS A PRERELEASE, FILES ARE UPLOADED WITH SSH, NOT TO THE RUBYFORGE FILE SECTION"
- puts "YOU MUST TYPE THE PASSWORD #{release_files.length} TIMES..."
-
- host = "rspec-website@rubyforge.org"
- remote_dir = "/var/www/gforge-projects/#{PKG_NAME}"
-
- publisher = Rake::SshFilePublisher.new(
- host,
- remote_dir,
- File.dirname(__FILE__),
- *release_files
- )
- publisher.upload
-
- puts "UPLADED THE FOLLOWING FILES:"
- release_files.each do |file|
- name = file.match(/pkg\/(.*)/)[1]
- puts "* http://rspec.rubyforge.org/#{name}"
- end
-
- puts "They are not linked to anywhere, so don't forget to tell people!"
- end
-end
-
-desc "Publish news on RubyForge"
-task :publish_news => [:verify_user] do
- unless Spec::VERSION::RELEASE_CANDIDATE
- require 'meta_project'
- require 'rake/contrib/xforge'
- Rake::XForge::NewsPublisher.new(MetaProject::Project::XForge::RubyForge.new(PKG_NAME)) do |news|
- # Never hardcode user name and password in the Rakefile!
- news.user_name = ENV['RUBYFORGE_USER']
- end
- else
- puts "** Not publishing news to RubyForge - this is a prerelease"
- end
-end
-
-def core
- PreCommit::Core.new(self)
-end
+++ /dev/null
-=== Before releasing 1.1.0:
-
+++ /dev/null
-= Upgrading existing code to RSpec-0.9
-
-== General (see below for Spec::Rails specifics)
-
-=== New Syntax for should and should_not
-
-* Use translator (should get 90% of your code)
-* Manually fix "parenthesis" warnings
-
-=== Change before_context_eval to before_eval
-
-before_context_eval is an un-published hook used by
-Spec::Rails to create specialized behaviour contexts.
-Most of you don't need to change this, but for those
-who have exploited it, you'll need to change it to
-before_eval.
-
-== Spec::Rails
-
-=== spec_helper.rb
-
-We've added a new way to configure Spec::Runner to do
-things like use_transactional_fixtures and use_instantiated_fixtures.
-You'll need to update spec/spec_helper.rb accordingly. You can either
-just re-generate it:
-
- script/generate rspec
-
-Or modify spec_helper.rb based on the template, which can be found at:
-
- vendor/plugins/rspec_on_rails/generators/rspec/templates/spec_helper.rb
\ No newline at end of file
+++ /dev/null
-#!/usr/bin/env ruby
-$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
-require 'spec'
-exit ::Spec::Runner::CommandLine.run(rspec_options)
+++ /dev/null
-#!/usr/bin/env ruby
-raise "\n\nUsage: spec_translator from_dir to_dir\n\n" if ARGV.size != 2
-$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
-require 'spec/translator'
-t = ::Spec::Translator.new
-from = ARGV[0]
-to = ARGV[1]
-t.translate(from, to)
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-
-# Run spec w/ -fs to see the output of this file
-
-describe "Examples with no descriptions" do
-
- # description is auto-generated as "should equal(5)" based on the last #should
- it do
- 3.should equal(3)
- 5.should equal(5)
- end
-
- it { 3.should be < 5 }
-
- it { ["a"].should include("a") }
-
- it { [1,2,3].should respond_to(:size) }
-
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-$global = 0
-
-describe "State created in before(:all)" do
- before :all do
- @sideeffect = 1
- $global +=1
- end
-
- before :each do
- @isolated = 1
- end
-
- it "should be accessible from example" do
- @sideeffect.should == 1
- $global.should == 1
- @isolated.should == 1
-
- @sideeffect += 1
- @isolated += 1
- end
-
- it "should not have sideffects" do
- @sideeffect.should == 1
- $global.should == 2
- @isolated.should == 1
-
- @sideeffect += 1
- @isolated += 1
- end
-
- after :each do
- $global += 1
- end
-
- after :all do
- $global.should == 3
- $global = 0
- end
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-
-def behave_as_electric_musician
- respond_to(:read_notes, :turn_down_amp)
-end
-
-def behave_as_musician
- respond_to(:read_notes)
-end
-
-module BehaveAsExample
-
- class BluesGuitarist
- def read_notes; end
- def turn_down_amp; end
- end
-
- class RockGuitarist
- def read_notes; end
- def turn_down_amp; end
- end
-
- class ClassicGuitarist
- def read_notes; end
- end
-
- describe BluesGuitarist do
- it "should behave as guitarist" do
- BluesGuitarist.new.should behave_as_electric_musician
- end
- end
-
- describe RockGuitarist do
- it "should behave as guitarist" do
- RockGuitarist.new.should behave_as_electric_musician
- end
- end
-
- describe ClassicGuitarist do
- it "should not behave as guitarist" do
- ClassicGuitarist.new.should behave_as_musician
- end
- end
-
-end
+++ /dev/null
-module AnimalSpecHelper
- class Eat
- def initialize(food)
- @food = food
- end
-
- def matches?(animal)
- @animal = animal
- @animal.eats?(@food)
- end
-
- def failure_message
- "expected #{@animal} to eat #{@food}, but it does not"
- end
-
- def negative_failure_message
- "expected #{@animal} not to eat #{@food}, but it does"
- end
- end
-
- def eat(food)
- Eat.new(food)
- end
-end
-
-module Animals
- class Animal
- def eats?(food)
- return foods_i_eat.include?(food)
- end
- end
-
- class Mouse < Animal
- def foods_i_eat
- [:cheese]
- end
- end
-
- describe Mouse do
- include AnimalSpecHelper
- before(:each) do
- @mouse = Animals::Mouse.new
- end
-
- it "should eat cheese" do
- @mouse.should eat(:cheese)
- end
-
- it "should not eat cat" do
- @mouse.should_not eat(:cat)
- end
- end
-
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-require 'spec/runner/formatter/progress_bar_formatter'
-
-# Example of a formatter with custom bactrace printing. Run me with:
-# ruby bin/spec failing_examples -r examples/custom_formatter.rb -f CustomFormatter
-class CustomFormatter < Spec::Runner::Formatter::ProgressBarFormatter
- def backtrace_line(line)
- line.gsub(/([^:]*\.rb):(\d*)/) do
- "<a href=\"file://#{File.expand_path($1)}\">#{$1}:#{$2}</a> "
- end
- end
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-
-describe "Some integers" do
- (1..10).each do |n|
- it "The root of #{n} square should be #{n}" do
- Math.sqrt(n*n).should == n
- end
- end
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-class FileAccessor
- def open_and_handle_with(pathname, processor)
- pathname.open do |io|
- processor.process(io)
- end
- end
-end
-
-if __FILE__ == $0
- require File.dirname(__FILE__) + '/io_processor'
- require 'pathname'
-
- accessor = FileAccessor.new
- io_processor = IoProcessor.new
- file = Pathname.new ARGV[0]
-
- accessor.open_and_handle_with(file, io_processor)
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-require File.dirname(__FILE__) + '/file_accessor'
-require 'stringio'
-
-describe "A FileAccessor" do
- # This sequence diagram illustrates what this spec specifies.
- #
- # +--------------+ +----------+ +-------------+
- # | FileAccessor | | Pathname | | IoProcessor |
- # +--------------+ +----------+ +-------------+
- # | | |
- # open_and_handle_with | | |
- # -------------------->| | open | |
- # | |--------------->| | |
- # | | io | | |
- # | |<...............| | |
- # | | | process(io) |
- # | |---------------------------------->| |
- # | | | | |
- # | |<..................................| |
- # | | |
- #
- it "should open a file and pass it to the processor's process method" do
- # This is the primary actor
- accessor = FileAccessor.new
-
- # These are the primary actor's neighbours, which we mock.
- file = mock "Pathname"
- io_processor = mock "IoProcessor"
-
- io = StringIO.new "whatever"
- file.should_receive(:open).and_yield io
- io_processor.should_receive(:process).with(io)
-
- accessor.open_and_handle_with(file, io_processor)
- end
-
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-# greeter.rb
-#
-# Based on http://glu.ttono.us/articles/2006/12/19/tormenting-your-tests-with-heckle
-#
-# Run with:
-#
-# spec greeter_spec.rb --heckle Greeter
-#
-class Greeter
- def initialize(person = nil)
- @person = person
- end
-
- def greet
- @person.nil? ? "Hi there!" : "Hi #{@person}!"
- end
-end
-
-describe "Greeter" do
- it "should say Hi to person" do
- greeter = Greeter.new("Kevin")
- greeter.greet.should == "Hi Kevin!"
- end
-
- it "should say Hi to nobody" do
- greeter = Greeter.new
- # Uncomment the next line to make Heckle happy
- #greeter.greet.should == "Hi there!"
- end
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-
-module HelperMethodExample
- describe "an example group with helper a method" do
- def helper_method
- "received call"
- end
-
- it "should make that method available to specs" do
- helper_method.should == "received call"
- end
- end
-end
-
+++ /dev/null
-class DataTooShort < StandardError; end
-
-class IoProcessor
- # Does some fancy stuff unless the length of +io+ is shorter than 32
- def process(io)
- raise DataTooShort if io.read.length < 32
- end
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-require File.dirname(__FILE__) + '/io_processor'
-require 'stringio'
-
-describe "An IoProcessor" do
- before(:each) do
- @processor = IoProcessor.new
- end
-
- it "should raise nothing when the file is exactly 32 bytes" do
- lambda {
- @processor.process(StringIO.new("z"*32))
- }.should_not raise_error
- end
-
- it "should raise an exception when the file length is less than 32 bytes" do
- lambda {
- @processor.process(StringIO.new("z"*31))
- }.should raise_error(DataTooShort)
- end
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-context "A legacy spec" do
- setup do
- end
-
- specify "should work fine" do
- end
-
- teardown do
- end
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-
-describe "A consumer of a mock" do
- it "should be able to send messages to the mock" do
- mock = mock("poke me")
- mock.should_receive(:poke)
- mock.poke
- end
-end
-
-describe "a mock" do
- it "should be able to mock the same message twice w/ different args" do
- mock = mock("mock")
- mock.should_receive(:msg).with(:arg1).and_return(:val1)
- mock.should_receive(:msg).with(:arg2).and_return(:val2)
- mock.msg(:arg1).should eql(:val1)
- mock.msg(:arg2).should eql(:val2)
- end
-
- it "should be able to mock the same message twice w/ different args in reverse order" do
- mock = mock("mock")
- mock.should_receive(:msg).with(:arg1).and_return(:val1)
- mock.should_receive(:msg).with(:arg2).and_return(:val2)
- mock.msg(:arg2).should eql(:val2)
- mock.msg(:arg1).should eql(:val1)
- end
-end
+++ /dev/null
-class MultiThreadedExampleGroupRunner < Spec::Runner::ExampleGroupRunner
- def initialize(options, arg)
- super(options)
- # configure these
- @thread_count = 4
- @thread_wait = 0
- end
-
- def run
- @threads = []
- q = Queue.new
- example_groups.each { |b| q << b}
- success = true
- @thread_count.times do
- @threads << Thread.new(q) do |queue|
- while not queue.empty?
- example_group = queue.pop
- success &= example_group.suite.run(nil)
- end
- end
- sleep @thread_wait
- end
- @threads.each {|t| t.join}
- success
- end
-end
-
-MultiThreadedBehaviourRunner = MultiThreadedExampleGroupRunner
\ No newline at end of file
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-require File.dirname(__FILE__) + '/stack'
-
-class StackExamples < Spec::ExampleGroup
- describe(Stack)
- before(:each) do
- @stack = Stack.new
- end
-end
-
-class EmptyStackExamples < StackExamples
- describe("when empty")
- it "should be empty" do
- @stack.should be_empty
- end
-end
-
-class AlmostFullStackExamples < StackExamples
- describe("when almost full")
- before(:each) do
- (1..9).each {|n| @stack.push n}
- end
- it "should be full" do
- @stack.should_not be_full
- end
-end
-
-class FullStackExamples < StackExamples
- describe("when full")
- before(:each) do
- (1..10).each {|n| @stack.push n}
- end
- it "should be full" do
- @stack.should be_full
- end
-end
\ No newline at end of file
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-
-class MockableClass
- def self.find id
- return :original_return
- end
-end
-
-describe "A partial mock" do
-
- it "should work at the class level" do
- MockableClass.should_receive(:find).with(1).and_return {:stub_return}
- MockableClass.find(1).should equal(:stub_return)
- end
-
- it "should revert to the original after each spec" do
- MockableClass.find(1).should equal(:original_return)
- end
-
- it "can be mocked w/ ordering" do
- MockableClass.should_receive(:msg_1).ordered
- MockableClass.should_receive(:msg_2).ordered
- MockableClass.should_receive(:msg_3).ordered
- MockableClass.msg_1
- MockableClass.msg_2
- MockableClass.msg_3
- end
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-
-describe "pending example (using pending method)" do
- it %Q|should be reported as "PENDING: for some reason"| do
- pending("for some reason")
- end
-end
-
-describe "pending example (with no block)" do
- it %Q|should be reported as "PENDING: Not Yet Implemented"|
-end
-
-describe "pending example (with block for pending)" do
- it %Q|should have a failing block, passed to pending, reported as "PENDING: for some reason"| do
- pending("for some reason") do
- raise "some reason"
- end
- end
-end
-
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-
-class BddFramework
- def intuitive?
- true
- end
-
- def adopted_quickly?
- true
- end
-end
-
-describe "BDD framework" do
-
- before(:each) do
- @bdd_framework = BddFramework.new
- end
-
- it "should be adopted quickly" do
- @bdd_framework.should be_adopted_quickly
- end
-
- it "should be intuitive" do
- @bdd_framework.should be_intuitive
- end
-
-end
+++ /dev/null
-examples/custom_expectation_matchers.rb
\ No newline at end of file
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-
-module SharedExampleGroupExample
- class OneThing
- def what_things_do
- "stuff"
- end
- end
-
- class AnotherThing
- def what_things_do
- "stuff"
- end
- end
-
- class YetAnotherThing
- def what_things_do
- "stuff"
- end
- end
-
- # A SharedExampleGroup is an example group that doesn't get run.
- # You can create one like this:
- share_examples_for "most things" do
- def helper_method
- "helper method"
- end
-
- it "should do what things do" do
- @thing.what_things_do.should == "stuff"
- end
- end
-
- # A SharedExampleGroup is also module. If you create one like this
- # it gets assigned to the constant AllThings
- share_as :MostThings do
- def helper_method
- "helper method"
- end
-
- it "should do what things do" do
- @thing.what_things_do.should == "stuff"
- end
- end
-
- describe OneThing do
- # Now you can include the shared example group like this, which
- # feels more like what you might say ...
- it_should_behave_like "most things"
-
- before(:each) { @thing = OneThing.new }
-
- it "should have access to helper methods defined in the shared example group" do
- helper_method.should == "helper method"
- end
- end
-
- describe AnotherThing do
- # ... or you can include the example group like this, which
- # feels more like the programming language we love.
- it_should_behave_like MostThings
-
- before(:each) { @thing = AnotherThing.new }
-
- it "should have access to helper methods defined in the shared example group" do
- helper_method.should == "helper method"
- end
- end
-
- describe YetAnotherThing do
- # ... or you can include the example group like this, which
- # feels more like the programming language we love.
- include MostThings
-
- before(:each) { @thing = AnotherThing.new }
-
- it "should have access to helper methods defined in the shared example group" do
- helper_method.should == "helper method"
- end
- end
-end
+++ /dev/null
-require File.join(File.dirname(__FILE__), *%w[spec_helper])
-
-shared_examples_for "non-empty Stack" do
-
- it { @stack.should_not be_empty }
-
- it "should return the top item when sent #peek" do
- @stack.peek.should == @last_item_added
- end
-
- it "should NOT remove the top item when sent #peek" do
- @stack.peek.should == @last_item_added
- @stack.peek.should == @last_item_added
- end
-
- it "should return the top item when sent #pop" do
- @stack.pop.should == @last_item_added
- end
-
- it "should remove the top item when sent #pop" do
- @stack.pop.should == @last_item_added
- unless @stack.empty?
- @stack.pop.should_not == @last_item_added
- end
- end
-
-end
-
-shared_examples_for "non-full Stack" do
-
- it { @stack.should_not be_full }
-
- it "should add to the top when sent #push" do
- @stack.push "newly added top item"
- @stack.peek.should == "newly added top item"
- end
-
-end
\ No newline at end of file
+++ /dev/null
-lib_path = File.expand_path("#{File.dirname(__FILE__)}/../../lib")
-$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
-require 'spec'
+++ /dev/null
-class StackUnderflowError < RuntimeError
-end
-
-class StackOverflowError < RuntimeError
-end
-
-class Stack
-
- def initialize
- @items = []
- end
-
- def push object
- raise StackOverflowError if @items.length == 10
- @items.push object
- end
-
- def pop
- raise StackUnderflowError if @items.empty?
- @items.delete @items.last
- end
-
- def peek
- raise StackUnderflowError if @items.empty?
- @items.last
- end
-
- def empty?
- @items.empty?
- end
-
- def full?
- @items.length == 10
- end
-
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-require File.dirname(__FILE__) + "/stack"
-require File.dirname(__FILE__) + '/shared_stack_examples'
-
-describe Stack, " (empty)" do
- before(:each) do
- @stack = Stack.new
- end
-
- # NOTE that this one auto-generates the description "should be empty"
- it { @stack.should be_empty }
-
- it_should_behave_like "non-full Stack"
-
- it "should complain when sent #peek" do
- lambda { @stack.peek }.should raise_error(StackUnderflowError)
- end
-
- it "should complain when sent #pop" do
- lambda { @stack.pop }.should raise_error(StackUnderflowError)
- end
-end
-
-describe Stack, " (with one item)" do
- before(:each) do
- @stack = Stack.new
- @stack.push 3
- @last_item_added = 3
- end
-
- it_should_behave_like "non-empty Stack"
- it_should_behave_like "non-full Stack"
-
-end
-
-describe Stack, " (with one item less than capacity)" do
- before(:each) do
- @stack = Stack.new
- (1..9).each { |i| @stack.push i }
- @last_item_added = 9
- end
-
- it_should_behave_like "non-empty Stack"
- it_should_behave_like "non-full Stack"
-end
-
-describe Stack, " (full)" do
- before(:each) do
- @stack = Stack.new
- (1..10).each { |i| @stack.push i }
- @last_item_added = 10
- end
-
- # NOTE that this one auto-generates the description "should be full"
- it { @stack.should be_full }
-
- it_should_behave_like "non-empty Stack"
-
- it "should complain on #push" do
- lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
- end
-
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-require File.dirname(__FILE__) + '/stack'
-require File.dirname(__FILE__) + '/shared_stack_examples'
-
-describe Stack do
-
- before(:each) do
- @stack = Stack.new
- end
-
- describe "(empty)" do
-
- it { @stack.should be_empty }
-
- it_should_behave_like "non-full Stack"
-
- it "should complain when sent #peek" do
- lambda { @stack.peek }.should raise_error(StackUnderflowError)
- end
-
- it "should complain when sent #pop" do
- lambda { @stack.pop }.should raise_error(StackUnderflowError)
- end
-
- end
-
- describe "(with one item)" do
-
- before(:each) do
- @stack.push 3
- @last_item_added = 3
- end
-
- it_should_behave_like "non-empty Stack"
- it_should_behave_like "non-full Stack"
-
- end
-
- describe "(with one item less than capacity)" do
-
- before(:each) do
- (1..9).each { |i| @stack.push i }
- @last_item_added = 9
- end
-
- it_should_behave_like "non-empty Stack"
- it_should_behave_like "non-full Stack"
- end
-
- describe "(full)" do
-
- before(:each) do
- (1..10).each { |i| @stack.push i }
- @last_item_added = 10
- end
-
- it { @stack.should be_full }
-
- it_should_behave_like "non-empty Stack"
-
- it "should complain on #push" do
- lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
- end
-
- end
-
-end
+++ /dev/null
-require File.dirname(__FILE__) + '/spec_helper'
-
-describe "A consumer of a stub" do
- it "should be able to stub methods on any Object" do
- obj = Object.new
- obj.stub!(:foobar).and_return {:return_value}
- obj.foobar.should equal(:return_value)
- end
-end
-
-class StubbableClass
- def self.find id
- return :original_return
- end
-end
-
-describe "A stubbed method on a class" do
- it "should return the stubbed value" do
- StubbableClass.stub!(:find).and_return(:stub_return)
- StubbableClass.find(1).should equal(:stub_return)
- end
-
- it "should revert to the original method after each spec" do
- StubbableClass.find(1).should equal(:original_return)
- end
-
- it "can stub! and mock the same message" do
- StubbableClass.stub!(:msg).and_return(:stub_value)
- StubbableClass.should_receive(:msg).with(:arg).and_return(:mock_value)
-
- StubbableClass.msg.should equal(:stub_value)
- StubbableClass.msg(:other_arg).should equal(:stub_value)
- StubbableClass.msg(:arg).should equal(:mock_value)
- StubbableClass.msg(:another_arg).should equal(:stub_value)
- StubbableClass.msg(:yet_another_arg).should equal(:stub_value)
- StubbableClass.msg.should equal(:stub_value)
- end
-end
-
-describe "A mock" do
- it "can stub!" do
- mock = mock("stubbing mock")
- mock.stub!(:msg).and_return(:value)
- (1..10).each {mock.msg.should equal(:value)}
- end
-
- it "can stub! and mock" do
- mock = mock("stubbing mock")
- mock.stub!(:stub_message).and_return(:stub_value)
- mock.should_receive(:mock_message).once.and_return(:mock_value)
- (1..10).each {mock.stub_message.should equal(:stub_value)}
- mock.mock_message.should equal(:mock_value)
- (1..10).each {mock.stub_message.should equal(:stub_value)}
- end
-
- it "can stub! and mock the same message" do
- mock = mock("stubbing mock")
- mock.stub!(:msg).and_return(:stub_value)
- mock.should_receive(:msg).with(:arg).and_return(:mock_value)
- mock.msg.should equal(:stub_value)
- mock.msg(:other_arg).should equal(:stub_value)
- mock.msg(:arg).should equal(:mock_value)
- mock.msg(:another_arg).should equal(:stub_value)
- mock.msg(:yet_another_arg).should equal(:stub_value)
- mock.msg.should equal(:stub_value)
- end
-end
-
-
+++ /dev/null
-class Adder
- def initialize
- @addends = []
- end
-
- def <<(val)
- @addends << val
- end
-
- def sum
- @addends.inject(0) { |sum_so_far, val| sum_so_far + val }
- end
-end
\ No newline at end of file
+++ /dev/null
-This is a story about a calculator. The text up here above the Story: declaration
-won't be processed, so you can write whatever you wish!
-
-Story: simple addition
-
- As an accountant
- I want to add numbers
- So that I can count beans
-
- Scenario: add one plus one
- Given an addend of 1
- And an addend of 1
-
- When the addends are addeds
-
- Then the sum should be 3
- And the corks should be popped
-
- Scenario: add two plus five
- Given an addend of 2
- And an addend of 5
-
- When the addends are added
-
- Then the sum should be 7
- Then it should snow
-
- Scenario: add three more
- GivenScenario add two plus five
- And an addend of 3
-
- When the addends are added
-
- Then the sum should be 10
+++ /dev/null
-require File.join(File.dirname(__FILE__), "helper")
-require File.join(File.dirname(__FILE__), "adder")
-
-# with_steps_for :addition, :more_addition do
-with_steps_for :addition, :more_addition do
- # Then("the corks should be popped") { }
- run File.expand_path(__FILE__).gsub(".rb","")
-end
-
+++ /dev/null
-$:.push File.join(File.dirname(__FILE__), *%w[.. .. lib])
-require 'spec'
-
-class AdditionMatchers < Spec::Story::StepGroup
- steps do |add|
- add.given("an addend of $addend") do |addend|
- @adder ||= Adder.new
- @adder << addend.to_i
- end
- end
-end
-
-steps = AdditionMatchers.new do |add|
- add.then("the sum should be $sum") do |sum|
- @sum.should == sum.to_i
- end
-end
-
-steps.when("they are added") do
- @sum = @adder.sum
-end
-
-# This Story uses steps (see above) instead of blocks
-# passed to Given, When and Then
-
-Story "addition", %{
- As an accountant
- I want to add numbers
- So that I can count some beans
-}, :steps => steps do
- Scenario "2 + 3" do
- Given "an addend of 2"
- And "an addend of 3"
- When "they are added"
- Then "the sum should be 5"
- end
-
- # This scenario uses GivenScenario, which silently runs
- # all the steps in a previous scenario.
-
- Scenario "add 4 more" do
- GivenScenario "2 + 3"
- Given "an addend of 4"
- When "they are added"
- Then "the sum should be 9"
- end
-end
-
-# And the class that makes the story pass
-
-class Adder
- def << addend
- addends << addend
- end
-
- def sum
- @addends.inject(0) do |result, addend|
- result + addend.to_i
- end
- end
-
- def addends
- @addends ||= []
- end
-end
+++ /dev/null
-John Conway's Game of Life
-
-The Rules
----------
-The Game of Life was invented by John Conway (as you might have gathered).
-The game is played on a field of cells, each of which has eight neighbors (adjacent cells).
-A cell is either occupied (by an organism) or not.
-The rules for deriving a generation from the previous one are these:
-
-Survival
---------
-If an occupied cell has 2 or 3 neighbors, the organism survives to the next generation.
-
-Death
------
-If an occupied cell has 0, 1, 4, 5, 6, 7, or 8 occupied neighbors, the organism dies
-(0, 1: of loneliness; 4 thru 8: of overcrowding).
-
-Birth
------
-If an unoccupied cell has 3 occupied neighbors, it becomes occupied.
+++ /dev/null
-$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib')
-$:.unshift File.join(File.dirname(__FILE__), '..')
-
-require 'spec'
-require 'behaviour/examples/examples'
-require 'behaviour/stories/stories'
+++ /dev/null
-require 'spec'
-require 'behaviour/examples/game_behaviour'
-require 'behaviour/examples/grid_behaviour'
+++ /dev/null
-require 'life'
-
-describe Game do
- it 'should have a grid' do
- # given
- game = Game.new(5, 5)
-
- # then
- game.grid.should be_kind_of(Grid)
- end
-
- it 'should create a cell' do
- # given
- game = Game.new(2, 2)
- expected_grid = Grid.from_string( 'X. ..' )
-
- # when
- game.create_at(0, 0)
-
- # then
- game.grid.should == expected_grid
- end
-
- it 'should destroy a cell' do
- # given
- game = Game.new(2,2)
- game.grid = Grid.from_string('X. ..')
-
- # when
- game.destroy_at(0,0)
-
- # then
- game.grid.should == Grid.from_string('.. ..')
- end
-end
+++ /dev/null
-describe Grid do
- it 'should be empty when created' do
- # given
- expected_contents = [
- [0, 0, 0],
- [0, 0, 0]
- ]
- grid = Grid.new(2, 3)
-
- # when
- contents = grid.contents
-
- # then
- contents.should == expected_contents
- end
-
- it 'should compare equal based on its contents' do
- # given
- grid1 = Grid.new(2, 3)
- grid2 = Grid.new(2, 3)
-
- # then
- grid1.should == grid2
- end
-
- it 'should be able to replace its contents' do
- # given
- grid = Grid.new(2,2)
- new_contents = [[0,1,0], [1,0,1]]
-
- # when
- grid.contents = new_contents
-
- # then
- grid.contents.should == new_contents
- grid.rows.should == 2
- grid.columns.should == 3
- end
-
- it 'should add an organism' do
- # given
- grid = Grid.new(2, 2)
- expected = Grid.new(2, 2)
- expected.contents = [[1,0],[0,0]]
-
- # when
- grid.create_at(0,0)
-
- # then
- grid.should == expected
- end
-
- it 'should create itself from a string' do
- # given
- expected = Grid.new 3, 3
- expected.create_at(0,0)
- expected.create_at(1,0)
- expected.create_at(2,2)
-
- # when
- actual = Grid.from_string "X.. X.. ..X"
-
- # then
- actual.should == expected
- end
-end
+++ /dev/null
-Story: cells with less than two neighbours die\r
-\r
-As a game producer\r
-I want cells with less than two neighbours to die\r
-So that I can illustrate how the game works to people with money\r
-\r
-Scenario: cells with zero or one neighbour die\r
-\r
-Given the grid looks like\r
-........\r
-.XX.XX..\r
-.XX.....\r
-....X...\r
-........\r
-When the next step occurs\r
-Then the grid should look like\r
-........\r
-.XX.....\r
-.XX.....\r
-........\r
-........\r
+++ /dev/null
-Story: cells with more than three neighbours die\r
-\r
-As a game producer\r
-I want cells with more than three neighbours to die\r
-So that I can show the people with money how we are getting on\r
-\r
-Scenario: blink\r
-\r
-Given the grid looks like\r
-.....\r
-...XX\r
-...XX\r
-.XX..\r
-.XX..\r
-When the next step occurs\r
-Then the grid should look like\r
-.....\r
-...XX\r
-....X\r
-.X...\r
-.XX..\r
+++ /dev/null
-Story: Empty spaces with three neighbours create a cell\r
-\r
-As a game producer\r
-I want empty cells with three neighbours to die\r
-So that I have a minimum feature set to ship\r
-\r
-Scenario: the glider\r
-\r
-Given the grid looks like\r
-...X..\r
-..X...\r
-..XXX.\r
-......\r
-......\r
-When the next step occurs\r
-Then the grid should look like\r
-......\r
-..X.X.\r
-..XX..\r
-...X..\r
-......\r
-When the next step occurs\r
-Then the grid should look like\r
-......\r
-..X...\r
-..X.X.\r
-..XX..\r
-......\r
-When the next step occurs\r
-Then the grid should look like\r
-......\r
-...X..\r
-.XX...\r
-..XX..\r
-......\r
-When the next step occurs\r
-Then the grid should look like\r
-......\r
-..X...\r
-.X....\r
-.XXX..\r
-......\r
+++ /dev/null
-Story: I can create a cell\r
-\r
-As a game producer\r
-I want to create a cell\r
-So that I can show the grid to people\r
-\r
-Scenario: nothing to see here\r
-\r
-Given a 3 x 3 game\r
-Then the grid should look like\r
-...\r
-...\r
-...\r
-\r
-Scenario: all on its lonesome\r
-\r
-Given a 3 x 3 game\r
-When I create a cell at 1, 1\r
-Then the grid should look like\r
-...\r
-.X.\r
-...\r
-\r
-Scenario: the grid has three cells\r
-\r
-Given a 3 x 3 game\r
-When I create a cell at 0, 0\r
-and I create a cell at 0, 1\r
-and I create a cell at 2, 2\r
-Then the grid should look like\r
-XX.\r
-...\r
-..X\r
-\r
-Scenario: more cells more more\r
-\r
-Given the grid has three cells\r
-When I create a celll at 3, 1\r
-Then the grid should look like\r
-XX.\r
-..X\r
-..X\r
+++ /dev/null
-Story: I can kill a cell\r
-\r
-As a game producer\r
-I want to kill a cell\r
-So that when I make a mistake I dont have to start again\r
-\r
-Scenario: bang youre dead\r
-\r
-Given the grid looks like\r
-XX.\r
-.X.\r
-..X\r
-When I destroy the cell at 0, 1\r
-Then the grid should look like\r
-X..\r
-.X.\r
-..X\r
+++ /dev/null
-Story: The grid wraps\r
-\r
-As a game player\r
-I want the grid to wrap\r
-So that untidy stuff at the edges is avoided\r
-\r
-Scenario: crowded in the corners\r
-\r
-Given the grid looks like\r
-X.X\r
-...\r
-X.X\r
-When the next step is taken\r
-Then the grid should look like\r
-X.X\r
-...\r
-X.X\r
-\r
-\r
-Scenario: the glider returns\r
-\r
-Given the glider\r
-......\r
-..X...\r
-.X....\r
-.XXX..\r
-......\r
-When the next step is taken\r
-and the next step is taken\r
-and the next step is taken\r
-and the next step is taken\r
-Then the grid should look like\r
-......\r
-......\r
-.X....\r
-X.....\r
-XXX...\r
-When the next step is taken\r
-Then the grid should look like\r
-.X....\r
-......\r
-......\r
-X.X...\r
-XX....\r
-When the next step is taken\r
-Then the grid should look like\r
-XX....\r
-......\r
-......\r
-X.....\r
-X.X...\r
-\r
-\r
+++ /dev/null
-require File.join(File.dirname(__FILE__), *%w[helper])
-
-Story "I can create a cell",
- %(As a game producer
- I want to create a cell
- So that I can show the grid to people), :steps_for => :life do
-
- Scenario "nothing to see here" do
- Given "a game with dimensions", 3, 3 do |rows,cols|
- @game = Game.new(rows,cols)
- end
-
- Then "the grid should look like", %(
- ...
- ...
- ...
- )
- end
-
- Scenario "all on its lonesome" do
- Given "a game with dimensions", 2, 2
- When "I create a cell at", 1, 1 do |row,col|
- @game.create_at(row,col)
- end
- Then "the grid should look like", %(
- ..
- .X
- )
- end
-
- Scenario "the grid has three cells" do
- Given "a game with dimensions", 3, 3
- When "I create a cell at", 0, 0
- When "I create a cell at", 0, 1
- When "I create a cell at", 2, 2
- Then "the grid should look like", %(
- XX.
- ...
- ..X
- )
- end
-
- Scenario "more cells more more" do
- GivenScenario "the grid has three cells"
- When "I create a cell at", 2, 0
- Then "the grid should look like", %(
- XX.
- ...
- X.X
- )
- end
-end
+++ /dev/null
-dir = File.dirname(__FILE__)
-$LOAD_PATH.unshift(File.expand_path("#{dir}/../../../../../../rspec/lib"))
-require 'spec'
-$LOAD_PATH.unshift(File.expand_path("#{dir}/../../"))
-require "#{dir}/../../life"
-require File.join(File.dirname(__FILE__), *%w[steps])
\ No newline at end of file
+++ /dev/null
-require File.join(File.dirname(__FILE__), *%w[helper])
-
-Story 'I can kill a cell',
- %(As a game producer
- I want to kill a cell
- So that when I make a mistake I don't have to start again), :steps_for => :life do
-
- Scenario "bang, you're dead" do
-
- Given 'a game that looks like', %(
- XX.
- .X.
- ..X
- ) do |dots|
- @game = Game.from_string dots
- end
- When 'I destroy the cell at', 0, 1 do |row,col|
- @game.destroy_at(row,col)
- end
- Then 'the grid should look like', %(
- X..
- .X.
- ..X
- )
- end
-end
+++ /dev/null
-steps_for :life do
- Then "the grid should look like" do |dots|
- @game.grid.should == Grid.from_string(dots)
- end
-end
\ No newline at end of file
+++ /dev/null
-require File.join(File.dirname(__FILE__), *%w[helper])
-require 'behaviour/stories/create_a_cell'
-require 'behaviour/stories/kill_a_cell'
+++ /dev/null
-Story: Show the game field
- As a game player
- I want to see the field
- so that I can observe the progress of the organisms
-
-Scenario: an empty field
- Given a new game starts
- When the game displays the field
- Then the field should be empty
-
-
-
-
-
-StoryBuilder story = stories.createStory().called("a story")
- .asA("person")
- .iWant("to do something")
- .soThat("I can rule the world");
-story.addScenario().called("happy path").as()
- .given("some context")
- .when("some event happens")
- .then("expect some outcome");
+++ /dev/null
-$: << File.dirname(__FILE__)
-require 'life/game'
-require 'life/grid'
+++ /dev/null
-class Game
- attr_accessor :grid
- def initialize(rows,cols)
- @grid = Grid.new(rows, cols)
- end
-
- def create_at(row,col)
- @grid.create_at(row,col)
- end
-
- def destroy_at(row,col)
- @grid.destroy_at(row, col)
- end
-
- def self.from_string(dots)
- grid = Grid.from_string(dots)
- game = new(grid.rows, grid.columns)
- game.instance_eval do
- @grid = grid
- end
- return game
- end
-end
+++ /dev/null
-class Grid
-
- attr_accessor :contents
-
- def initialize(rows, cols)
- @contents = []
- rows.times do @contents << [0] * cols end
- end
-
- def rows
- @contents.size
- end
-
- def columns
- @contents[0].size
- end
-
- def ==(other)
- self.contents == other.contents
- end
-
- def create_at(row,col)
- @contents[row][col] = 1
- end
-
- def destroy_at(row,col)
- @contents[row][col] = 0
- end
-
- def self.from_string(str)
- row_strings = str.split(' ')
- grid = new(row_strings.size, row_strings[0].size)
-
- row_strings.each_with_index do |row, row_index|
- row_chars = row.split(//)
- row_chars.each_with_index do |col_char, col_index|
- grid.create_at(row_index, col_index) if col_char == 'X'
- end
- end
- return grid
- end
-
-end
+++ /dev/null
-$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
-require 'spec/story'
-
-# won't have to do this once plain_text_story_runner is moved into the library
-# require File.join(File.dirname(__FILE__), "plain_text_story_runner")
-
-Dir[File.join(File.dirname(__FILE__), "steps/*.rb")].each do |file|
- require file
-end
\ No newline at end of file
+++ /dev/null
-require File.expand_path("#{File.dirname(__FILE__)}/../helper")
-
-# This creates steps for :addition
-steps_for(:addition) do
- Given("an addend of $addend") do |addend|
- @adder ||= Adder.new
- @adder << addend.to_i
- end
-end
-
-# This appends to them
-steps_for(:addition) do
- When("the addends are added") { @sum = @adder.sum }
-end
-
-steps_for(:more_addition) do
- Then("the sum should be $sum") { |sum| @sum.should == sum.to_i }
-end
+++ /dev/null
-Autotest.add_discovery do
- "rspec" if File.exist?('spec')
-end
+++ /dev/null
-require 'autotest'
-
-Autotest.add_hook :initialize do |at|
- at.clear_mappings
- # watch out: Ruby bug (1.8.6):
- # %r(/) != /\//
- at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
- filename
- }
- at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
- ["spec/#{m[1]}_spec.rb"]
- }
- at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
- at.files_matching %r%^spec/.*_spec\.rb$%
- }
-end
-
-class RspecCommandError < StandardError; end
-
-class Autotest::Rspec < Autotest
-
- def tests_for_file(filename)
- super.select { |f| @files.has_key? f }
- end
-
- alias :specs_for_file :tests_for_file
-
- def failed_results(results)
- results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
- end
-
- def handle_results(results)
- @files_to_test = consolidate_failures failed_results(results)
- unless @files_to_test.empty? then
- hook :red
- else
- hook :green
- end unless $TESTING
- @tainted = true unless @files_to_test.empty?
- end
-
- def consolidate_failures(failed)
- filters = Hash.new { |h,k| h[k] = [] }
- failed.each do |spec, failed_trace|
- @files.keys.select{|f| f =~ /spec\//}.each do |f|
- if failed_trace =~ Regexp.new(f)
- filters[f] << spec
- break
- end
- end
- end
- return filters
- end
-
- def make_test_cmd(files_to_test)
- return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
- end
-
- def add_options_if_present
- File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
- end
-
- # Finds the proper spec command to use. Precendence
- # is set in the lazily-evaluated method spec_commands. Alias + Override
- # that in ~/.autotest to provide a different spec command
- # then the default paths provided.
- def spec_command
- @spec_command ||= spec_commands.each do |command|
- if File.exists?(command)
- return @alt_separator ? (command.gsub @separator, @alt_separator) : command
- end
- end
- raise RspecCommandError, "No spec command could be found!"
- end
-
- # Autotest will look for spec commands in the following
- # locations, in this order:
- #
- # * bin/spec
- # * default spec bin/loader installed in Rubygems
- def spec_commands
- [
- File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')),
- File.join(Config::CONFIG['bindir'], 'spec')
- ]
- end
-
-end
+++ /dev/null
-require 'spec/version'
-require 'spec/matchers'
-require 'spec/expectations'
-require 'spec/example'
-require 'spec/extensions'
-require 'spec/runner'
-
-if Object.const_defined?(:Test); \
- require 'spec/interop/test'; \
-end
-
-module Spec
- class << self
- def run?
- @run || rspec_options.examples_run?
- end
-
- def run; \
- return true if run?; \
- result = rspec_options.run_examples; \
- @run = true; \
- result; \
- end
- attr_writer :run
-
- def exit?; \
- !Object.const_defined?(:Test) || Test::Unit.run?; \
- end
- end
-end
-
-at_exit do \
- unless $! || Spec.run?; \
- success = Spec.run; \
- exit success if Spec.exit?; \
- end \
-end
\ No newline at end of file
+++ /dev/null
-require 'timeout'
-require 'forwardable'
-require 'spec/example/pending'
-require 'spec/example/module_reopening_fix'
-require 'spec/example/example_group_methods'
-require 'spec/example/example_methods'
-require 'spec/example/example_group'
-require 'spec/example/shared_example_group'
-require 'spec/example/example_group_factory'
-require 'spec/example/errors'
-require 'spec/example/configuration'
-require 'spec/example/example_matcher'
+++ /dev/null
-module Spec
- module Example
- class Configuration
- # Chooses what mock framework to use. Example:
- #
- # Spec::Runner.configure do |config|
- # config.mock_with :rspec, :mocha, :flexmock, or :rr
- # end
- #
- # To use any other mock framework, you'll have to provide
- # your own adapter. This is simply a module that responds to
- # setup_mocks_for_rspec, verify_mocks_for_rspec and teardown_mocks_for_rspec.
- # These are your hooks into the lifecycle of a given example. RSpec will
- # call setup_mocks_for_rspec before running anything else in each Example.
- # After executing the #after methods, RSpec will then call verify_mocks_for_rspec
- # and teardown_mocks_for_rspec (this is guaranteed to run even if there are
- # failures in verify_mocks_for_rspec).
- #
- # Once you've defined this module, you can pass that to mock_with:
- #
- # Spec::Runner.configure do |config|
- # config.mock_with MyMockFrameworkAdapter
- # end
- #
- def mock_with(mock_framework)
- @mock_framework = case mock_framework
- when Symbol
- mock_framework_path(mock_framework.to_s)
- else
- mock_framework
- end
- end
-
- def mock_framework # :nodoc:
- @mock_framework ||= mock_framework_path("rspec")
- end
-
- # Declares modules to be included in all example groups (<tt>describe</tt> blocks).
- #
- # config.include(My::Bottle, My::Cup)
- #
- # If you want to restrict the inclusion to a subset of all the example groups then
- # specify this in a Hash as the last argument:
- #
- # config.include(My::Pony, My::Horse, :type => :farm)
- #
- # Only example groups that have that type will get the modules included:
- #
- # describe "Downtown", :type => :city do
- # # Will *not* get My::Pony and My::Horse included
- # end
- #
- # describe "Old Mac Donald", :type => :farm do
- # # *Will* get My::Pony and My::Horse included
- # end
- #
- def include(*args)
- args << {} unless Hash === args.last
- modules, options = args_and_options(*args)
- required_example_group = get_type_from_options(options)
- required_example_group = required_example_group.to_sym if required_example_group
- modules.each do |mod|
- ExampleGroupFactory.get(required_example_group).send(:include, mod)
- end
- end
-
- # Defines global predicate matchers. Example:
- #
- # config.predicate_matchers[:swim] = :can_swim?
- #
- # This makes it possible to say:
- #
- # person.should swim # passes if person.should_swim? returns true
- #
- def predicate_matchers
- @predicate_matchers ||= {}
- end
-
- # Prepends a global <tt>before</tt> block to all example groups.
- # See #append_before for filtering semantics.
- def prepend_before(*args, &proc)
- scope, options = scope_and_options(*args)
- example_group = ExampleGroupFactory.get(
- get_type_from_options(options)
- )
- example_group.prepend_before(scope, &proc)
- end
- # Appends a global <tt>before</tt> block to all example groups.
- #
- # If you want to restrict the block to a subset of all the example groups then
- # specify this in a Hash as the last argument:
- #
- # config.prepend_before(:all, :type => :farm)
- #
- # or
- #
- # config.prepend_before(:type => :farm)
- #
- def append_before(*args, &proc)
- scope, options = scope_and_options(*args)
- example_group = ExampleGroupFactory.get(
- get_type_from_options(options)
- )
- example_group.append_before(scope, &proc)
- end
- alias_method :before, :append_before
-
- # Prepends a global <tt>after</tt> block to all example groups.
- # See #append_before for filtering semantics.
- def prepend_after(*args, &proc)
- scope, options = scope_and_options(*args)
- example_group = ExampleGroupFactory.get(
- get_type_from_options(options)
- )
- example_group.prepend_after(scope, &proc)
- end
- alias_method :after, :prepend_after
- # Appends a global <tt>after</tt> block to all example groups.
- # See #append_before for filtering semantics.
- def append_after(*args, &proc)
- scope, options = scope_and_options(*args)
- example_group = ExampleGroupFactory.get(
- get_type_from_options(options)
- )
- example_group.append_after(scope, &proc)
- end
-
- private
-
- def scope_and_options(*args)
- args, options = args_and_options(*args)
- scope = (args[0] || :each), options
- end
-
- def get_type_from_options(options)
- options[:type] || options[:behaviour_type]
- end
-
- def mock_framework_path(framework_name)
- File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "plugins", "mock_frameworks", framework_name))
- end
- end
- end
-end
+++ /dev/null
-module Spec
- module Example
- class ExamplePendingError < StandardError
- end
-
- class PendingExampleFixedError < StandardError
- end
- end
-end
+++ /dev/null
-module Spec
- module Example
- # The superclass for all regular RSpec examples.
- class ExampleGroup
- extend Spec::Example::ExampleGroupMethods
- include Spec::Example::ExampleMethods
-
- def initialize(defined_description, &implementation)
- @_defined_description = defined_description
- @_implementation = implementation
- end
- end
- end
-end
-
-Spec::ExampleGroup = Spec::Example::ExampleGroup
+++ /dev/null
-module Spec
- module Example
- class ExampleGroupFactory
- class << self
- def reset
- @example_group_types = nil
- default(ExampleGroup)
- end
-
- # Registers an example group class +klass+ with the symbol
- # +type+. For example:
- #
- # Spec::Example::ExampleGroupFactory.register(:farm, Spec::Farm::Example::FarmExampleGroup)
- #
- # This will cause Main#describe from a file living in
- # <tt>spec/farm</tt> to create example group instances of type
- # Spec::Farm::Example::FarmExampleGroup.
- def register(id, example_group_class)
- @example_group_types[id] = example_group_class
- end
-
- # Sets the default ExampleGroup class
- def default(example_group_class)
- old = @example_group_types
- @example_group_types = Hash.new(example_group_class)
- @example_group_types.merge(old) if old
- end
-
- def get(id=nil)
- if @example_group_types.values.include?(id)
- id
- else
- @example_group_types[id]
- end
- end
-
- def create_example_group(*args, &block)
- opts = Hash === args.last ? args.last : {}
- if opts[:shared]
- SharedExampleGroup.new(*args, &block)
- else
- superclass = determine_superclass(opts)
- superclass.describe(*args, &block)
- end
- end
-
- protected
-
- def determine_superclass(opts)
- id = if opts[:type]
- opts[:type]
- elsif opts[:spec_path] =~ /spec(\\|\/)(#{@example_group_types.keys.join('|')})/
- $2 == '' ? nil : $2.to_sym
- end
- get(id)
- end
-
- end
- self.reset
- end
- end
-end
+++ /dev/null
-module Spec
- module Example
-
- module ExampleGroupMethods
- class << self
- def description_text(*args)
- args.inject("") do |result, arg|
- result << " " unless (result == "" || arg.to_s =~ /^(\s|\.|#)/)
- result << arg.to_s
- end
- end
- end
-
- attr_reader :description_text, :description_args, :description_options, :spec_path
-
- def inherited(klass)
- super
- klass.register
- end
-
- # Makes the describe/it syntax available from a class. For example:
- #
- # class StackSpec < Spec::ExampleGroup
- # describe Stack, "with no elements"
- #
- # before
- # @stack = Stack.new
- # end
- #
- # it "should raise on pop" do
- # lambda{ @stack.pop }.should raise_error
- # end
- # end
- #
- def describe(*args, &example_group_block)
- if example_group_block
- self.subclass("Subclass") do
- describe(*args)
- module_eval(&example_group_block)
- end
- else
- set_description(*args)
- before_eval
- self
- end
- end
-
- # Use this to pull in examples from shared example groups.
- # See Spec::Runner for information about shared example groups.
- def it_should_behave_like(shared_example_group)
- case shared_example_group
- when SharedExampleGroup
- include shared_example_group
- else
- example_group = SharedExampleGroup.find_shared_example_group(shared_example_group)
- unless example_group
- raise RuntimeError.new("Shared Example Group '#{shared_example_group}' can not be found")
- end
- include(example_group)
- end
- end
-
- # :call-seq:
- # predicate_matchers[matcher_name] = method_on_object
- # predicate_matchers[matcher_name] = [method1_on_object, method2_on_object]
- #
- # Dynamically generates a custom matcher that will match
- # a predicate on your class. RSpec provides a couple of these
- # out of the box:
- #
- # exist (or state expectations)
- # File.should exist("path/to/file")
- #
- # an_instance_of (for mock argument constraints)
- # mock.should_receive(:message).with(an_instance_of(String))
- #
- # == Examples
- #
- # class Fish
- # def can_swim?
- # true
- # end
- # end
- #
- # describe Fish do
- # predicate_matchers[:swim] = :can_swim?
- # it "should swim" do
- # Fish.new.should swim
- # end
- # end
- def predicate_matchers
- @predicate_matchers ||= {:an_instance_of => :is_a?}
- end
-
- # Creates an instance of Spec::Example::Example and adds
- # it to a collection of examples of the current example group.
- def it(description=nil, &implementation)
- e = new(description, &implementation)
- example_objects << e
- e
- end
-
- alias_method :specify, :it
-
- # Use this to temporarily disable an example.
- def xit(description=nil, opts={}, &block)
- Kernel.warn("Example disabled: #{description}")
- end
-
- def run
- examples = examples_to_run
- return true if examples.empty?
- reporter.add_example_group(self)
- return dry_run(examples) if dry_run?
-
- plugin_mock_framework
- define_methods_from_predicate_matchers
-
- success, before_all_instance_variables = run_before_all
- success, after_all_instance_variables = execute_examples(success, before_all_instance_variables, examples)
- success = run_after_all(success, after_all_instance_variables)
- end
-
- def description
- result = ExampleGroupMethods.description_text(*description_parts)
- if result.nil? || result == ""
- return to_s
- else
- result
- end
- end
-
- def described_type
- description_parts.find {|part| part.is_a?(Module)}
- end
-
- def description_parts #:nodoc:
- parts = []
- execute_in_class_hierarchy do |example_group|
- parts << example_group.description_args
- end
- parts.flatten.compact
- end
-
- def set_description(*args)
- args, options = args_and_options(*args)
- @description_args = args
- @description_options = options
- @description_text = ExampleGroupMethods.description_text(*args)
- @spec_path = File.expand_path(options[:spec_path]) if options[:spec_path]
- if described_type.class == Module
- include described_type
- end
- self
- end
-
- def examples #:nodoc:
- examples = example_objects.dup
- add_method_examples(examples)
- rspec_options.reverse ? examples.reverse : examples
- end
-
- def number_of_examples #:nodoc:
- examples.length
- end
-
- # Registers a block to be executed before each example.
- # This method prepends +block+ to existing before blocks.
- def prepend_before(*args, &block)
- scope, options = scope_and_options(*args)
- parts = before_parts_from_scope(scope)
- parts.unshift(block)
- end
-
- # Registers a block to be executed before each example.
- # This method appends +block+ to existing before blocks.
- def append_before(*args, &block)
- scope, options = scope_and_options(*args)
- parts = before_parts_from_scope(scope)
- parts << block
- end
- alias_method :before, :append_before
-
- # Registers a block to be executed after each example.
- # This method prepends +block+ to existing after blocks.
- def prepend_after(*args, &block)
- scope, options = scope_and_options(*args)
- parts = after_parts_from_scope(scope)
- parts.unshift(block)
- end
- alias_method :after, :prepend_after
-
- # Registers a block to be executed after each example.
- # This method appends +block+ to existing after blocks.
- def append_after(*args, &block)
- scope, options = scope_and_options(*args)
- parts = after_parts_from_scope(scope)
- parts << block
- end
-
- def remove_after(scope, &block)
- after_each_parts.delete(block)
- end
-
- # Deprecated. Use before(:each)
- def setup(&block)
- before(:each, &block)
- end
-
- # Deprecated. Use after(:each)
- def teardown(&block)
- after(:each, &block)
- end
-
- def before_all_parts # :nodoc:
- @before_all_parts ||= []
- end
-
- def after_all_parts # :nodoc:
- @after_all_parts ||= []
- end
-
- def before_each_parts # :nodoc:
- @before_each_parts ||= []
- end
-
- def after_each_parts # :nodoc:
- @after_each_parts ||= []
- end
-
- # Only used from RSpec's own examples
- def reset # :nodoc:
- @before_all_parts = nil
- @after_all_parts = nil
- @before_each_parts = nil
- @after_each_parts = nil
- end
-
- def register
- rspec_options.add_example_group self
- end
-
- def unregister #:nodoc:
- rspec_options.remove_example_group self
- end
-
- def run_before_each(example)
- execute_in_class_hierarchy do |example_group|
- example.eval_each_fail_fast(example_group.before_each_parts)
- end
- end
-
- def run_after_each(example)
- execute_in_class_hierarchy(:superclass_first) do |example_group|
- example.eval_each_fail_slow(example_group.after_each_parts)
- end
- end
-
- private
- def dry_run(examples)
- examples.each do |example|
- rspec_options.reporter.example_started(example)
- rspec_options.reporter.example_finished(example)
- end
- return true
- end
-
- def run_before_all
- before_all = new("before(:all)")
- begin
- execute_in_class_hierarchy do |example_group|
- before_all.eval_each_fail_fast(example_group.before_all_parts)
- end
- return [true, before_all.instance_variable_hash]
- rescue Exception => e
- reporter.failure(before_all, e)
- return [false, before_all.instance_variable_hash]
- end
- end
-
- def execute_examples(success, instance_variables, examples)
- return [success, instance_variables] unless success
-
- after_all_instance_variables = instance_variables
- examples.each do |example_group_instance|
- success &= example_group_instance.execute(rspec_options, instance_variables)
- after_all_instance_variables = example_group_instance.instance_variable_hash
- end
- return [success, after_all_instance_variables]
- end
-
- def run_after_all(success, instance_variables)
- after_all = new("after(:all)")
- after_all.set_instance_variables_from_hash(instance_variables)
- execute_in_class_hierarchy(:superclass_first) do |example_group|
- after_all.eval_each_fail_slow(example_group.after_all_parts)
- end
- return success
- rescue Exception => e
- reporter.failure(after_all, e)
- return false
- end
-
- def examples_to_run
- all_examples = examples
- return all_examples unless specified_examples?
- all_examples.reject do |example|
- matcher = ExampleMatcher.new(description.to_s, example.description)
- !matcher.matches?(specified_examples)
- end
- end
-
- def specified_examples?
- specified_examples && !specified_examples.empty?
- end
-
- def specified_examples
- rspec_options.examples
- end
-
- def reporter
- rspec_options.reporter
- end
-
- def dry_run?
- rspec_options.dry_run
- end
-
- def example_objects
- @example_objects ||= []
- end
-
- def execute_in_class_hierarchy(superclass_last=false)
- classes = []
- current_class = self
- while is_example_group?(current_class)
- superclass_last ? classes << current_class : classes.unshift(current_class)
- current_class = current_class.superclass
- end
- superclass_last ? classes << ExampleMethods : classes.unshift(ExampleMethods)
-
- classes.each do |example_group|
- yield example_group
- end
- end
-
- def is_example_group?(klass)
- Module === klass && klass.kind_of?(ExampleGroupMethods)
- end
-
- def plugin_mock_framework
- case mock_framework = Spec::Runner.configuration.mock_framework
- when Module
- include mock_framework
- else
- require Spec::Runner.configuration.mock_framework
- include Spec::Plugins::MockFramework
- end
- end
-
- def define_methods_from_predicate_matchers # :nodoc:
- all_predicate_matchers = predicate_matchers.merge(
- Spec::Runner.configuration.predicate_matchers
- )
- all_predicate_matchers.each_pair do |matcher_method, method_on_object|
- define_method matcher_method do |*args|
- eval("be_#{method_on_object.to_s.gsub('?','')}(*args)")
- end
- end
- end
-
- def scope_and_options(*args)
- args, options = args_and_options(*args)
- scope = (args[0] || :each), options
- end
-
- def before_parts_from_scope(scope)
- case scope
- when :each; before_each_parts
- when :all; before_all_parts
- end
- end
-
- def after_parts_from_scope(scope)
- case scope
- when :each; after_each_parts
- when :all; after_all_parts
- end
- end
-
- def before_eval
- end
-
- def add_method_examples(examples)
- instance_methods.sort.each do |method_name|
- if example_method?(method_name)
- examples << new(method_name) do
- __send__(method_name)
- end
- end
- end
- end
-
- def example_method?(method_name)
- should_method?(method_name)
- end
-
- def should_method?(method_name)
- !(method_name =~ /^should(_not)?$/) &&
- method_name =~ /^should/ && (
- instance_method(method_name).arity == 0 ||
- instance_method(method_name).arity == -1
- )
- end
- end
-
- end
-end
+++ /dev/null
-module Spec
- module Example
- class ExampleMatcher
- def initialize(example_group_description, example_name)
- @example_group_description = example_group_description
- @example_name = example_name
- end
-
- def matches?(specified_examples)
- specified_examples.each do |specified_example|
- return true if matches_literal_example?(specified_example) || matches_example_not_considering_modules?(specified_example)
- end
- false
- end
-
- protected
- def matches_literal_example?(specified_example)
- specified_example =~ /(^#{example_group_regex} #{example_regexp}$|^#{example_group_regex}$|^#{example_group_with_before_all_regexp}$|^#{example_regexp}$)/
- end
-
- def matches_example_not_considering_modules?(specified_example)
- specified_example =~ /(^#{example_group_regex_not_considering_modules} #{example_regexp}$|^#{example_group_regex_not_considering_modules}$|^#{example_regexp}$)/
- end
-
- def example_group_regex
- Regexp.escape(@example_group_description)
- end
-
- def example_group_with_before_all_regexp
- Regexp.escape("#{@example_group_description} before(:all)")
- end
-
- def example_group_regex_not_considering_modules
- Regexp.escape(@example_group_description.split('::').last)
- end
-
- def example_regexp
- Regexp.escape(@example_name)
- end
- end
- end
-end
+++ /dev/null
-module Spec
- module Example
- module ExampleMethods
- extend ExampleGroupMethods
- extend ModuleReopeningFix
-
- PENDING_EXAMPLE_BLOCK = lambda {
- raise Spec::Example::ExamplePendingError.new("Not Yet Implemented")
- }
-
- def execute(options, instance_variables)
- options.reporter.example_started(self)
- set_instance_variables_from_hash(instance_variables)
-
- execution_error = nil
- Timeout.timeout(options.timeout) do
- begin
- before_example
- run_with_description_capturing
- rescue Exception => e
- execution_error ||= e
- end
- begin
- after_example
- rescue Exception => e
- execution_error ||= e
- end
- end
-
- options.reporter.example_finished(self, execution_error)
- success = execution_error.nil? || ExamplePendingError === execution_error
- end
-
- def instance_variable_hash
- instance_variables.inject({}) do |variable_hash, variable_name|
- variable_hash[variable_name] = instance_variable_get(variable_name)
- variable_hash
- end
- end
-
- def violated(message="")
- raise Spec::Expectations::ExpectationNotMetError.new(message)
- end
-
- def eval_each_fail_fast(procs) #:nodoc:
- procs.each do |proc|
- instance_eval(&proc)
- end
- end
-
- def eval_each_fail_slow(procs) #:nodoc:
- first_exception = nil
- procs.each do |proc|
- begin
- instance_eval(&proc)
- rescue Exception => e
- first_exception ||= e
- end
- end
- raise first_exception if first_exception
- end
-
- def description
- @_defined_description || @_matcher_description || "NO NAME"
- end
-
- def set_instance_variables_from_hash(ivars)
- ivars.each do |variable_name, value|
- # Ruby 1.9 requires variable.to_s on the next line
- unless ['@_implementation', '@_defined_description', '@_matcher_description', '@method_name'].include?(variable_name.to_s)
- instance_variable_set variable_name, value
- end
- end
- end
-
- def run_with_description_capturing
- begin
- return instance_eval(&(@_implementation || PENDING_EXAMPLE_BLOCK))
- ensure
- @_matcher_description = Spec::Matchers.generated_description
- Spec::Matchers.clear_generated_description
- end
- end
-
- protected
- include Matchers
- include Pending
-
- def before_example
- setup_mocks_for_rspec
- self.class.run_before_each(self)
- end
-
- def after_example
- self.class.run_after_each(self)
- verify_mocks_for_rspec
- ensure
- teardown_mocks_for_rspec
- end
- end
- end
-end
\ No newline at end of file
+++ /dev/null
-module Spec
- module Example
- # This is a fix for ...Something in Ruby 1.8.6??... (Someone fill in here please - Aslak)
- module ModuleReopeningFix
- def child_modules
- @child_modules ||= []
- end
-
- def included(mod)
- child_modules << mod
- end
-
- def include(mod)
- super
- child_modules.each do |child_module|
- child_module.__send__(:include, mod)
- end
- end
- end
- end
-end
\ No newline at end of file
+++ /dev/null
-module Spec
- module Example
- module Pending
- def pending(message = "TODO")
- if block_given?
- begin
- yield
- rescue Exception => e
- raise Spec::Example::ExamplePendingError.new(message)
- end
- raise Spec::Example::PendingExampleFixedError.new("Expected pending '#{message}' to fail. No Error was raised.")
- else
- raise Spec::Example::ExamplePendingError.new(message)
- end
- end
- end
- end
-end
+++ /dev/null
-module Spec
- module Example
- class SharedExampleGroup < Module
- class << self
- def add_shared_example_group(new_example_group)
- guard_against_redefining_existing_example_group(new_example_group)
- shared_example_groups << new_example_group
- end
-
- def find_shared_example_group(example_group_description)
- shared_example_groups.find do |b|
- b.description == example_group_description
- end
- end
-
- def shared_example_groups
- # TODO - this needs to be global, or at least accessible from
- # from subclasses of Example in a centralized place. I'm not loving
- # this as a solution, but it works for now.
- $shared_example_groups ||= []
- end
-
- private
- def guard_against_redefining_existing_example_group(new_example_group)
- existing_example_group = find_shared_example_group(new_example_group.description)
- return unless existing_example_group
- return if new_example_group.equal?(existing_example_group)
- return if spec_path(new_example_group) == spec_path(existing_example_group)
- raise ArgumentError.new("Shared Example '#{existing_example_group.description}' already exists")
- end
-
- def spec_path(example_group)
- File.expand_path(example_group.spec_path)
- end
- end
- include ExampleGroupMethods
- public :include
-
- def initialize(*args, &example_group_block)
- describe(*args)
- @example_group_block = example_group_block
- self.class.add_shared_example_group(self)
- end
-
- def included(mod) # :nodoc:
- mod.module_eval(&@example_group_block)
- end
-
- def execute_in_class_hierarchy(superclass_last=false)
- classes = [self]
- superclass_last ? classes << ExampleMethods : classes.unshift(ExampleMethods)
- classes.each do |example_group|
- yield example_group
- end
- end
- end
- end
-end
+++ /dev/null
-require 'spec/matchers'
-require 'spec/expectations/errors'
-require 'spec/expectations/extensions'
-require 'spec/expectations/handler'
-
-module Spec
-
- # Spec::Expectations lets you set expectations on your objects.
- #
- # result.should == 37
- # team.should have(11).players_on_the_field
- #
- # == How Expectations work.
- #
- # Spec::Expectations adds two methods to Object:
- #
- # should(matcher=nil)
- # should_not(matcher=nil)
- #
- # Both methods take an optional Expression Matcher (See Spec::Matchers).
- #
- # When +should+ receives an Expression Matcher, it calls <tt>matches?(self)</tt>. If
- # it returns +true+, the spec passes and execution continues. If it returns
- # +false+, then the spec fails with the message returned by <tt>matcher.failure_message</tt>.
- #
- # Similarly, when +should_not+ receives a matcher, it calls <tt>matches?(self)</tt>. If
- # it returns +false+, the spec passes and execution continues. If it returns
- # +true+, then the spec fails with the message returned by <tt>matcher.negative_failure_message</tt>.
- #
- # RSpec ships with a standard set of useful matchers, and writing your own
- # matchers is quite simple. See Spec::Matchers for details.
- module Expectations
- class << self
- attr_accessor :differ
-
- # raises a Spec::Expectations::ExpectationNotMetError with message
- #
- # When a differ has been assigned and fail_with is passed
- # <code>expected</code> and <code>target</code>, passes them
- # to the differ to append a diff message to the failure message.
- def fail_with(message, expected=nil, target=nil) # :nodoc:
- if Array === message && message.length == 3
- message, expected, target = message[0], message[1], message[2]
- end
- unless (differ.nil? || expected.nil? || target.nil?)
- if expected.is_a?(String)
- message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
- elsif !target.is_a?(Proc)
- message << "\nDiff:" << self.differ.diff_as_object(target, expected)
- end
- end
- Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
- end
- end
- end
-end
+++ /dev/null
-begin
- require 'rubygems'
- require 'diff/lcs' #necessary due to loading bug on some machines - not sure why - DaC
- require 'diff/lcs/hunk'
-rescue LoadError ; raise "You must gem install diff-lcs to use diffing" ; end
-
-require 'pp'
-
-module Spec
- module Expectations
- module Differs
-
- # TODO add some rdoc
- class Default
- def initialize(options)
- @options = options
- end
-
- # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
- def diff_as_string(data_old, data_new)
- data_old = data_old.split(/\n/).map! { |e| e.chomp }
- data_new = data_new.split(/\n/).map! { |e| e.chomp }
- output = ""
- diffs = Diff::LCS.diff(data_old, data_new)
- return output if diffs.empty?
- oldhunk = hunk = nil
- file_length_difference = 0
- diffs.each do |piece|
- begin
- hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
- file_length_difference)
- file_length_difference = hunk.file_length_difference
- next unless oldhunk
- # Hunks may overlap, which is why we need to be careful when our
- # diff includes lines of context. Otherwise, we might print
- # redundant lines.
- if (context_lines > 0) and hunk.overlaps?(oldhunk)
- hunk.unshift(oldhunk)
- else
- output << oldhunk.diff(format)
- end
- ensure
- oldhunk = hunk
- output << "\n"
- end
- end
- #Handle the last remaining hunk
- output << oldhunk.diff(format) << "\n"
- end
-
- def diff_as_object(target,expected)
- diff_as_string(PP.pp(target,""), PP.pp(expected,""))
- end
-
- protected
- def format
- @options.diff_format
- end
-
- def context_lines
- @options.context_lines
- end
- end
- end
- end
-end
+++ /dev/null
-module Spec
- module Expectations
- # If Test::Unit is loaed, we'll use its error as baseclass, so that Test::Unit
- # will report unmet RSpec expectations as failures rather than errors.
- superclass = ['Test::Unit::AssertionFailedError', '::StandardError'].map do |c|
- eval(c) rescue nil
- end.compact.first
-
- class ExpectationNotMetError < superclass
- end
- end
-end
+++ /dev/null
-require 'spec/expectations/extensions/object'
-require 'spec/expectations/extensions/string_and_symbol'
+++ /dev/null
-module Spec
- module Expectations
- # rspec adds #should and #should_not to every Object (and,
- # implicitly, every Class).
- module ObjectExpectations
- # :call-seq:
- # should(matcher)
- # should == expected
- # should === expected
- # should =~ expected
- #
- # receiver.should(matcher)
- # => Passes if matcher.matches?(receiver)
- #
- # receiver.should == expected #any value
- # => Passes if (receiver == expected)
- #
- # receiver.should === expected #any value
- # => Passes if (receiver === expected)
- #
- # receiver.should =~ regexp
- # => Passes if (receiver =~ regexp)
- #
- # See Spec::Matchers for more information about matchers
- #
- # == Warning
- #
- # NOTE that this does NOT support receiver.should != expected.
- # Instead, use receiver.should_not == expected
- def should(matcher = :default_parameter, &block)
- if :default_parameter == matcher
- Spec::Matchers::PositiveOperatorMatcher.new(self)
- else
- ExpectationMatcherHandler.handle_matcher(self, matcher, &block)
- end
- end
-
- # :call-seq:
- # should_not(matcher)
- # should_not == expected
- # should_not === expected
- # should_not =~ expected
- #
- # receiver.should_not(matcher)
- # => Passes unless matcher.matches?(receiver)
- #
- # receiver.should_not == expected
- # => Passes unless (receiver == expected)
- #
- # receiver.should_not === expected
- # => Passes unless (receiver === expected)
- #
- # receiver.should_not =~ regexp
- # => Passes unless (receiver =~ regexp)
- #
- # See Spec::Matchers for more information about matchers
- def should_not(matcher = :default_parameter, &block)
- if :default_parameter == matcher
- Spec::Matchers::NegativeOperatorMatcher.new(self)
- else
- NegativeExpectationMatcherHandler.handle_matcher(self, matcher, &block)
- end
- end
-
- end
- end
-end
-
-class Object
- include Spec::Expectations::ObjectExpectations
-end
+++ /dev/null
-module Spec
- module Expectations
- module StringHelpers
- def starts_with?(prefix)
- to_s[0..(prefix.to_s.length - 1)] == prefix.to_s
- end
- end
- end
-end
-
-class String
- include Spec::Expectations::StringHelpers
-end
-
-class Symbol
- include Spec::Expectations::StringHelpers
-end
+++ /dev/null
-module Spec
- module Expectations
- class InvalidMatcherError < ArgumentError; end
-
- module MatcherHandlerHelper
- def describe_matcher(matcher)
- matcher.respond_to?(:description) ? matcher.description : "[#{matcher.class.name} does not provide a description]"
- end
- end
-
- class ExpectationMatcherHandler
- class << self
- include MatcherHandlerHelper
- def handle_matcher(actual, matcher, &block)
- unless matcher.respond_to?(:matches?)
- raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
- end
-
- match = matcher.matches?(actual, &block)
- ::Spec::Matchers.generated_description = "should #{describe_matcher(matcher)}"
- Spec::Expectations.fail_with(matcher.failure_message) unless match
- end
- end
- end
-
- class NegativeExpectationMatcherHandler
- class << self
- include MatcherHandlerHelper
- def handle_matcher(actual, matcher, &block)
- unless matcher.respond_to?(:matches?)
- raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
- end
-
- unless matcher.respond_to?(:negative_failure_message)
- Spec::Expectations.fail_with(
-<<-EOF
-Matcher does not support should_not.
-See Spec::Matchers for more information
-about matchers.
-EOF
-)
- end
- match = matcher.matches?(actual, &block)
- ::Spec::Matchers.generated_description = "should not #{describe_matcher(matcher)}"
- Spec::Expectations.fail_with(matcher.negative_failure_message) if match
- end
- end
- end
-
- end
-end
-
+++ /dev/null
-require 'spec/extensions/object'
-require 'spec/extensions/class'
-require 'spec/extensions/main'
+++ /dev/null
-class Class
- # Creates a new subclass of self, with a name "under" our own name.
- # Example:
- #
- # x = Foo::Bar.subclass('Zap'){}
- # x.name # => Foo::Bar::Zap_1
- # x.superclass.name # => Foo::Bar
- def subclass(base_name, &body)
- klass = Class.new(self)
- class_name = "#{base_name}_#{class_count!}"
- instance_eval do
- const_set(class_name, klass)
- end
- klass.instance_eval(&body)
- klass
- end
-
- private
- def class_count!
- @class_count ||= 0
- @class_count += 1
- @class_count
- end
-end
\ No newline at end of file
+++ /dev/null
-module Spec
- module Extensions
- module Main
- # Creates and returns a class that includes the ExampleGroupMethods
- # module. Which ExampleGroup type is created depends on the directory of the file
- # calling this method. For example, Spec::Rails will use different
- # classes for specs living in <tt>spec/models</tt>,
- # <tt>spec/helpers</tt>, <tt>spec/views</tt> and
- # <tt>spec/controllers</tt>.
- #
- # It is also possible to override autodiscovery of the example group
- # type with an options Hash as the last argument:
- #
- # describe "name", :type => :something_special do ...
- #
- # The reason for using different behaviour classes is to have different
- # matcher methods available from within the <tt>describe</tt> block.
- #
- # See Spec::Example::ExampleFactory#register for details about how to
- # register special implementations.
- #
- def describe(*args, &block)
- raise ArgumentError if args.empty?
- raise ArgumentError unless block
- args << {} unless Hash === args.last
- args.last[:spec_path] = caller(0)[1]
- Spec::Example::ExampleGroupFactory.create_example_group(*args, &block)
- end
- alias :context :describe
-
- # Creates an example group that can be shared by other example groups
- #
- # == Examples
- #
- # share_examples_for "All Editions" do
- # it "all editions behaviour" ...
- # end
- #
- # describe SmallEdition do
- # it_should_behave_like "All Editions"
- #
- # it "should do small edition stuff" do
- # ...
- # end
- # end
- def share_examples_for(name, &block)
- describe(name, :shared => true, &block)
- end
-
- alias :shared_examples_for :share_examples_for
-
- # Creates a Shared Example Group and assigns it to a constant
- #
- # share_as :AllEditions do
- # it "should do all editions stuff" ...
- # end
- #
- # describe SmallEdition do
- # it_should_behave_like AllEditions
- #
- # it "should do small edition stuff" do
- # ...
- # end
- # end
- #
- # And, for those of you who prefer to use something more like Ruby, you
- # can just include the module directly
- #
- # describe SmallEdition do
- # include AllEditions
- #
- # it "should do small edition stuff" do
- # ...
- # end
- # end
- def share_as(name, &block)
- begin
- Object.const_set(name, share_examples_for(name, &block))
- rescue NameError => e
- raise NameError.new(e.message + "\nThe first argument to share_as must be a legal name for a constant\n")
- end
- end
-
- private
-
- def rspec_options
- $rspec_options ||= begin; \
- parser = ::Spec::Runner::OptionParser.new(STDERR, STDOUT); \
- parser.order!(ARGV); \
- $rspec_options = parser.options; \
- end
- $rspec_options
- end
-
- def init_rspec_options(options)
- $rspec_options = options if $rspec_options.nil?
- end
- end
- end
-end
-
-include Spec::Extensions::Main
\ No newline at end of file
+++ /dev/null
-class Object
- def args_and_options(*args)
- options = Hash === args.last ? args.pop : {}
- return args, options
- end
-
- def metaclass
- class << self; self; end
- end
-end
+++ /dev/null
-require 'test/unit'
-require 'test/unit/testresult'
-
-require 'spec/interop/test/unit/testcase'
-require 'spec/interop/test/unit/testsuite_adapter'
-require 'spec/interop/test/unit/autorunner'
-require 'spec/interop/test/unit/testresult'
-require 'spec/interop/test/unit/ui/console/testrunner'
-
-Spec::Example::ExampleGroupFactory.default(Test::Unit::TestCase)
\ No newline at end of file
+++ /dev/null
-class Test::Unit::AutoRunner
- remove_method :process_args
- def process_args(argv)
- true
- end
-end
+++ /dev/null
-require 'test/unit/testcase'
-
-module Test
- module Unit
- # This extension of the standard Test::Unit::TestCase makes RSpec
- # available from within, so that you can do things like:
- #
- # require 'test/unit'
- # require 'spec'
- #
- # class MyTest < Test::Unit::TestCase
- # it "should work with Test::Unit assertions" do
- # assert_equal 4, 2+1
- # end
- #
- # def test_should_work_with_rspec_expectations
- # (3+1).should == 5
- # end
- # end
- #
- # See also Spec::Example::ExampleGroup
- class TestCase
- extend Spec::Example::ExampleGroupMethods
- include Spec::Example::ExampleMethods
-
- before(:each) {setup}
- after(:each) {teardown}
-
- class << self
- def suite
- Test::Unit::TestSuiteAdapter.new(self)
- end
-
- def example_method?(method_name)
- should_method?(method_name) || test_method?(method_name)
- end
-
- def test_method?(method_name)
- method_name =~ /^test[_A-Z]./ && (
- instance_method(method_name).arity == 0 ||
- instance_method(method_name).arity == -1
- )
- end
- end
-
- def initialize(defined_description, &implementation)
- @_defined_description = defined_description
- @_implementation = implementation
-
- @_result = ::Test::Unit::TestResult.new
- # @method_name is important to set here because it "complies" with Test::Unit's interface.
- # Some Test::Unit extensions depend on @method_name being present.
- @method_name = @_defined_description
- end
-
- def run(ignore_this_argument=nil)
- super()
- end
- end
- end
-end
+++ /dev/null
-class Test::Unit::TestResult
- alias_method :tu_passed?, :passed?
- def passed?
- return tu_passed? & ::Spec.run
- end
-end
\ No newline at end of file
+++ /dev/null
-module Test
- module Unit
- class TestSuiteAdapter < TestSuite
- attr_reader :example_group, :examples
- alias_method :tests, :examples
- def initialize(example_group)
- @example_group = example_group
- @examples = example_group.examples
- end
-
- def name
- example_group.description
- end
-
- def run(*args)
- return true unless args.empty?
- example_group.run
- end
-
- def size
- example_group.number_of_examples
- end
-
- def delete(example)
- examples.delete example
- end
-
- def empty?
- examples.empty?
- end
- end
- end
-end
-
+++ /dev/null
-require 'test/unit/ui/console/testrunner'
-
-module Test
- module Unit
- module UI
- module Console
- class TestRunner
-
- alias_method :started_without_rspec, :started
- def started_with_rspec(result)
- @result = result
- @need_to_output_started = true
- end
- alias_method :started, :started_with_rspec
-
- alias_method :test_started_without_rspec, :test_started
- def test_started_with_rspec(name)
- if @need_to_output_started
- if @rspec_io
- @rspec_io.rewind
- output(@rspec_io.read)
- end
- output("Started")
- @need_to_output_started = false
- end
- test_started_without_rspec(name)
- end
- alias_method :test_started, :test_started_with_rspec
-
- alias_method :test_finished_without_rspec, :test_finished
- def test_finished_with_rspec(name)
- test_finished_without_rspec(name)
- @ran_test = true
- end
- alias_method :test_finished, :test_finished_with_rspec
-
- alias_method :finished_without_rspec, :finished
- def finished_with_rspec(elapsed_time)
- if @ran_test
- finished_without_rspec(elapsed_time)
- end
- end
- alias_method :finished, :finished_with_rspec
-
- alias_method :setup_mediator_without_rspec, :setup_mediator
- def setup_mediator_with_rspec
- orig_io = @io
- @io = StringIO.new
- setup_mediator_without_rspec
- ensure
- @rspec_io = @io
- @io = orig_io
- end
- alias_method :setup_mediator, :setup_mediator_with_rspec
-
- end
- end
- end
- end
-end
+++ /dev/null
-require 'spec/matchers/simple_matcher'
-require 'spec/matchers/be'
-require 'spec/matchers/be_close'
-require 'spec/matchers/change'
-require 'spec/matchers/eql'
-require 'spec/matchers/equal'
-require 'spec/matchers/exist'
-require 'spec/matchers/has'
-require 'spec/matchers/have'
-require 'spec/matchers/include'
-require 'spec/matchers/match'
-require 'spec/matchers/raise_error'
-require 'spec/matchers/respond_to'
-require 'spec/matchers/satisfy'
-require 'spec/matchers/throw_symbol'
-require 'spec/matchers/operator_matcher'
-
-module Spec
-
- # RSpec ships with a number of useful Expression Matchers. An Expression Matcher
- # is any object that responds to the following methods:
- #
- # matches?(actual)
- # failure_message
- # negative_failure_message #optional
- # description #optional
- #
- # See Spec::Expectations to learn how to use these as Expectation Matchers.
- # See Spec::Mocks to learn how to use them as Mock Argument Constraints.
- #
- # == Predicates
- #
- # In addition to those Expression Matchers that are defined explicitly, RSpec will
- # create custom Matchers on the fly for any arbitrary predicate, giving your specs
- # a much more natural language feel.
- #
- # A Ruby predicate is a method that ends with a "?" and returns true or false.
- # Common examples are +empty?+, +nil?+, and +instance_of?+.
- #
- # All you need to do is write +should be_+ followed by the predicate without
- # the question mark, and RSpec will figure it out from there. For example:
- #
- # [].should be_empty => [].empty? #passes
- # [].should_not be_empty => [].empty? #fails
- #
- # In addtion to prefixing the predicate matchers with "be_", you can also use "be_a_"
- # and "be_an_", making your specs read much more naturally:
- #
- # "a string".should be_an_instance_of(String) =>"a string".instance_of?(String) #passes
- #
- # 3.should be_a_kind_of(Fixnum) => 3.kind_of?(Numeric) #passes
- # 3.should be_a_kind_of(Numeric) => 3.kind_of?(Numeric) #passes
- # 3.should be_an_instance_of(Fixnum) => 3.instance_of?(Fixnum) #passes
- # 3.should_not be_instance_of(Numeric) => 3.instance_of?(Numeric) #fails
- #
- # RSpec will also create custom matchers for predicates like +has_key?+. To
- # use this feature, just state that the object should have_key(:key) and RSpec will
- # call has_key?(:key) on the target. For example:
- #
- # {:a => "A"}.should have_key(:a) => {:a => "A"}.has_key?(:a) #passes
- # {:a => "A"}.should have_key(:b) => {:a => "A"}.has_key?(:b) #fails
- #
- # You can use this feature to invoke any predicate that begins with "has_", whether it is
- # part of the Ruby libraries (like +Hash#has_key?+) or a method you wrote on your own class.
- #
- # == Custom Expectation Matchers
- #
- # When you find that none of the stock Expectation Matchers provide a natural
- # feeling expectation, you can very easily write your own.
- #
- # For example, imagine that you are writing a game in which players can
- # be in various zones on a virtual board. To specify that bob should
- # be in zone 4, you could say:
- #
- # bob.current_zone.should eql(Zone.new("4"))
- #
- # But you might find it more expressive to say:
- #
- # bob.should be_in_zone("4")
- #
- # and/or
- #
- # bob.should_not be_in_zone("3")
- #
- # To do this, you would need to write a class like this:
- #
- # class BeInZone
- # def initialize(expected)
- # @expected = expected
- # end
- # def matches?(target)
- # @target = target
- # @target.current_zone.eql?(Zone.new(@expected))
- # end
- # def failure_message
- # "expected #{@target.inspect} to be in Zone #{@expected}"
- # end
- # def negative_failure_message
- # "expected #{@target.inspect} not to be in Zone #{@expected}"
- # end
- # end
- #
- # ... and a method like this:
- #
- # def be_in_zone(expected)
- # BeInZone.new(expected)
- # end
- #
- # And then expose the method to your specs. This is normally done
- # by including the method and the class in a module, which is then
- # included in your spec:
- #
- # module CustomGameMatchers
- # class BeInZone
- # ...
- # end
- #
- # def be_in_zone(expected)
- # ...
- # end
- # end
- #
- # describe "Player behaviour" do
- # include CustomGameMatchers
- # ...
- # end
- #
- # or you can include in globally in a spec_helper.rb file <tt>require</tt>d
- # from your spec file(s):
- #
- # Spec::Runner.configure do |config|
- # config.include(CustomGameMatchers)
- # end
- #
- module Matchers
- module ModuleMethods
- attr_accessor :generated_description
-
- def clear_generated_description
- self.generated_description = nil
- end
- end
-
- extend ModuleMethods
-
- def method_missing(sym, *args, &block) # :nodoc:
- return Matchers::Be.new(sym, *args) if sym.starts_with?("be_")
- return Matchers::Has.new(sym, *args) if sym.starts_with?("have_")
- super
- end
-
- class MatcherError < StandardError
- end
-
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class Be #:nodoc:
- def initialize(*args)
- if args.empty?
- @expected = :satisfy_if
- else
- @expected = parse_expected(args.shift)
- end
- @args = args
- @comparison = ""
- end
-
- def matches?(actual)
- @actual = actual
- if handling_predicate?
- begin
- return @result = actual.__send__(predicate, *@args)
- rescue => predicate_error
- # This clause should be empty, but rcov will not report it as covered
- # unless something (anything) is executed within the clause
- rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
- end
-
- # This supports should_exist > target.exists? in the old world.
- # We should consider deprecating that ability as in the new world
- # you can't write "should exist" unless you have your own custom matcher.
- begin
- return @result = actual.__send__(present_tense_predicate, *@args)
- rescue
- raise predicate_error
- end
- else
- return match_or_compare
- end
- end
-
- def failure_message
- return "expected #{@comparison}#{expected}, got #{@actual.inspect}" unless handling_predicate?
- return "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
- end
-
- def negative_failure_message
- return "expected not #{expected}, got #{@actual.inspect}" unless handling_predicate?
- return "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
- end
-
- def expected
- return "if to be satisfied" if @expected == :satisfy_if
- return true if @expected == :true
- return false if @expected == :false
- return "nil" if @expected == :nil
- return @expected.inspect
- end
-
- def match_or_compare
- return @actual ? true : false if @expected == :satisfy_if
- return @actual == true if @expected == :true
- return @actual == false if @expected == :false
- return @actual.nil? if @expected == :nil
- return @actual < @expected if @less_than
- return @actual <= @expected if @less_than_or_equal
- return @actual >= @expected if @greater_than_or_equal
- return @actual > @expected if @greater_than
- return @actual == @expected if @double_equal
- return @actual === @expected if @triple_equal
- return @actual.equal?(@expected)
- end
-
- def ==(expected)
- @prefix = "be "
- @double_equal = true
- @comparison = "== "
- @expected = expected
- self
- end
-
- def ===(expected)
- @prefix = "be "
- @triple_equal = true
- @comparison = "=== "
- @expected = expected
- self
- end
-
- def <(expected)
- @prefix = "be "
- @less_than = true
- @comparison = "< "
- @expected = expected
- self
- end
-
- def <=(expected)
- @prefix = "be "
- @less_than_or_equal = true
- @comparison = "<= "
- @expected = expected
- self
- end
-
- def >=(expected)
- @prefix = "be "
- @greater_than_or_equal = true
- @comparison = ">= "
- @expected = expected
- self
- end
-
- def >(expected)
- @prefix = "be "
- @greater_than = true
- @comparison = "> "
- @expected = expected
- self
- end
-
- def description
- "#{prefix_to_sentence}#{comparison}#{expected_to_sentence}#{args_to_sentence}"
- end
-
- private
- def parse_expected(expected)
- if Symbol === expected
- @handling_predicate = true
- ["be_an_","be_a_","be_"].each do |prefix|
- if expected.starts_with?(prefix)
- @prefix = prefix
- return "#{expected.to_s.sub(@prefix,"")}".to_sym
- end
- end
- end
- @prefix = ""
- return expected
- end
-
- def handling_predicate?
- return false if [:true, :false, :nil].include?(@expected)
- return @handling_predicate
- end
-
- def predicate
- "#{@expected.to_s}?".to_sym
- end
-
- def present_tense_predicate
- "#{@expected.to_s}s?".to_sym
- end
-
- def args_to_s
- return "" if @args.empty?
- inspected_args = @args.collect{|a| a.inspect}
- return "(#{inspected_args.join(', ')})"
- end
-
- def comparison
- @comparison
- end
-
- def expected_to_sentence
- split_words(@expected)
- end
-
- def prefix_to_sentence
- split_words(@prefix)
- end
-
- def split_words(sym)
- sym.to_s.gsub(/_/,' ')
- end
-
- def args_to_sentence
- case @args.length
- when 0
- ""
- when 1
- " #{@args[0]}"
- else
- " #{@args[0...-1].join(', ')} and #{@args[-1]}"
- end
- end
-
- end
-
- # :call-seq:
- # should be
- # should be_true
- # should be_false
- # should be_nil
- # should be_arbitrary_predicate(*args)
- # should_not be_nil
- # should_not be_arbitrary_predicate(*args)
- #
- # Given true, false, or nil, will pass if actual is
- # true, false or nil (respectively). Given no args means
- # the caller should satisfy an if condition (to be or not to be).
- #
- # Predicates are any Ruby method that ends in a "?" and returns true or false.
- # Given be_ followed by arbitrary_predicate (without the "?"), RSpec will match
- # convert that into a query against the target object.
- #
- # The arbitrary_predicate feature will handle any predicate
- # prefixed with "be_an_" (e.g. be_an_instance_of), "be_a_" (e.g. be_a_kind_of)
- # or "be_" (e.g. be_empty), letting you choose the prefix that best suits the predicate.
- #
- # == Examples
- #
- # target.should be
- # target.should be_true
- # target.should be_false
- # target.should be_nil
- # target.should_not be_nil
- #
- # collection.should be_empty #passes if target.empty?
- # "this string".should be_an_intance_of(String)
- #
- # target.should_not be_empty #passes unless target.empty?
- # target.should_not be_old_enough(16) #passes unless target.old_enough?(16)
- def be(*args)
- Matchers::Be.new(*args)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class BeClose #:nodoc:
- def initialize(expected, delta)
- @expected = expected
- @delta = delta
- end
-
- def matches?(actual)
- @actual = actual
- (@actual - @expected).abs < @delta
- end
-
- def failure_message
- "expected #{@expected} +/- (< #{@delta}), got #{@actual}"
- end
-
- def description
- "be close to #{@expected} (within +- #{@delta})"
- end
- end
-
- # :call-seq:
- # should be_close(expected, delta)
- # should_not be_close(expected, delta)
- #
- # Passes if actual == expected +/- delta
- #
- # == Example
- #
- # result.should be_close(3.0, 0.5)
- def be_close(expected, delta)
- Matchers::BeClose.new(expected, delta)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- #Based on patch from Wilson Bilkovich
- class Change #:nodoc:
- def initialize(receiver=nil, message=nil, &block)
- @receiver = receiver
- @message = message
- @block = block
- end
-
- def matches?(target, &block)
- if block
- raise MatcherError.new(<<-EOF
-block passed to should or should_not change must use {} instead of do/end
-EOF
-)
- end
- @target = target
- execute_change
- return false if @from && (@from != @before)
- return false if @to && (@to != @after)
- return (@before + @amount == @after) if @amount
- return ((@after - @before) >= @minimum) if @minimum
- return ((@after - @before) <= @maximum) if @maximum
- return @before != @after
- end
-
- def execute_change
- @before = @block.nil? ? @receiver.send(@message) : @block.call
- @target.call
- @after = @block.nil? ? @receiver.send(@message) : @block.call
- end
-
- def failure_message
- if @to
- "#{result} should have been changed to #{@to.inspect}, but is now #{@after.inspect}"
- elsif @from
- "#{result} should have initially been #{@from.inspect}, but was #{@before.inspect}"
- elsif @amount
- "#{result} should have been changed by #{@amount.inspect}, but was changed by #{actual_delta.inspect}"
- elsif @minimum
- "#{result} should have been changed by at least #{@minimum.inspect}, but was changed by #{actual_delta.inspect}"
- elsif @maximum
- "#{result} should have been changed by at most #{@maximum.inspect}, but was changed by #{actual_delta.inspect}"
- else
- "#{result} should have changed, but is still #{@before.inspect}"
- end
- end
-
- def result
- @message || "result"
- end
-
- def actual_delta
- @after - @before
- end
-
- def negative_failure_message
- "#{result} should not have changed, but did change from #{@before.inspect} to #{@after.inspect}"
- end
-
- def by(amount)
- @amount = amount
- self
- end
-
- def by_at_least(minimum)
- @minimum = minimum
- self
- end
-
- def by_at_most(maximum)
- @maximum = maximum
- self
- end
-
- def to(to)
- @to = to
- self
- end
-
- def from (from)
- @from = from
- self
- end
- end
-
- # :call-seq:
- # should change(receiver, message, &block)
- # should change(receiver, message, &block).by(value)
- # should change(receiver, message, &block).from(old).to(new)
- # should_not change(receiver, message, &block)
- #
- # Allows you to specify that a Proc will cause some value to change.
- #
- # == Examples
- #
- # lambda {
- # team.add_player(player)
- # }.should change(roster, :count)
- #
- # lambda {
- # team.add_player(player)
- # }.should change(roster, :count).by(1)
- #
- # lambda {
- # team.add_player(player)
- # }.should change(roster, :count).by_at_least(1)
- #
- # lambda {
- # team.add_player(player)
- # }.should change(roster, :count).by_at_most(1)
- #
- # string = "string"
- # lambda {
- # string.reverse
- # }.should change { string }.from("string").to("gnirts")
- #
- # lambda {
- # person.happy_birthday
- # }.should change(person, :birthday).from(32).to(33)
- #
- # lambda {
- # employee.develop_great_new_social_networking_app
- # }.should change(employee, :title).from("Mail Clerk").to("CEO")
- #
- # Evaluates +receiver.message+ or +block+ before and
- # after it evaluates the c object (generated by the lambdas in the examples above).
- #
- # Then compares the values before and after the +receiver.message+ and
- # evaluates the difference compared to the expected difference.
- #
- # == Warning
- # +should_not+ +change+ only supports the form with no subsequent calls to
- # +by+, +by_at_least+, +by_at_most+, +to+ or +from+.
- #
- # blocks passed to +should+ +change+ and +should_not+ +change+
- # must use the <tt>{}</tt> form (<tt>do/end</tt> is not supported)
- def change(target=nil, message=nil, &block)
- Matchers::Change.new(target, message, &block)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class Eql #:nodoc:
- def initialize(expected)
- @expected = expected
- end
-
- def matches?(actual)
- @actual = actual
- @actual.eql?(@expected)
- end
-
- def failure_message
- return "expected #{@expected.inspect}, got #{@actual.inspect} (using .eql?)", @expected, @actual
- end
-
- def negative_failure_message
- return "expected #{@actual.inspect} not to equal #{@expected.inspect} (using .eql?)", @expected, @actual
- end
-
- def description
- "eql #{@expected.inspect}"
- end
- end
-
- # :call-seq:
- # should eql(expected)
- # should_not eql(expected)
- #
- # Passes if actual and expected are of equal value, but not necessarily the same object.
- #
- # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
- #
- # == Examples
- #
- # 5.should eql(5)
- # 5.should_not eql(3)
- def eql(expected)
- Matchers::Eql.new(expected)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class Equal #:nodoc:
- def initialize(expected)
- @expected = expected
- end
-
- def matches?(actual)
- @actual = actual
- @actual.equal?(@expected)
- end
-
- def failure_message
- return "expected #{@expected.inspect}, got #{@actual.inspect} (using .equal?)", @expected, @actual
- end
-
- def negative_failure_message
- return "expected #{@actual.inspect} not to equal #{@expected.inspect} (using .equal?)", @expected, @actual
- end
-
- def description
- "equal #{@expected.inspect}"
- end
- end
-
- # :call-seq:
- # should equal(expected)
- # should_not equal(expected)
- #
- # Passes if actual and expected are the same object (object identity).
- #
- # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
- #
- # == Examples
- #
- # 5.should equal(5) #Fixnums are equal
- # "5".should_not equal("5") #Strings that look the same are not the same object
- def equal(expected)
- Matchers::Equal.new(expected)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
- class Exist
- def matches? actual
- @actual = actual
- @actual.exist?
- end
- def failure_message
- "expected #{@actual.inspect} to exist, but it doesn't."
- end
- def negative_failure_message
- "expected #{@actual.inspect} to not exist, but it does."
- end
- end
- def exist; Exist.new; end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class Has #:nodoc:
- def initialize(sym, *args)
- @sym = sym
- @args = args
- end
-
- def matches?(target)
- @target = target
- begin
- return target.send(predicate, *@args)
- rescue => @error
- # This clause should be empty, but rcov will not report it as covered
- # unless something (anything) is executed within the clause
- rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
- end
- return false
- end
-
- def failure_message
- raise @error if @error
- "expected ##{predicate}(#{@args[0].inspect}) to return true, got false"
- end
-
- def negative_failure_message
- raise @error if @error
- "expected ##{predicate}(#{@args[0].inspect}) to return false, got true"
- end
-
- def description
- "have key #{@args[0].inspect}"
- end
-
- private
- def predicate
- "#{@sym.to_s.sub("have_","has_")}?".to_sym
- end
-
- end
-
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class Have #:nodoc:
- def initialize(expected, relativity=:exactly)
- @expected = (expected == :no ? 0 : expected)
- @relativity = relativity
- end
-
- def relativities
- @relativities ||= {
- :exactly => "",
- :at_least => "at least ",
- :at_most => "at most "
- }
- end
-
- def method_missing(sym, *args, &block)
- @collection_name = sym
- @plural_collection_name = Inflector.pluralize(sym.to_s) if Object.const_defined?(:Inflector)
- @args = args
- @block = block
- self
- end
-
- def matches?(collection_owner)
- if collection_owner.respond_to?(@collection_name)
- collection = collection_owner.send(@collection_name, *@args, &@block)
- elsif (@plural_collection_name && collection_owner.respond_to?(@plural_collection_name))
- collection = collection_owner.send(@plural_collection_name, *@args, &@block)
- elsif (collection_owner.respond_to?(:length) || collection_owner.respond_to?(:size))
- collection = collection_owner
- else
- collection_owner.send(@collection_name, *@args, &@block)
- end
- @actual = collection.size if collection.respond_to?(:size)
- @actual = collection.length if collection.respond_to?(:length)
- raise not_a_collection if @actual.nil?
- return @actual >= @expected if @relativity == :at_least
- return @actual <= @expected if @relativity == :at_most
- return @actual == @expected
- end
-
- def not_a_collection
- "expected #{@collection_name} to be a collection but it does not respond to #length or #size"
- end
-
- def failure_message
- "expected #{relative_expectation} #{@collection_name}, got #{@actual}"
- end
-
- def negative_failure_message
- if @relativity == :exactly
- return "expected target not to have #{@expected} #{@collection_name}, got #{@actual}"
- elsif @relativity == :at_most
- return <<-EOF
-Isn't life confusing enough?
-Instead of having to figure out the meaning of this:
- should_not have_at_most(#{@expected}).#{@collection_name}
-We recommend that you use this instead:
- should have_at_least(#{@expected + 1}).#{@collection_name}
-EOF
- elsif @relativity == :at_least
- return <<-EOF
-Isn't life confusing enough?
-Instead of having to figure out the meaning of this:
- should_not have_at_least(#{@expected}).#{@collection_name}
-We recommend that you use this instead:
- should have_at_most(#{@expected - 1}).#{@collection_name}
-EOF
- end
- end
-
- def description
- "have #{relative_expectation} #{@collection_name}"
- end
-
- private
-
- def relative_expectation
- "#{relativities[@relativity]}#{@expected}"
- end
- end
-
- # :call-seq:
- # should have(number).named_collection__or__sugar
- # should_not have(number).named_collection__or__sugar
- #
- # Passes if receiver is a collection with the submitted
- # number of items OR if the receiver OWNS a collection
- # with the submitted number of items.
- #
- # If the receiver OWNS the collection, you must use the name
- # of the collection. So if a <tt>Team</tt> instance has a
- # collection named <tt>#players</tt>, you must use that name
- # to set the expectation.
- #
- # If the receiver IS the collection, you can use any name
- # you like for <tt>named_collection</tt>. We'd recommend using
- # either "elements", "members", or "items" as these are all
- # standard ways of describing the things IN a collection.
- #
- # This also works for Strings, letting you set an expectation
- # about its length
- #
- # == Examples
- #
- # # Passes if team.players.size == 11
- # team.should have(11).players
- #
- # # Passes if [1,2,3].length == 3
- # [1,2,3].should have(3).items #"items" is pure sugar
- #
- # # Passes if "this string".length == 11
- # "this string".should have(11).characters #"characters" is pure sugar
- def have(n)
- Matchers::Have.new(n)
- end
- alias :have_exactly :have
-
- # :call-seq:
- # should have_at_least(number).items
- #
- # Exactly like have() with >=.
- #
- # == Warning
- #
- # +should_not+ +have_at_least+ is not supported
- def have_at_least(n)
- Matchers::Have.new(n, :at_least)
- end
-
- # :call-seq:
- # should have_at_most(number).items
- #
- # Exactly like have() with <=.
- #
- # == Warning
- #
- # +should_not+ +have_at_most+ is not supported
- def have_at_most(n)
- Matchers::Have.new(n, :at_most)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class Include #:nodoc:
-
- def initialize(*expecteds)
- @expecteds = expecteds
- end
-
- def matches?(actual)
- @actual = actual
- @expecteds.each do |expected|
- return false unless actual.include?(expected)
- end
- true
- end
-
- def failure_message
- _message
- end
-
- def negative_failure_message
- _message("not ")
- end
-
- def description
- "include #{_pretty_print(@expecteds)}"
- end
-
- private
- def _message(maybe_not="")
- "expected #{@actual.inspect} #{maybe_not}to include #{_pretty_print(@expecteds)}"
- end
-
- def _pretty_print(array)
- result = ""
- array.each_with_index do |item, index|
- if index < (array.length - 2)
- result << "#{item.inspect}, "
- elsif index < (array.length - 1)
- result << "#{item.inspect} and "
- else
- result << "#{item.inspect}"
- end
- end
- result
- end
- end
-
- # :call-seq:
- # should include(expected)
- # should_not include(expected)
- #
- # Passes if actual includes expected. This works for
- # collections and Strings. You can also pass in multiple args
- # and it will only pass if all args are found in collection.
- #
- # == Examples
- #
- # [1,2,3].should include(3)
- # [1,2,3].should include(2,3) #would pass
- # [1,2,3].should include(2,3,4) #would fail
- # [1,2,3].should_not include(4)
- # "spread".should include("read")
- # "spread".should_not include("red")
- def include(*expected)
- Matchers::Include.new(*expected)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class Match #:nodoc:
- def initialize(expected)
- @expected = expected
- end
-
- def matches?(actual)
- @actual = actual
- return true if actual =~ @expected
- return false
- end
-
- def failure_message
- return "expected #{@actual.inspect} to match #{@expected.inspect}", @expected, @actual
- end
-
- def negative_failure_message
- return "expected #{@actual.inspect} not to match #{@expected.inspect}", @expected, @actual
- end
-
- def description
- "match #{@expected.inspect}"
- end
- end
-
- # :call-seq:
- # should match(regexp)
- # should_not match(regexp)
- #
- # Given a Regexp, passes if actual =~ regexp
- #
- # == Examples
- #
- # email.should match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
- def match(regexp)
- Matchers::Match.new(regexp)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
- class BaseOperatorMatcher
- attr_reader :generated_description
-
- def initialize(target)
- @target = target
- end
-
- def ==(expected)
- @expected = expected
- __delegate_method_missing_to_target("==", expected)
- end
-
- def ===(expected)
- @expected = expected
- __delegate_method_missing_to_target("===", expected)
- end
-
- def =~(expected)
- @expected = expected
- __delegate_method_missing_to_target("=~", expected)
- end
-
- def >(expected)
- @expected = expected
- __delegate_method_missing_to_target(">", expected)
- end
-
- def >=(expected)
- @expected = expected
- __delegate_method_missing_to_target(">=", expected)
- end
-
- def <(expected)
- @expected = expected
- __delegate_method_missing_to_target("<", expected)
- end
-
- def <=(expected)
- @expected = expected
- __delegate_method_missing_to_target("<=", expected)
- end
-
- def fail_with_message(message)
- Spec::Expectations.fail_with(message, @expected, @target)
- end
-
- end
-
- class PositiveOperatorMatcher < BaseOperatorMatcher #:nodoc:
-
- def __delegate_method_missing_to_target(operator, expected)
- ::Spec::Matchers.generated_description = "should #{operator} #{expected.inspect}"
- return if @target.send(operator, expected)
- return fail_with_message("expected: #{expected.inspect},\n got: #{@target.inspect} (using #{operator})") if ['==','===', '=~'].include?(operator)
- return fail_with_message("expected: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{@target.inspect}")
- end
-
- end
-
- class NegativeOperatorMatcher < BaseOperatorMatcher #:nodoc:
-
- def __delegate_method_missing_to_target(operator, expected)
- ::Spec::Matchers.generated_description = "should not #{operator} #{expected.inspect}"
- return unless @target.send(operator, expected)
- return fail_with_message("expected not: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{@target.inspect}")
- end
-
- end
-
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class RaiseError #:nodoc:
- def initialize(error_or_message=Exception, message=nil)
- if String === error_or_message
- @expected_error = Exception
- @expected_message = error_or_message
- else
- @expected_error = error_or_message
- @expected_message = message
- end
- end
-
- def matches?(proc)
- @raised_expected_error = false
- @raised_other = false
- begin
- proc.call
- rescue @expected_error => @actual_error
- if @expected_message.nil?
- @raised_expected_error = true
- else
- case @expected_message
- when Regexp
- if @expected_message =~ @actual_error.message
- @raised_expected_error = true
- else
- @raised_other = true
- end
- else
- if @expected_message == @actual_error.message
- @raised_expected_error = true
- else
- @raised_other = true
- end
- end
- end
- rescue => @actual_error
- @raised_other = true
- ensure
- return @raised_expected_error
- end
- end
-
- def failure_message
- return "expected #{expected_error}#{actual_error}" if @raised_other || !@raised_expected_error
- end
-
- def negative_failure_message
- "expected no #{expected_error}#{actual_error}"
- end
-
- def description
- "raise #{expected_error}"
- end
-
- private
- def expected_error
- case @expected_message
- when nil
- @expected_error
- when Regexp
- "#{@expected_error} with message matching #{@expected_message.inspect}"
- else
- "#{@expected_error} with #{@expected_message.inspect}"
- end
- end
-
- def actual_error
- @actual_error.nil? ? " but nothing was raised" : ", got #{@actual_error.inspect}"
- end
- end
-
- # :call-seq:
- # should raise_error()
- # should raise_error(NamedError)
- # should raise_error(NamedError, String)
- # should raise_error(NamedError, Regexp)
- # should_not raise_error()
- # should_not raise_error(NamedError)
- # should_not raise_error(NamedError, String)
- # should_not raise_error(NamedError, Regexp)
- #
- # With no args, matches if any error is raised.
- # With a named error, matches only if that specific error is raised.
- # With a named error and messsage specified as a String, matches only if both match.
- # With a named error and messsage specified as a Regexp, matches only if both match.
- #
- # == Examples
- #
- # lambda { do_something_risky }.should raise_error
- # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError)
- # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError, "that was too risky")
- # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError, /oo ri/)
- #
- # lambda { do_something_risky }.should_not raise_error
- # lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError)
- # lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError, "that was too risky")
- # lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError, /oo ri/)
- def raise_error(error=Exception, message=nil)
- Matchers::RaiseError.new(error, message)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class RespondTo #:nodoc:
- def initialize(*names)
- @names = names
- @names_not_responded_to = []
- end
-
- def matches?(target)
- @names.each do |name|
- unless target.respond_to?(name)
- @names_not_responded_to << name
- end
- end
- return @names_not_responded_to.empty?
- end
-
- def failure_message
- "expected target to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}"
- end
-
- def negative_failure_message
- "expected target not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
- end
-
- def description
- "respond to ##{@names.to_s}"
- end
- end
-
- # :call-seq:
- # should respond_to(*names)
- # should_not respond_to(*names)
- #
- # Matches if the target object responds to all of the names
- # provided. Names can be Strings or Symbols.
- #
- # == Examples
- #
- def respond_to(*names)
- Matchers::RespondTo.new(*names)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
-
- class Satisfy #:nodoc:
- def initialize(&block)
- @block = block
- end
-
- def matches?(actual, &block)
- @block = block if block
- @actual = actual
- @block.call(actual)
- end
-
- def failure_message
- "expected #{@actual} to satisfy block"
- end
-
- def negative_failure_message
- "expected #{@actual} not to satisfy block"
- end
- end
-
- # :call-seq:
- # should satisfy {}
- # should_not satisfy {}
- #
- # Passes if the submitted block returns true. Yields target to the
- # block.
- #
- # Generally speaking, this should be thought of as a last resort when
- # you can't find any other way to specify the behaviour you wish to
- # specify.
- #
- # If you do find yourself in such a situation, you could always write
- # a custom matcher, which would likely make your specs more expressive.
- #
- # == Examples
- #
- # 5.should satisfy { |n|
- # n > 3
- # }
- def satisfy(&block)
- Matchers::Satisfy.new(&block)
- end
- end
-end
+++ /dev/null
-module Spec
- module Matchers
- class SimpleMatcher
- attr_reader :description
-
- def initialize(description, &match_block)
- @description = description
- @match_block = match_block
- end
-
- def matches?(actual)
- @actual = actual
- return @match_block.call(@actual)
- end
-
- def failure_message()
- return %[expected #{@description.inspect} but got #{@actual.inspect}]
- end
-
- def negative_failure_message()
- return %[expected not to get #{@description.inspect}, but got #{@actual.inspect}]
- end
- end
-
- def simple_matcher(message, &match_block)
- SimpleMatcher.new(message, &match_block)
- end
- end
-end
\ No newline at end of file
+++ /dev/null
-module Spec
- module Matchers
-
- class ThrowSymbol #:nodoc:
- def initialize(expected=nil)
- @expected = expected
- @actual = nil
- end
-
- def matches?(proc)
- begin
- proc.call
- rescue NameError => e
- raise e unless e.message =~ /uncaught throw/
- @actual = e.name.to_sym
- ensure
- if @expected.nil?
- return @actual.nil? ? false : true
- else
- return @actual == @expected
- end
- end
- end
-
- def failure_message
- if @actual
- "expected #{expected}, got #{@actual.inspect}"
- else
- "expected #{expected} but nothing was thrown"
- end
- end
-
- def negative_failure_message
- if @expected
- "expected #{expected} not to be thrown"
- else
- "expected no Symbol, got :#{@actual}"
- end
- end
-
- def description
- "throw #{expected}"
- end
-
- private
-
- def expected
- @expected.nil? ? "a Symbol" : @expected.inspect
- end
-
- end
-
- # :call-seq:
- # should throw_symbol()
- # should throw_symbol(:sym)
- # should_not throw_symbol()
- # should_not throw_symbol(:sym)
- #
- # Given a Symbol argument, matches if a proc throws the specified Symbol.
- #
- # Given no argument, matches if a proc throws any Symbol.
- #
- # == Examples
- #
- # lambda { do_something_risky }.should throw_symbol
- # lambda { do_something_risky }.should throw_symbol(:that_was_risky)
- #
- # lambda { do_something_risky }.should_not throw_symbol
- # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky)
- def throw_symbol(sym=nil)
- Matchers::ThrowSymbol.new(sym)
- end
- end
-end
+++ /dev/null
-require 'spec/mocks/methods'
-require 'spec/mocks/argument_constraint_matchers'
-require 'spec/mocks/spec_methods'
-require 'spec/mocks/proxy'
-require 'spec/mocks/mock'
-require 'spec/mocks/argument_expectation'
-require 'spec/mocks/message_expectation'
-require 'spec/mocks/order_group'
-require 'spec/mocks/errors'
-require 'spec/mocks/error_generator'
-require 'spec/mocks/extensions/object'
-require 'spec/mocks/space'
-
-
-module Spec
- # == Mocks and Stubs
- #
- # RSpec will create Mock Objects and Stubs for you at runtime, or attach stub/mock behaviour
- # to any of your real objects (Partial Mock/Stub). Because the underlying implementation
- # for mocks and stubs is the same, you can intermingle mock and stub
- # behaviour in either dynamically generated mocks or your pre-existing classes.
- # There is a semantic difference in how they are created, however,
- # which can help clarify the role it is playing within a given spec.
- #
- # == Mock Objects
- #
- # Mocks are objects that allow you to set and verify expectations that they will
- # receive specific messages during run time. They are very useful for specifying how the subject of
- # the spec interacts with its collaborators. This approach is widely known as "interaction
- # testing".
- #
- # Mocks are also very powerful as a design tool. As you are
- # driving the implementation of a given class, Mocks provide an anonymous
- # collaborator that can change in behaviour as quickly as you can write an expectation in your
- # spec. This flexibility allows you to design the interface of a collaborator that often
- # does not yet exist. As the shape of the class being specified becomes more clear, so do the
- # requirements for its collaborators - often leading to the discovery of new types that are
- # needed in your system.
- #
- # Read Endo-Testing[http://www.mockobjects.com/files/endotesting.pdf] for a much
- # more in depth description of this process.
- #
- # == Stubs
- #
- # Stubs are objects that allow you to set "stub" responses to
- # messages. As Martin Fowler points out on his site,
- # mocks_arent_stubs[http://www.martinfowler.com/articles/mocksArentStubs.html].
- # Paraphrasing Fowler's paraphrasing
- # of Gerard Meszaros: Stubs provide canned responses to messages they might receive in a test, while
- # mocks allow you to specify and, subsquently, verify that certain messages should be received during
- # the execution of a test.
- #
- # == Partial Mocks/Stubs
- #
- # RSpec also supports partial mocking/stubbing, allowing you to add stub/mock behaviour
- # to instances of your existing classes. This is generally
- # something to be avoided, because changes to the class can have ripple effects on
- # seemingly unrelated specs. When specs fail due to these ripple effects, the fact
- # that some methods are being mocked can make it difficult to understand why a
- # failure is occurring.
- #
- # That said, partials do allow you to expect and
- # verify interactions with class methods such as +#find+ and +#create+
- # on Ruby on Rails model classes.
- #
- # == Further Reading
- #
- # There are many different viewpoints about the meaning of mocks and stubs. If you are interested
- # in learning more, here is some recommended reading:
- #
- # * Mock Objects: http://www.mockobjects.com/
- # * Endo-Testing: http://www.mockobjects.com/files/endotesting.pdf
- # * Mock Roles, Not Objects: http://www.mockobjects.com/files/mockrolesnotobjects.pdf
- # * Test Double Patterns: http://xunitpatterns.com/Test%20Double%20Patterns.html
- # * Mocks aren't stubs: http://www.martinfowler.com/articles/mocksArentStubs.html
- #
- # == Creating a Mock
- #
- # You can create a mock in any specification (or setup) using:
- #
- # mock(name, options={})
- #
- # The optional +options+ argument is a +Hash+. Currently the only supported
- # option is +:null_object+. Setting this to true instructs the mock to ignore
- # any messages it hasn’t been told to expect – and quietly return itself. For example:
- #
- # mock("person", :null_object => true)
- #
- # == Creating a Stub
- #
- # You can create a stub in any specification (or setup) using:
- #
- # stub(name, stub_methods_and_values_hash)
- #
- # For example, if you wanted to create an object that always returns
- # "More?!?!?!" to "please_sir_may_i_have_some_more" you would do this:
- #
- # stub("Mr Sykes", :please_sir_may_i_have_some_more => "More?!?!?!")
- #
- # == Creating a Partial Mock
- #
- # You don't really "create" a partial mock, you simply add method stubs and/or
- # mock expectations to existing classes and objects:
- #
- # Factory.should_receive(:find).with(id).and_return(value)
- # obj.stub!(:to_i).and_return(3)
- # etc ...
- #
- # == Expecting Messages
- #
- # my_mock.should_receive(:sym)
- # my_mock.should_not_receive(:sym)
- #
- # == Expecting Arguments
- #
- # my_mock.should_receive(:sym).with(*args)
- # my_mock.should_not_receive(:sym).with(*args)
- #
- # == Argument Constraints using Expression Matchers
- #
- # Arguments that are passed to #with are compared with actual arguments received
- # using == by default. In cases in which you want to specify things about the arguments
- # rather than the arguments themselves, you can use any of the Expression Matchers.
- # They don't all make syntactic sense (they were primarily designed for use with
- # Spec::Expectations), but you are free to create your own custom Spec::Matchers.
- #
- # Spec::Mocks does provide one additional Matcher method named #ducktype.
- #
- # In addition, Spec::Mocks adds some keyword Symbols that you can use to
- # specify certain kinds of arguments:
- #
- # my_mock.should_receive(:sym).with(no_args())
- # my_mock.should_receive(:sym).with(any_args())
- # my_mock.should_receive(:sym).with(1, an_instance_of(Numeric), "b") #2nd argument can any type of Numeric
- # my_mock.should_receive(:sym).with(1, boolean(), "b") #2nd argument can true or false
- # my_mock.should_receive(:sym).with(1, /abc/, "b") #2nd argument can be any String matching the submitted Regexp
- # my_mock.should_receive(:sym).with(1, anything(), "b") #2nd argument can be anything at all
- # my_mock.should_receive(:sym).with(1, ducktype(:abs, :div), "b")
- # #2nd argument can be object that responds to #abs and #div
- #
- # == Receive Counts
- #
- # my_mock.should_receive(:sym).once
- # my_mock.should_receive(:sym).twice
- # my_mock.should_receive(:sym).exactly(n).times
- # my_mock.should_receive(:sym).at_least(:once)
- # my_mock.should_receive(:sym).at_least(:twice)
- # my_mock.should_receive(:sym).at_least(n).times
- # my_mock.should_receive(:sym).at_most(:once)
- # my_mock.should_receive(:sym).at_most(:twice)
- # my_mock.should_receive(:sym).at_most(n).times
- # my_mock.should_receive(:sym).any_number_of_times
- #
- # == Ordering
- #
- # my_mock.should_receive(:sym).ordered
- # my_mock.should_receive(:other_sym).ordered
- # #This will fail if the messages are received out of order
- #
- # == Setting Reponses
- #
- # Whether you are setting a mock expectation or a simple stub, you can tell the
- # object precisely how to respond:
- #
- # my_mock.should_receive(:sym).and_return(value)
- # my_mock.should_receive(:sym).exactly(3).times.and_return(value1, value2, value3)
- # # returns value1 the first time, value2 the second, etc
- # my_mock.should_receive(:sym).and_return { ... } #returns value returned by the block
- # my_mock.should_receive(:sym).and_raise(error)
- # #error can be an instantiated object or a class
- # #if it is a class, it must be instantiable with no args
- # my_mock.should_receive(:sym).and_throw(:sym)
- # my_mock.should_receive(:sym).and_yield(values,to,yield)
- # my_mock.should_receive(:sym).and_yield(values,to,yield).and_yield(some,other,values,this,time)
- # # for methods that yield to a block multiple times
- #
- # Any of these responses can be applied to a stub as well, but stubs do
- # not support any qualifiers about the message received (i.e. you can't specify arguments
- # or receive counts):
- #
- # my_mock.stub!(:sym).and_return(value)
- # my_mock.stub!(:sym).and_return(value1, value2, value3)
- # my_mock.stub!(:sym).and_raise(error)
- # my_mock.stub!(:sym).and_throw(:sym)
- # my_mock.stub!(:sym).and_yield(values,to,yield)
- # my_mock.stub!(:sym).and_yield(values,to,yield).and_yield(some,other,values,this,time)
- #
- # == Arbitrary Handling
- #
- # Once in a while you'll find that the available expectations don't solve the
- # particular problem you are trying to solve. Imagine that you expect the message
- # to come with an Array argument that has a specific length, but you don't care
- # what is in it. You could do this:
- #
- # my_mock.should_receive(:sym) do |arg|
- # arg.should be_an_istance_of(Array)
- # arg.length.should == 7
- # end
- #
- # Note that this would fail if the number of arguments received was different from
- # the number of block arguments (in this case 1).
- #
- # == Combining Expectation Details
- #
- # Combining the message name with specific arguments, receive counts and responses
- # you can get quite a bit of detail in your expectations:
- #
- # my_mock.should_receive(:<<).with("illegal value").once.and_raise(ArgumentError)
- module Mocks
- end
-end
+++ /dev/null
-module Spec
- module Mocks
- module ArgumentConstraintMatchers
-
- # Shortcut for creating an instance of Spec::Mocks::DuckTypeArgConstraint
- def duck_type(*args)
- DuckTypeArgConstraint.new(*args)
- end
-
- def any_args
- AnyArgsConstraint.new
- end
-
- def anything
- AnyArgConstraint.new(nil)
- end
-
- def boolean
- BooleanArgConstraint.new(nil)
- end
-
- def no_args
- NoArgsConstraint.new
- end
- end
- end
-end
+++ /dev/null
-module Spec
- module Mocks
-
- class MatcherConstraint
- def initialize(matcher)
- @matcher = matcher
- end
-
- def matches?(value)
- @matcher.matches?(value)
- end
- end
-
- class LiteralArgConstraint
- def initialize(literal)
- @literal_value = literal
- end
-
- def matches?(value)
- @literal_value == value
- end
- end
-
- class RegexpArgConstraint
- def initialize(regexp)
- @regexp = regexp
- end
-
- def matches?(value)
- return value =~ @regexp unless value.is_a?(Regexp)
- value == @regexp
- end
- end
-
- class AnyArgConstraint
- def initialize(ignore)
- end
-
- def ==(other)
- true
- end
-
- # TODO - need this?
- def matches?(value)
- true
- end
- end
-
- class AnyArgsConstraint
- def description
- "any args"
- end
- end
-
- class NoArgsConstraint
- def description
- "no args"
- end
-
- def ==(args)
- args == []
- end
- end
-
- class NumericArgConstraint
- def initialize(ignore)
- end
-
- def matches?(value)
- value.is_a?(Numeric)
- end
- end
-
- class BooleanArgConstraint
- def initialize(ignore)
- end
-
- def ==(value)
- matches?(value)
- end
-
- def matches?(value)
- return true if value.is_a?(TrueClass)
- return true if value.is_a?(FalseClass)
- false
- end
- end
-
- class StringArgConstraint
- def initialize(ignore)
- end
-
- def matches?(value)
- value.is_a?(String)
- end
- end
-
- class DuckTypeArgConstraint
- def initialize(*methods_to_respond_to)
- @methods_to_respond_to = methods_to_respond_to
- end
-
- def matches?(value)
- @methods_to_respond_to.all? { |sym| value.respond_to?(sym) }
- end
-
- def description
- "duck_type"
- end
- end
-
- class ArgumentExpectation
- attr_reader :args
- @@constraint_classes = Hash.new { |hash, key| LiteralArgConstraint}
- @@constraint_classes[:anything] = AnyArgConstraint
- @@constraint_classes[:numeric] = NumericArgConstraint
- @@constraint_classes[:boolean] = BooleanArgConstraint
- @@constraint_classes[:string] = StringArgConstraint
-
- def initialize(args)
- @args = args
- if [:any_args] == args
- @expected_params = nil
- warn_deprecated(:any_args.inspect, "any_args()")
- elsif args.length == 1 && args[0].is_a?(AnyArgsConstraint) then @expected_params = nil
- elsif [:no_args] == args
- @expected_params = []
- warn_deprecated(:no_args.inspect, "no_args()")
- elsif args.length == 1 && args[0].is_a?(NoArgsConstraint) then @expected_params = []
- else @expected_params = process_arg_constraints(args)
- end
- end
-
- def process_arg_constraints(constraints)
- constraints.collect do |constraint|
- convert_constraint(constraint)
- end
- end
-
- def warn_deprecated(deprecated_method, instead)
- Kernel.warn "The #{deprecated_method} constraint is deprecated. Use #{instead} instead."
- end
-
- def convert_constraint(constraint)
- if [:anything, :numeric, :boolean, :string].include?(constraint)
- case constraint
- when :anything
- instead = "anything()"
- when :boolean
- instead = "boolean()"
- when :numeric
- instead = "an_instance_of(Numeric)"
- when :string
- instead = "an_instance_of(String)"
- end
- warn_deprecated(constraint.inspect, instead)
- return @@constraint_classes[constraint].new(constraint)
- end
- return MatcherConstraint.new(constraint) if is_matcher?(constraint)
- return RegexpArgConstraint.new(constraint) if constraint.is_a?(Regexp)
- return LiteralArgConstraint.new(constraint)
- end
-
- def is_matcher?(obj)
- return obj.respond_to?(:matches?) && obj.respond_to?(:description)
- end
-
- def check_args(args)
- return true if @expected_params.nil?
- return true if @expected_params == args
- return constraints_match?(args)
- end
-
- def constraints_match?(args)
- return false if args.length != @expected_params.length
- @expected_params.each_index { |i| return false unless @expected_params[i].matches?(args[i]) }
- return true
- end
-
- end
-
- end
-end
+++ /dev/null
-module Spec
- module Mocks
- class ErrorGenerator
- attr_writer :opts
-
- def initialize(target, name)
- @target = target
- @name = name
- end
-
- def opts
- @opts ||= {}
- end
-
- def raise_unexpected_message_error(sym, *args)
- __raise "#{intro} received unexpected message :#{sym}#{arg_message(*args)}"
- end
-
- def raise_unexpected_message_args_error(expectation, *args)
- expected_args = format_args(*expectation.expected_args)
- actual_args = args.empty? ? "(no args)" : format_args(*args)
- __raise "#{intro} expected #{expectation.sym.inspect} with #{expected_args} but received it with #{actual_args}"
- end
-
- def raise_expectation_error(sym, expected_received_count, actual_received_count, *args)
- __raise "#{intro} expected :#{sym}#{arg_message(*args)} #{count_message(expected_received_count)}, but received it #{count_message(actual_received_count)}"
- end
-
- def raise_out_of_order_error(sym)
- __raise "#{intro} received :#{sym} out of order"
- end
-
- def raise_block_failed_error(sym, detail)
- __raise "#{intro} received :#{sym} but passed block failed with: #{detail}"
- end
-
- def raise_missing_block_error(args_to_yield)
- __raise "#{intro} asked to yield |#{arg_list(*args_to_yield)}| but no block was passed"
- end
-
- def raise_wrong_arity_error(args_to_yield, arity)
- __raise "#{intro} yielded |#{arg_list(*args_to_yield)}| to block with arity of #{arity}"
- end
-
- private
- def intro
- @name ? "Mock '#{@name}'" : @target.inspect
- end
-
- def __raise(message)
- message = opts[:message] unless opts[:message].nil?
- Kernel::raise(Spec::Mocks::MockExpectationError, message)
- end
-
- def arg_message(*args)
- " with " + format_args(*args)
- end
-
- def format_args(*args)
- return "(no args)" if args.empty? || args == [:no_args]
- return "(any args)" if args == [:any_args]
- "(" + arg_list(*args) + ")"
- end
-
- def arg_list(*args)
- args.collect do |arg|
- arg.respond_to?(:description) ? arg.description : arg.inspect
- end.join(", ")
- end
-
- def count_message(count)
- return "at least #{pretty_print(count.abs)}" if count < 0
- return pretty_print(count)
- end
-
- def pretty_print(count)
- return "once" if count == 1
- return "twice" if count == 2
- return "#{count} times"
- end
-
- end
- end
-end
+++ /dev/null
-module Spec
- module Mocks
- class MockExpectationError < StandardError
- end
-
- class AmbiguousReturnError < StandardError
- end
- end
-end
-
+++ /dev/null
-class Object
- include Spec::Mocks::Methods
-end
+++ /dev/null
-module Spec
- module Mocks
-
- class BaseExpectation
- attr_reader :sym
-
- def initialize(error_generator, expectation_ordering, expected_from, sym, method_block, expected_received_count=1, opts={})
- @error_generator = error_generator
- @error_generator.opts = opts
- @expected_from = expected_from
- @sym = sym
- @method_block = method_block
- @return_block = nil
- @actual_received_count = 0
- @expected_received_count = expected_received_count
- @args_expectation = ArgumentExpectation.new([AnyArgsConstraint.new])
- @consecutive = false
- @exception_to_raise = nil
- @symbol_to_throw = nil
- @order_group = expectation_ordering
- @at_least = nil
- @at_most = nil
- @args_to_yield = []
- end
-
- def expected_args
- @args_expectation.args
- end
-
- def and_return(*values, &return_block)
- Kernel::raise AmbiguousReturnError unless @method_block.nil?
- case values.size
- when 0 then value = nil
- when 1 then value = values[0]
- else
- value = values
- @consecutive = true
- @expected_received_count = values.size if !ignoring_args? &&
- @expected_received_count < values.size
- end
- @return_block = block_given? ? return_block : lambda { value }
- # Ruby 1.9 - see where this is used below
- @ignore_args = !block_given?
- end
-
- # :call-seq:
- # and_raise()
- # and_raise(Exception) #any exception class
- # and_raise(exception) #any exception object
- #
- # == Warning
- #
- # When you pass an exception class, the MessageExpectation will
- # raise an instance of it, creating it with +new+. If the exception
- # class initializer requires any parameters, you must pass in an
- # instance and not the class.
- def and_raise(exception=Exception)
- @exception_to_raise = exception
- end
-
- def and_throw(symbol)
- @symbol_to_throw = symbol
- end
-
- def and_yield(*args)
- @args_to_yield << args
- self
- end
-
- def matches(sym, args)
- @sym == sym and @args_expectation.check_args(args)
- end
-
- def invoke(args, block)
- @order_group.handle_order_constraint self
-
- begin
- Kernel::raise @exception_to_raise unless @exception_to_raise.nil?
- Kernel::throw @symbol_to_throw unless @symbol_to_throw.nil?
-
- if !@method_block.nil?
- default_return_val = invoke_method_block(args)
- elsif @args_to_yield.size > 0
- default_return_val = invoke_with_yield(block)
- else
- default_return_val = nil
- end
-
- if @consecutive
- return invoke_consecutive_return_block(args, block)
- elsif @return_block
- return invoke_return_block(args, block)
- else
- return default_return_val
- end
- ensure
- @actual_received_count += 1
- end
- end
-
- protected
-
- def invoke_method_block(args)
- begin
- @method_block.call(*args)
- rescue => detail
- @error_generator.raise_block_failed_error @sym, detail.message
- end
- end
-
- def invoke_with_yield(block)
- if block.nil?
- @error_generator.raise_missing_block_error @args_to_yield
- end
- @args_to_yield.each do |args_to_yield_this_time|
- if block.arity > -1 && args_to_yield_this_time.length != block.arity
- @error_generator.raise_wrong_arity_error args_to_yield_this_time, block.arity
- end
- block.call(*args_to_yield_this_time)
- end
- end
-
- def invoke_consecutive_return_block(args, block)
- args << block unless block.nil?
- value = @return_block.call(*args)
-
- index = [@actual_received_count, value.size-1].min
- value[index]
- end
-
- def invoke_return_block(args, block)
- args << block unless block.nil?
- # Ruby 1.9 - when we set @return_block to return values
- # regardless of arguments, any arguments will result in
- # a "wrong number of arguments" error
- if @ignore_args
- @return_block.call()
- else
- @return_block.call(*args)
- end
- end
- end
-
- class MessageExpectation < BaseExpectation
-
- def matches_name_but_not_args(sym, args)
- @sym == sym and not @args_expectation.check_args(args)
- end
-
- def verify_messages_received
- return if ignoring_args? || matches_exact_count? ||
- matches_at_least_count? || matches_at_most_count?
-
- generate_error
- rescue Spec::Mocks::MockExpectationError => error
- error.backtrace.insert(0, @expected_from)
- Kernel::raise error
- end
-
- def ignoring_args?
- @expected_received_count == :any
- end
-
- def matches_at_least_count?
- @at_least && @actual_received_count >= @expected_received_count
- end
-
- def matches_at_most_count?
- @at_most && @actual_received_count <= @expected_received_count
- end
-
- def matches_exact_count?
- @expected_received_count == @actual_received_count
- end
-
- def generate_error
- @error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
- end
-
- def with(*args, &block)
- @method_block = block if block
- @args_expectation = ArgumentExpectation.new(args)
- self
- end
-
- def exactly(n)
- set_expected_received_count :exactly, n
- self
- end
-
- def at_least(n)
- set_expected_received_count :at_least, n
- self
- end
-
- def at_most(n)
- set_expected_received_count :at_most, n
- self
- end
-
- def times(&block)
- @method_block = block if block
- self
- end
-
- def any_number_of_times(&block)
- @method_block = block if block
- @expected_received_count = :any
- self
- end
-
- def never
- @expected_received_count = 0
- self
- end
-
- def once(&block)
- @method_block = block if block
- @expected_received_count = 1
- self
- end
-
- def twice(&block)
- @method_block = block if block
- @expected_received_count = 2
- self
- end
-
- def ordered(&block)
- @method_block = block if block
- @order_group.register(self)
- @ordered = true
- self
- end
-
- def negative_expectation_for?(sym)
- return false
- end
-
- protected
- def set_expected_received_count(relativity, n)
- @at_least = (relativity == :at_least)
- @at_most = (relativity == :at_most)
- @expected_received_count = case n
- when Numeric
- n
- when :once
- 1
- when :twice
- 2
- end
- end
-
- end
-
- class NegativeMessageExpectation < MessageExpectation
- def initialize(message, expectation_ordering, expected_from, sym, method_block)
- super(message, expectation_ordering, expected_from, sym, method_block, 0)
- end
-
- def negative_expectation_for?(sym)
- return @sym == sym
- end
- end
-
- end
-end