No commit activity in last 3 years
No release in over 3 years
Provides the ActiveModel::Lint::Tests for test-unit or minitest an RSpec shared example.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Code Climate

ActiveModel Lint for RSpec

Form objects are a great way to move logic out of your controllers and models while ensuring that classes focus on their core responsibility. When you implement ActiveModel behavior in a class, this gem provides a one-line test to ensure that your class implements required behavior such as the #persisted? method that is required for your form object to function within a Rails form.

The code here was shamelessly cribbed from an example published by Mike Gehard at Pivotal Labs. It appears in this blog post. This gem merely puts the shared example into a gem for easy distribution into your project.

Example

Just one line to attach the shared example to your spec.

describe MyFormObjectClass do

  it_behaves_like 'an ActiveModel'

end

Then run your specs:

MyFormObjectClass
  behaves like an ActiveModel
    test persisted?
    test to param
    test to partial path
    test to key
    test model naming
    test errors aref

Installation

###Rails and other Bundler projects

Add the gem to your test group.

group :test do
  gem "active_model_lint-rspec"
end

Other Ruby projects

Require the gem after RSpec has been required.

require 'rspec'
require 'active_model_lint-rspec'

Further reading

Credits

ActiveModelLint-RSpec is packaged by Geoff Harcourt. It was built using code from a blog post written by Mike Gehard.

License

ActiveModelLint-Rspec is free software, and may be redistributed under the terms of the MIT license.