mercredi 2 mars 2016

How would I test a ruby method that only calls a system command?

After looking at:

How do I stub/mock a call to the command line with rspec?

The answer provided is:

require "rubygems"
require "spec"

class Dummy
  def command_line
    system("ls")
  end
end

describe Dummy do
  it  "command_line should call ls" do
    d = Dummy.new
    d.should_receive("system").with("ls")
    d.command_line
  end
end

My question is: How does that actually test anything?

By making a method to that says "call the ls command on the system", and then writing a test that says "my method should call the ls command on the system", how does that provide any benefit?

If the method were to change, I would have to change the test as well, but I'm not sure I see the added benefit.

Aucun commentaire:

Enregistrer un commentaire