Module: RSpec::Rails::Mocks::ActiveModelInstanceMethods

Defined in:
lib/rspec/rails/mocks.rb

Instance Method Summary collapse

Instance Method Details

#as_new_recordObject

Stubs ‘persisted?` to return false and `id` to return nil

Returns:

  • self



14
15
16
17
18
# File 'lib/rspec/rails/mocks.rb', line 14

def as_new_record
  self.stub(:persisted?) { false }
  self.stub(:id) { nil }
  self
end

#persisted?Boolean

Returns true by default. Override with a stub.

Returns:

  • (Boolean)


21
22
23
# File 'lib/rspec/rails/mocks.rb', line 21

def persisted?
  true
end

#respond_to?(message, include_private = false) ⇒ Boolean

Returns false for names matching /_before_type_cast$/, otherwise delegates to super.

Returns:

  • (Boolean)


27
28
29
# File 'lib/rspec/rails/mocks.rb', line 27

def respond_to?(message, include_private=false)
  message.to_s =~ /_before_type_cast$/ ? false : super
end