Adding rspec test for library module doesn't seem to pickup Expectations and Matchers

前端 未结 1 1604
暖寄归人
暖寄归人 2021-02-14 04:01

I\'m adding more rspec testing to my app and would like to test a ScoringMethods module, which is in /lib/scoring_methods.rb. So I added a /spec/lib directory and added scoring

相关标签:
1条回答
  • 2021-02-14 04:07

    You should include your test block in an "it" block. For example:

    require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
    
    describe ScoringMethods do
    
      describe "should have scorePublicContest method" do
        it "should have a scorePublicContest method" do
          methods = ScoringMethods.instance_methods
          methods[0].should match(/scorePublicContest/)
        end
      end
    end
    

    You will find that the methods names returned aren't guaranteed to be in the order they exist in the file.

    A model we often use when testing Modules is to include the module in either a class created for the test (inside the spec file) or included inside the spec itself.

    0 讨论(0)
提交回复
热议问题