-
-
Notifications
You must be signed in to change notification settings - Fork 358
raise ArgumentError if object cannot be proxied #1357
Conversation
@pirj can you take a look? however I cannot understand why travis CI failed, I will try to reproduce with the given ruby versions on localhost to identify what's wrong |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this, some feedback
thanks @JonRowe will update |
I couldn't find changelog for ruby 2.0.0, but surely in previous ruby versions symbols where not frozen by default, that's why travis was failing for older ruby versions. irb(main):001:0> RUBY_VERSION
=> "1.9.3"
irb(main):002:0> :subject.frozen?
=> false |
@zhisme If you wish to target this off |
@JonRowe any idea of travis-ci build error?
|
Thanks, don't worry about Travis we're phasing it out as its become really unreliable since they essentially dropped open source. |
raise ArgumentError if object cannot be proxied
raise ArgumentError if object cannot be proxied
raise ArgumentError if object cannot be proxied
Hi, I've just pulled this in and am getting test failures in areas where I've stubbed destroyed ActiveRecord objects, which freezes them. I'm not understanding why rspec should refuse to stub these objects and I'm not seeing any explanation here, but hoping someone could explain it to me? |
@keegangroth Frozen objects cannot be modified, which is required to stub them. |
OK, I think there's something specific to ActiveRecord here, because old and new versions of rspec both throw errors for Hash objects. I'll see if I can come up with a trivial example for activerecord. Here's an example with Hash that behaves more or less the same both before and after this change.
|
The behavior has definitely changed for destroyed ActiveRecord Models. I don't know what makes their version of freezing different from hash. Trivial example using rails to do the db setup:
result on rspec-mocks 3.10.0:
result on rspec-mocks 3.10.1:
Probably warrants it's own (new) issue? Kind of niche, but it's now a major headache to test certain kinds of functionality in active record (I actually haven't yet figured out the work around for my particular case). |
The activerecord models are not really frozen, they override that method and delegates it to the attributes, which are frozen when the record is destroyed. https://github.com/rails/rails/blob/914caca2d31bd753f47f9168f2a375921d9e91cc/activerecord/lib/active_record/core.rb#L618 def frozen?
@attributes.frozen?
end I'm not sure if there's a better way to check the real frozen status for the model itself. |
Feel free to raise that as a bug with the Rails team, if an object isn't actually frozen it probably shouldn't return that it is. |
I don't mind raising this with rails, but does any one really think they're going to change their interface for this? Seems like there are some pretty simple alternatives here in rspec such as just catching the FrozenError (which looks like it was always raised in these cases) and re-raising with the appropriate message. |
They might not be aware they are breaking an expected Ruby behaviour, they might have a reason for it being the way it is, I don't know, but currently these objects don't behave as they should by the standards Ruby sets, its worth finding out if this is blocking you, equally If you'd like to create an alternative implementation for this warning feel free. |
#1401 for what it's worth |
Fails like this with rspec-mocks >=3.10.1 because we set logger to false, and false is frozen. 1) InfluxDB::Logging when logging is disabled does not log Failure/Error: expect(InfluxDB::Logging.logger).not_to receive(:debug) ArgumentError: Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations. # ./spec/influxdb/logging_spec.rb:42:in `block (3 levels) in <top (required)>' # ./spec/influxdb/logging_spec.rb:19:in `block (2 levels) in <top (required)>' Related links - rspec/rspec-mocks#1357 - https://github.com/rspec/rspec-mocks/blob/v3.10.2/Changelog.md
raise ArgumentError if object cannot be proxied --- This commit was imported from rspec/rspec-mocks@2d12304.
This commit was imported from rspec/rspec-mocks@cfb2e7f.
raise ArgumentError if object cannot be proxied --- This commit was imported from rspec/rspec-mocks@e76b942.
This commit was imported from rspec/rspec-mocks@144b2fd.
raise ArgumentError if object cannot be proxied --- This commit was imported from rspec/rspec-mocks@bee61ba.
This commit was imported from rspec/rspec-mocks@6704f5a.
fixes #1356