Can VCR be used to record HTTP sessions run via executable as a test case ?

17 views
Skip to first unread message

otheus uibk

unread,
Jul 21, 2016, 7:02:00 AM7/21/16
to VCR Rubygem
I was just now referred to VCR to help do black-box / integration testing. What I mean by black box is that the thing I am testing is relatively opaque. This is as opposed to the typical rspec testing which can be considered 'white' or 'grey' box testing, whereby details of the implementation (ie, classes, definitions) are known. In my case, I want to build a test suite that the entire command-line application (written in Ruby) works correctly after refactoring. The refactoring will change the internal classes and definitions, and thus grey/whitebox testing is inappropriate. 

That ruby program does HTTP gets and posts to a server, whose data can be statically defined as test cases. In theory, I could build within RSpec, an HTTP listener/handler that starts up and listens on an arbitrary port, configure the client (program to be tested) to use that port/URL, and manually provide mock results. Or maybe VCR helps me do this?

Consider this rspec snippet:

it "should read the correct yaml from the test http server" do
    require 'open3'
    write_settings(Settings) # set up program's configuration data
    (sout,serr,status) = Open3.capture3(ENV, "ruby #{$target} #{$program_arguments}")
    expect(serr).to eql ""
    expect(status.exitstatus).to eql 0
    hash = YAML.load(sout)
end

The program's output should be well-formatted YAML code.

The program does both a POST and a GET. In one mode, it will do multiple GET operations.

Reply all
Reply to author
Forward
0 new messages