title: Rspec: expect vs expect with block - what's the difference?
body: <p>Just learning rspec syntax and I noticed that this code works:</p>
  
  <pre><code>  context "given a bad list of players" do
      let(:bad_players) { {} }
  
      it "fails to create given a bad player list" do
         expect{ Team.new("Random", bad_players) }.to raise_error
       end 
    end
  </code></pre>
  
  <p>But this code doesn't:</p>
  
  <pre><code>  context "given a bad list of players" do
      let(:bad_players) { {} }
  
      it "fails to create given a bad player list" do
         expect( Team.new("Random", bad_players) ).to raise_error
       end 
    end
  </code></pre>
  
  <p>It gives me this error:</p>
  
  <pre><code>Team given a bad list of players fails to create given a bad player list
       Failure/Error: expect( Team.new("Random", bad_players) ).to raise_error
       Exception:
         Exception
       # ./lib/team.rb:6:in `initialize'
       # ./spec/team_spec.rb:23:in `new'
       # ./spec/team_spec.rb:23:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>My question is:</p>
  
  <ol>
  <li>Why does this happen?</li>
  <li>What is the difference between the former and later example exactly in ruby?</li>
  </ol>
  
  <p>I am also looking for <strong>rules</strong> on when to use one over the other</p>
  
  <p>One more example of the same but inverse results, where this code works:</p>
  
  <pre><code>  it "has a list of players" do
      expect(Team.new("Random").players).to be_kind_of Array
    end 
  </code></pre>
  
  <p>But this code fails</p>
  
  <pre><code>  it "has a list of players" do
      expect{ Team.new("Random").players }.to be_kind_of Array
    end
  </code></pre>
  
  <p>Error I get in this case is:</p>
  
  <pre><code>Failure/Error: expect{ Team.new("Random").players }.to be_kind_of Array
         expected #&lt;Proc:0x007fbbbab29580@/Users/amiterandole/Documents/current/ruby_sandbox/tdd-ruby/spec/team_spec.rb:9&gt; to be a kind of Array
       # ./spec/team_spec.rb:9:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>The class I am testing looks like this:</p>
  
  <pre><code>class Team
    attr_reader :name, :players
  
    def initialize(name, players = [])
      raise Exception unless players.is_a? Array
  
      @name = name
      @players = players
    end
  end
  </code></pre>