Why there are Duplicate methods in Rest-assured framework like response.statusCode() and response.getStatusCode() ?
There are multiple duplicate methods in Rest-assured like : response.getBody() and response.body(), response.getBody().asString() and response.asString(), response.statusLine() and response.getStatusLine(), response.getHeader("Content-Type") and response.header("Content-Type"), and response.contentType() and response.getContentType(), etc.
What is the reason behind designing multiple methods for same purpose ?
Related
So I'm learning RoR and I have to 3 services that calls an API with the same structure and i want to know if i can do it with a parent class and then work with the parent class to save code.
Thanks!
Yes. This may work if you can define a method with fewer arguments, which builds that structure for the API call.
Approaches are:
Put that common method in a base class which the other classes inherit from.
Put that common method in a module as a mix in.
Write a class to handle the call to the API, which builds the structure.
I don't think you have an "isa" relationship from the sound of it. So unless you do, 2 is preferred to 1. You can only inherit from one class, so mixins are more flexible.
Approach 3 is a good idea. You can have internal methods for the hostname and other constants for your API call.
This can be combined with the other approaches as you can use the Aggregation pattern to aggregate the API object in the other classes. That might or might not make sense. It might be just as well as the other classes have methods which instantiate the class in approach 3 and call it.
Currently I'm working on a gem, which overrides ActiveRecords where. By working on that, I stumbled on two different find_by implementations. One is in the core and it uses some kind of cache, whereas the one from the FinderMethods module calls where directly. What is the difference between these two implementations? When is which used?
I think it's that way: When you use something like this:
User.find_by(...)
The ActiveRecord::Core#find_by is called, as the Core is included into Base from which you inherit.
But if you do something like:
User.first.products.find_by(...)
The ActiveRecord::Relation (includes FinderMethods here) will call FinderMethods#find_by
I don't know why this is implemented like that, but I'm sure there's a reason for this.
I would like to Verify that an expected method is called with the correct parameters in Swift in unit-testing. This was very easily done in Objective-C using the OCMock framework. You could do a combination of partialMocking and running OCMExpect/Verify to assert code paths with the right parameters were being called. Any idea how to do something like this in Swift?
Swift doesn't support reflection, so traditional mocking libraries aren't feasible. Instead, you need to create your own mock. There are at least two approaches to do this.
Create a testing subclass of the class under test. This is partial mocking. Avoid this if possible.
Use an interface instead of a class. Create a testing implementation of the interface.
Hand-crafted mocks aren't hard. You want to
Count the number of calls to a method
Capture its arguments
Simulate its return value
It is a lot of boilerplate. There are libraries out there that can auto-generate this code.
When I'm looking for a method of an object that I don't know, I used Xcode's autocompletion. The problem for me is that there are tons of methods that appear and most of them are inherited methods that make it harder for me to find methods proper to the object I'm working on.
Is there a way (other than going to the declaration code of the object) to make it clearer like an option to sort the methods first by inherited/locals and then alphabetically?
I would like to wrap Domain class's dynamic methods like save() get*() with an Around advice (possibly using Spring AOP). The idea is to intercept these methods and take the decision to apply them or not. As part of it I would also like to save the return value in case the method is executed.
This logic needs to be performed as part of a plugin so that existing source code is not affected. Any help in this regard is appreciated.