Inspect STDERR in a story

Hi

I have a story step that looks like this:

When /(the user|then) runs “migrate (.*)”/ do |_, args|
cd project_dir do
@output = #{migrate} #{args}
end
@output_lines = @output.split("\n")
end

Which is fine for testing STDOUT but not STDERR. I don’t want to
redirect STDERR to STDOUT because then the story can’t prove that
error messages are displayed separately (although the specs would)

Any hints? :slight_smile:

Thanks
Ashley


http://www.patchspace.co.uk/

On Sat, Apr 12, 2008 at 11:54 AM, Ashley M.
[email protected] wrote:

Which is fine for testing STDOUT but not STDERR. I don’t want to
redirect STDERR to STDOUT because then the story can’t prove that
error messages are displayed separately (although the specs would)

How about something along the lines

cd project_dir do
@stdout, @stdterr = capture_outputs("#{migrate} #{args}")
end


def capture_outputs(cmd)
stderr_log = “/tmp” + “/#{$0}-{$$}.log”
out = cmd 2> #{stderr_log}
err = File.read(stderr_log) if File.exist? stderr_log
[out, err]
end

Totally untested, but hopefully you get the idea?


“One day, when he was naughty, Mr Bunnsy looked over the hedge into
Farmer Fred’s field and it was full of fresh green lettuces. Mr
Bunnsy, however, was not full of lettuces. This did not seem fair.”
– Terry Pratchett, Mr. Bunnsy Has An Adventure

On 12 Apr 2008, at 11:51, Edvard M. wrote:

err = File.read(stderr_log) if File.exist? stderr_log
[out, err]

end

Totally untested, but hopefully you get the idea?

Yeah! Don’t know why I didn’t think of just sending stderr to a log
file myself…

Thanks
Ashley


http://www.patchspace.co.uk/

On Sat, Apr 12, 2008 at 4:17 PM, Ashley M.
[email protected] wrote:

Yeah! Don’t know why I didn’t think of just sending stderr to a log
file myself…

…because you’re likely smart enough to avoid using file as a
temporary variable whenever possible :slight_smile:

First off, using the method similar to above would break bad if you
run tests in parallel inside the same process. But
that’s easy enough to fix (eg. add some random stuff). No, I don’t run
stuff in parallel yet because deep_test is not ready for RSpec yet,
but in the future, I hope I’ll be able to.


“One day, when he was naughty, Mr Bunnsy looked over the hedge into
Farmer Fred’s field and it was full of fresh green lettuces. Mr
Bunnsy, however, was not full of lettuces. This did not seem fair.”
– Terry Pratchett, Mr. Bunnsy Has An Adventure

On 14 Apr 2008, at 14:36, Edvard M. wrote:

…because you’re likely smart enough to avoid using file as a
temporary variable whenever possible :slight_smile:

Ha, I don’t know… I haven’t checked Daily WTF lately to see if any
of my code has made it on there :slight_smile:

First off, using the method similar to above would break bad if you
run tests in parallel inside the same process. But
that’s easy enough to fix (eg. add some random stuff). No, I don’t run
stuff in parallel yet because deep_test is not ready for RSpec yet,
but in the future, I hope I’ll be able to.

Well I’m already using something similar - the stories make a
temporary directory with a random name to run the tool inside, so I
guess a statically named stderr.out file would be ok in there. It’s
just that using a file to capture half the output of a command seems
really ugly.

I had checked out deeptest and it looks pretty cool. Fingers crossed
it will support RSpec soon

Ashley


http://www.patchspace.co.uk/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs