Skip to content

Instantly share code, notes, and snippets.

@simonmorley
Created September 24, 2014 10:40
Show Gist options
  • Save simonmorley/57dd35abda1889bf3868 to your computer and use it in GitHub Desktop.
Save simonmorley/57dd35abda1889bf3868 to your computer and use it in GitHub Desktop.
Testing the gubbins
Here is a dummy gubbins.rb
#!/usr/bin/ruby
class Gubbins
def initialize
@api_url = "https://api.polkaspots.com"
end
def run
interface_name
end
def interface_name
# would usually output eth1 and will fail if we run this
# So we stub it for our tests
`/uci/i-will-fail.sh`
end
end
And now the spec file
require File.expand_path("../../gubbins", __FILE__)
describe "Main Tests for Gubbins" do
before(:each) do
@gubbins = instance_double("Gubbins")
allow(@gubbins).to receive(:interface_name) { "eth1" }
end
it "should test we have mocked the interface name" do
expect(@gubbins.interface_name).to eq 'eth1'
end
it "should run gubbins and output eth1" do
gubbins = Gubbins.new
allow(gubbins).to receive(:interface_name) { "eth1" }
expect(gubbins.run).to eq 'eth1'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment