-
Notifications
You must be signed in to change notification settings - Fork 125
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
Can subject
be called when one of the API methods is called?
#47
Comments
@PikachuEXE do you have an example of what you are trying to do? |
subject do
call_action
controller
end
let(:call_action) do
get :index
end
it {expect_json_types(pagination: :object)}
it {expect_json_types("data", {posts: :array_of_objects})}
it {expect_json_sizes("data", {listings: 1})} |
I think using
In many cases, when you're using the shorthand test syntax Also: I think using something like
is cleaner and more readable than the blocks you're using up top. With properly nested context blocks, you should only have to write that once and have it accessible by all your tests that need them. |
I agree. I don't think that is what |
Regardless of how I use / abuse |
Its not that we are intentionally not calling the Normally RSpec expectation take both the Is there a use-case other than the one above where it would make sense to do so? |
I will find my own way to solve this then. |
No problem. You can try wrapping the methods in your [:expect_json_types, :expect_json, :expect_json_keys, :expect_status, :expect_header, :expect_header_contains].each do |method_name|
method = instance_method(method_name)
define_method(method_name) do |*args, &block|
subject()
method.bind(self).call(*args, &block)
end
end |
I am already do the same thing (with another way). |
Ok no problem! |
I have many context group for my controller spec.
But I always needs to add the
get /path
at the very end BUT in before hookI just tried put the
get
insubject
to avoid the repeated call, it works withjson_spec
since they implement with custom matcher.But it doesn't work with this gem, with error complaining about missing
json_body
, meaningsubject
is not called.Is there a way to make it call
subject
when one of the API methods (e.g.expect_json_types
) is called?The text was updated successfully, but these errors were encountered: