title: How to make a stub return a hash value
body: <p>I have a model and a method inside that defined as follows :</p>
  
  <pre><code>class Farm &lt; ActiveRecord::Base
     def flags
      #has other code which returns a flag_details hash eg:
      # flag_details['flag1'] = true;
      # flag_details['flag2'] = false;
    end
  
  end
  </code></pre>
  
  <p>Now I need to write a test to verify that a particular div is displayed based on the flags that are set/unset. And I want to write a stub to be able to return these flags and then test if the page is displaying the correct div. How do I correct the following code, to get what I intend:</p>
  
  <pre><code>  scenario "display div named flower when flag1 or flag2 is false" do
      farm.stub(:flags).and_return("flag1" =&gt; false, "flag2" =&gt; false)
      if !farm.flags['flag1'] || !farm.flags['flag2']
        expect(page).to have_selector('div.flower', text: "4" )
      end    
    end
  </code></pre>
  
  <p>I am a beginner in ruby, rails and rspec, so any help will be great. I also tried using the following method but it did not work:</p>
  
  <pre><code>farm.stub(:flags[]).with('flag1').and_return(false)
  farm.stub(:flags[]).with('flag2').and_return(false)
  </code></pre>
  
  <p>I also checked this documentation (<a href="https://www.relishapp.com/rspec/rspec-mocks/v/2-4/docs/method-stubs" rel="nofollow">https://www.relishapp.com/rspec/rspec-mocks/v/2-4/docs/method-stubs</a>) but did not get my answer. Any other links that could be helpful in this, are really appreciated!</p>
  
  <p>Thanks!</p>