Found this tutorial using minitest, and was wondering if there is an equivalent matcher in rspec:
Interesting minitest assertion
describe "default attributes" do
it "must include httparty methods" do
Dish::Player.must_include HTTParty
end
it "must have the base url set to the Dribble API endpoint" do
Dish::Player.base_uri.must_equal 'http://api.dribbble.com'
end
end
Alternatively you can extend the test class with your module: let(:dummy_class) { Class.new { extend ModuleToBeTested } } Using 'let' is better than using an instance variable to define the dummy class in the before(:each) When to use RSpec let()? Share Improve this answer Follow edited Jul 3 '17 at 22:03
expect (message).to eq "Hello World!" The keyword eql is an RSpec “matcher”. Here, we will introduce the other types of matchers in RSpec. Matchers to test for object or value equality.
or you can include in globally in a spec_helper.rb file require d from your spec file (s): RSpec's built-in matchers are designed to be composed, in expressions like:
This is normally done by including the method and the class in a module, which is then included in your spec: or you can include in globally in a spec_helper.rb file require d from your spec file (s): RSpec's built-in matchers are designed to be composed, in expressions like:
Testing if a class has included a module is generally wrong, as you are testing implementation details instead of expected behavior.
Included modules can be found by calling ancestors
on the class, so you can simply use include
matcher:
expect(Dish::Player.ancestors).to include(HTTParty)
Your second expectation should be tested with:
expect(Dish::Player.base_uri).to eq 'http://api.dribbble.com'
EDIT
Until today I did not know that classes implement the <=>
operator. You can simply check if Dish::Player < HTTParty
.
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