Caching values between examples

4 views
Skip to first unread message

sas...@contentful.com

unread,
Jul 2, 2013, 4:24:31 AM7/2/13
to rs...@googlegroups.com
Hello everybody,

I'm a long time rspec user, mostly within Rails, but now using rspec for the first time for API integration tests. I'd appreciate your help on this. My code looks like this:

describe "Request" do
  let(:path) { path }
  let(:headers) { headers } 
  let(:response) { do_request(path, headers) }

  describe "success" do
    it "should have an ETag header" do
      response.headers[:etag].should(be_present) unless response.code == 204
    end

    it "should have a Cache-Control header" do
      response.headers[:cache_control].should be_present
    end

   # MORE EXAMPLES

   it_behaves_like "any GET request" # should create the response again, with invalid headers
  end
end

Is there a way to cache response between some examples? The code is actually more complicated and creating several requests, for example with different Content Type headers, so I don't just want to execute the request once in before(:all). The goal would be to speed up some of the examples that are in the "success" block and could reuse the response from the outter group. The code now is very slow, as the whole resource environment needs to be set up and teared down for each single example.

I tried looking into using a before(:all) block, but it's telling me that I should not use let within this block.

Thanks,
Sascha
Reply all
Reply to author
Forward
0 new messages