Hi Jack
Sorry for the delayed response but..
let(:perform) { get … }
Works for this, performs take a block and cache the result the equivalent (ish)
of
def perform
@result ||= begin
get …
end
end
You could also just define a method if you don’t want caching or want to rescue
exceptions etc.
Cheers
Jon Rowe
---------------------------
[email protected]
jonrowe.co.uk
On 12 July 2020 at 23:05, Jack Royal-Gordon wrote:
> Jon, I think I understand what you’re talking about (did a little reading
> about aggrregating failures), but that’s not really the issue I’m dealing
> with. I’m dealing with multiple tests that should all succeed, but the syntax
> available is such that I’m not sure how to not repeat the same request in two
> different places in my code and check all of the conditions. This is more of
> a DSL question that a functionality question. One of the conditions requires
> that I wrap the request with an "expect …to raise_error” while the other test
> requires that I test a side effect of the request “expect(response.status).to
> eq 404”. Those two tests handle the request itself differently and therefore
> cannot be aggregated into one block where the request only appears once. The
> best I can do to DRY up the request is to create a Proc from it and invoke
> the Proc twice. What I’m looking for is something like the following:
>
> > describe “Request for invalid record should fail” do
> > before(:each) do
> > get …
> > end
> >
> > it “should raise an error” do
> > expect it.to (http://it.to) raise_error(ActiveRecord::RecordNotFound)
> > end
> >
> > it “should redirect to the list” do
> > expect(response).to redirect_to(widget_index_path)
> > end
> > end
>
>
> I think the best I can do is:
>
> > describe “Request for invalid record should fail” do
> > @req_action = Proc { get … }
> >
> > it “should raise an error” do
> > expect {@req_action.call (http://action.call)}t.to (http://t.to)
> > raise_error(ActiveRecord::RecordNotFound)
> > end
> >
> > it “should redirect to the list” do
> > @req_action.call (http://action.call)
> > expect(response).to redirect_to(widget_index_path)
> > end
> > end
> >
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/dejalu-217-ddac54a0-d57a-405f-91a1-1bf75ade4875%40jonrowe.co.uk.