My model has
def self.empty_building
// stuff
end
How can I rspec for this existing?, have tried:
describe "empty_building" do
subject { Building.new }
it { should respond_to :empty_building }
end
but getting :
Failure/Error: it { should respond_to :empty_building }
expected #<Building id: nil, district_id: nil, name: nil,
direct: nil, created_at: nil, updated_at: nil> to respond to :empty_building
You can check a method is called or not by using receive in rspec.
To run a single Rspec test file, you can do: rspec spec/models/your_spec. rb to run the tests in the your_spec. rb file.
RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications.
The describe Keyword The word describe is an RSpec keyword. It is used to define an “Example Group”. You can think of an “Example Group” as a collection of tests. The describe keyword can take a class name and/or string argument.
You have a class method
self.empty_building
in your model.. but your subject is an instance of Building.
So either, it should be
def empty_building
or it should be:
describe "empty_building" do
it { Building.should respond_to :empty_building }
end
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