Skip to content

Instantly share code, notes, and snippets.

@cflipse
Created June 16, 2014 14:21
Show Gist options
  • Save cflipse/07a5cb0b5140bec7d6ef to your computer and use it in GitHub Desktop.
Save cflipse/07a5cb0b5140bec7d6ef to your computer and use it in GitHub Desktop.
require "active_model/lint"
require "test/unit/assertions"
shared_examples_for "ActiveModel" do
include ActiveModel::Lint::Tests
include Test::Unit::Assertions
before { @model = subject }
ActiveModel::Lint::Tests.public_instance_methods.map(&:to_s).grep(/^test/).each do |test|
example test.gsub("_", " ") do |example|
send test
end
end
end
2) User it should behave like ActiveModel test to param
Failure/Error: send test
NoMethodError:
undefined method `assertions' for #<RSpec::ExampleGroups::User::ItShouldBehaveLikeActiveModel:0x007f6d49e30450>
Shared Example Group: "ActiveModel" called from ./spec/models/user_spec.rb:6
# ./spec/support/active_model_lint.rb:12:in `block (3 levels) in <top (required)>'
@trliner
Copy link

trliner commented Mar 1, 2015

I was running into the same error while upgrading Rails from 4.0 to 4.1. I was able to get around it by adding attr_accessor :assertions and self.assertions = 0 like so:

shared_examples_for 'ActiveModel' do
  ...

  attr_accessor :assertions

  before do
    @model = subject
    self.assertions = 0
  end

  ...
end

Did you come up with a more elegant solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment