0

How do I write a test to ensure that ::base_uri is part of the class definition, for MyClass? Sample code follows.

require 'httparty'

class MyClass
  include HTTParty

  base_uri 'https://www.google.com'
end

describe MyClass do
  it "should call base_uri" do
    MyClass.should_receive(:base_uri)
    MyClass.new
  end
end
nc.
  • 7,179
  • 5
  • 28
  • 38

1 Answers1

1

First of all, i recommend you when in doubt take a look on how your gem implements/tests the code youre calling. So this is how HTTParty's #base_uri code is tested. And then you can write.

  it 'should have this base uri' do
     MyClass.base_uri.should == 'my_base_uri'
  end

I don't think that testing that the #base_uri is called on your class will give you the warranty that it will work as expected. I prefer to test if the value is really filled, instead of the method call.

Guilherme
  • 1,126
  • 9
  • 17