title: How to test initializer number of arguments in Ruby
body: <p>I need to autograde a Ruby exercise , testing with Rspec</p>
  
  <p>The class is pure ruby and I only have to validate attributes (existence and accessibility) and the number of arguments that are received in the initializer</p>
  
  <pre class="lang-rb prettyprint-override"><code># lib/card.rb
  class Card
    attr_reader :number, :suit
  
    def initialize(number, suit)
      @number = number
      @suit = suit
    end
  end
  
  # spec/card_spec.rb
  require "spec_helper"
  require_relative "../lib/card"
  
  describe Card do
    let(:subject) do
      Card.new(1, "D")
    end
  
    it { expect(Card).to respond_to(:new).with(4).arguments }
  end
  
  </code></pre>
  
  <pre class="lang-sh prettyprint-override"><code>➜ rspec spec/card_spec.rb
  .
  
  Finished in 0.00431 seconds (files took 0.12135 seconds to load)
  1 example, 0 failure
  </code></pre>
  
  <p>Tests are passing despite the fact that the initializer receives 2 arguments and I specify 4 arguments in my test</p>