Readme.md.mountain_berry_fields in surrogate-0.6.1 vs Readme.md.mountain_berry_fields in surrogate-0.6.2
- old
+ new
@@ -409,11 +409,11 @@
Assert that your mock has the **same interface** as your real class.
This will fail if the mock inherits methods which are not on the real class. It will also fail
if the real class has any methods which have not been defined on the mock or inherited by the mock.
-Presently, it will ignore methods defined directly in the mock (as it generally considers them to be helpers).
+Presently, it will ignore methods defined directly in the mock (as it considers them to be helpers).
In a future version, you will be able to tell it to treat other methods
as part of the API (will fail if they don't match, and maybe record their values).
```ruby
<% test 'substitutability example', with: :rspec, context: 'generic it block' do %>
@@ -427,34 +427,29 @@
define(:initialize) { |id| @id = id }
define :id
end
# they are the same
-MockUser.should substitute_for User
+User.should substitute_for MockUser
-# mock has extra method
+# they differ
MockUser.define :name
-MockUser.should_not substitute_for User
+User.should_not substitute_for MockUser
-# the same again via inheritance
-class UserWithName < User
- def name()end
-end
-MockUser.should substitute_for UserWithName
-
-# real class has extra methods
-class UserWithNameAndAddress < UserWithName
- def address()end
-end
-MockUser.should_not substitute_for UserWithNameAndAddress
-
-# signatures don't match
+# signatures don't match (you can turn this off by passing `types: false` to substitute_for)
class UserWithWrongSignature
def initialize()end # no id
def id()end
end
-MockUser.should_not substitute_for UserWithWrongSignature
+UserWithWrongSignature.should_not substitute_for MockUser
+
+# parameter names don't match
+class UserWithWrongParamNames
+ def initialize(name)end # real one takes an id
+ def id()end
+end
+UserWithWrongParamNames.should_not substitute_for MockUser, names: true
<% end %>
```
Sometimes you don't want to have to implement the entire interface.
In these cases, you can assert that the methods on the mock are a **subset**
@@ -473,14 +468,14 @@
define(:initialize) { |id| @id = id }
define :id
end
# doesn't matter that real user has a name as long as it has initialize and id
-MockUser.should substitute_for User, subset: true
+User.should substitute_for MockUser, subset: true
# but now it fails b/c it has no address
MockUser.define :address
-MockUser.should_not substitute_for User, subset: true
+User.should_not substitute_for MockUser, subset: true
<% end %>
```
Blocks