thoughtbot/shoulda-matchers — pull request #404 by fj (2013-12-16 17:46:37+00:00)
Title: Updates RailsShim to be explicit about which Rails pieces it needs

RailsShim currently checks against a Rails version to decide how to respond to certain functionality, but this is not a good idea. `shoulda-matchers` can be used without Rails -- for instance, in a Rack or Padrino application that happens to use ActiveModel models.

Without this patch, a Rack application that happens to use an ActiveModel model but which doesn't actually use Rails will fail if it uses anything that calls anything that hits RailsShim. For example, consider this trivial example:

```ruby
# dummy_model.rb
require 'active_model'

class User
include ActiveModel::Model
attr_accessor :password
attr_accessor :password_confirmation
end

# dummy_model_spec.rb
require 'spec_helper'

describe DummyModel do
it { should validate_confirmation_of :password }
end
```

This will fail, since `validate_confirmation_of` checks RailsShim:

```ruby
1) DummyModel should require password_confirmation to match password
Failure/Error: it { should validate_confirmation_of :password }
NameError:
uninitialized constant Shoulda::Matchers::RailsShim::Rails
# ./spec/models/dummy_model_spec.rb:4:in `block (2 levels) in '
```

It's better if, instead, these shim methods only check the versions of the pieces they need, rather than creating an implicit dependency on Rails as a whole.