-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewriting Queryable#query specs to test behavior #33
Conversation
Specs for `Queryable#query` tested internal implementation rather than behavior, this caused issues for classes mixing in `Queryable`, but delegating `#query` to some collaborator. See, e.g. ActiveTriples/ActiveTriples#169. This tests the contract directly, instead.
The introductory comment to RDF::Queryable says:
So, they should be protected. |
For ActiveTriples using the delegate pattern it seems that delegating query to RDF::Graph is reasonable. For classes which extend Queryable, they should implement query_execute and query_pattern, which might just be shims for redirect to the RDF::Graph implementations in this case, but delegating query seems to do the trick. Otherwise, I'm not sure if moving the query_pattern/query_execute behavior under the query specs is necessary, but I don't see it causing any harm. It could be extracted into common behavior which is used for both query_pattern/execute and query. |
I guess the way I'm seeing this is that The specs, however, focus on testing the protected methods, and test the public one only indirectly. So for I allow I may be missing something here. That the methods are protected rather than private suggests that other instances may be intended to use them; but I don't see where that actually happens or why they wouldn't just use Hopefully that helps clarify where I'm coming from. :) |
That they're protected says that it is allowed/intended for concrete implementations extending Queryable to implement them, and the specs insure that such implementations perform as expected. However, it's reasonable for concrete implementation to implement query instead, so having the behavior tested for both #query_execute/pattern and #query makes sense. |
Rewriting Queryable#query specs to test behavior
While thinking about the above, I considered a couple of things:
|
👍 |
`Queryable#query` lets users of the mixin implement `#query_execute` and `#query_pattern` as an easy path to its interface. Tests for this were removed from the shared examples by ruby-rdf/rdf-spec#33. This reintroduces them as tests on the implementation.
#33 created some duplicate tests; this refactors by moving them into a shared example set. Additionally, it skips specs for `#query_pattern` and `#query_execute` if they are not defined by the `Queryable`. This allows implementations to fulfill the `#query` interface directly, if desired.
Specs for
Queryable#query
tested internal implementation rather thanbehavior, this caused issues for classes mixing in
Queryable
, butdelegating
#query
to some collaborator. See,e.g. ActiveTriples/ActiveTriples#169.
This tests the contract directly, instead.
Before merging, note that these tests are cribbed from
#query_pattern
and#query_execute
. Both are protected, but it's not clear to me whether they are part of the required interface forQueryable
(i.e., should they be private?).Depending on the answer, we should either remove the tests, or merge them into shared examples to deduplicate.