I have the following test:
let(:client) { Descat::Client.new }
describe 'poblacio' do
it 'should set format correctly' do
client.poblacio('v1','json','dades')
expect (client.instance_variable_get(:format)).to eq('json')
end
end
And I have the following code that is being tested:
module Descat
class Client
BASE_URL = 'http://api.idescat.cat/'
def initialize(attributes = {})
attributes.each do |attr, value|
self.send("#{attr}=", value)
end
end
def poblacio(version, format, operation, *args)
@format = format
end
end
end
WHen running the tests I keep getting '
Failure/Error: expect (client.instance_variable_get(:format)).to eq('json')
NameError:
But, changing the name doesnt help.
'
To use instance_variable_get
you have to provide the name starting with "@"
. In your case:
client.instance_variable_get('@format')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With