Reputation: 2046
I'm trying to write some concise RSpec tests. The tests are as follows:
require 'spec_helper'
describe Video::Base do
subject { Video::Base }
its(:base_uri) { should match(/api\.wistia\.com/) }
its(:base_uri) { should match(/https/) }
its(:format) { should == :json }
describe :default_params do
its([:api_password]) { should_not be_nil }
end
end
The tests are looking quite nice, but the describe :default_params
fails. I know that RSpec is capable of calling its([api_password])
, but the issue is is that the target must be a hash. In this example, you see that I am calling the key onto the Video::Base
class and not the #default_params
method. How would I go about setting it to call its([deafult_params])
onto Video::Base.default_params
and not onto Video::Base
?
Upvotes: 0
Views: 130
Reputation: 44675
You need to override the subject:
describe :default_params do
subject { Video::Base.default_params }
its([:api_password]) { should_not be_nil }
end
Or, to have more flexibility, use super
:
describe :default_params do
subject { super().default_params }
its([:api_password]) { should_not be_nil }
end
Upvotes: 2