title: Rspec: ActionMailer::Base.deliveries should be empty
body: <p>Testing filling in the contact form without filling in one of the required fields in one test and then filling in the honey_pot field in another test. The tests when valid info is filled in are passing, but the two other specs are failing.</p>
  
  <p><strong>Update</strong> I've been running the test a couple of times and sometimes all the tests pass. Other times, the same specs fail. </p>
  
  <p>Terminal output</p>
  
  <pre><code>  3) Pages Home page it should behave like all static pages Footer Contact Form when honeypot is filled does not send an email
       Failure/Error: expect(ActionMailer::Base.deliveries).to be_empty
         expected empty? to return true, got false
       Shared Example Group: "all static pages" called from ./spec/requests/pages_spec.rb:69
       # ./spec/requests/pages_spec.rb:46:in `block (6 levels) in &lt;top (required)&gt;'
  
    4) Pages Home page it should behave like all static pages Footer Contact Form when fields are not filled does not send an email
       Failure/Error: expect(ActionMailer::Base.deliveries).to be_empty
         expected empty? to return true, got false
       Shared Example Group: "all static pages" called from ./spec/requests/pages_spec.rb:69
       # ./spec/requests/pages_spec.rb:38:in `block (6 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>pages_spec.rb</p>
  
  <pre><code>require 'spec_helper'                                                                                                                                    
  
  describe "Pages" do                                                                                                                                      
  
    subject { page }                                                                                                                                       
  
    shared_examples_for "all static pages" do |path_name|                                                                                                  
      before { visit send(path_name) }                                                                                                                     
  
      describe "Footer" do                                                                                                                                 
  
        describe "Contact Form" do                                                                                                                         
          it { should have_selector('h7', text: 'Contact Us') }                                                                                            
  
          context "when a valid message" do                                                                                                                
  
            it "sends an email" do                                                                                                                         
              post contact_create_path, message: attributes_for(:message)                                                                                  
              expect(ActionMailer::Base.deliveries.last.to).to eq(["#{ENV["MVP_USERNAME"]}"])                                                              
              ActionMailer::Base.deliveries.clear                                                                                                          
            end                                                                                                                                            
          end                                                                                                                                              
  
          context "when fields are not filled" do                                                                                                          
            it "does not send an email" do                                                                                                                 
              post contact_create_path, message: attributes_for(:message, name: '', body: '')                                                              
              expect(ActionMailer::Base.deliveries).to be_empty                                                                                            
              ActionMailer::Base.deliveries.clear                                                                                                          
            end                                                                                                                                            
          end                           
        end                                                                                                                                              
  
          context "when honeypot is filled" do                                                                                                             
            it "does not send an email" do                                                                                                                 
              post contact_create_path, message: attributes_for(:message, sweet_honey: 'bot')                                                              
              expect(ActionMailer::Base.deliveries).to be_empty                                                                                            
              ActionMailer::Base.deliveries.clear                                                                                                          
            end                                                                                                                                            
          end                                                                                                                                              
        end                                                                                                                                                
      end                                                                                                                                                  
    end                
  
    describe "Home page" do                                                                                                                                
      before { visit root_path }                                                                                                                           
      it_should_behave_like "all static pages", :root_path                                                                                                 
      it { should have_text('Quality Cars') }                                                                                                              
      it { should have_title('Misawa Used Cars - Misawa Auto Sales') }                                                                                     
  
      describe "Send a message" do                                                                                                                         
        before do                                                                                                                                          
          fill_in "Name", with: 'name'                                                                                                                     
          fill_in "Email", with: 'email@example.com'                                                                                                       
          fill_in "Phone", with: '999-9999-9999'                                                                                                           
          fill_in "Body", with: 'Hello'                                                                                                                    
          click_button "Send"                                                                                                                              
        end                                                                                                                                                
  
        describe "after the message is sent" do                                                                                                            
  
          it "should render the desired page with a flash" do                                                                                              
            expect(page).to have_text('Quality Cars')                                                                                                      
            expect(page).to have_title('Misawa Used Cars - Misawa Auto Sales')                                                                             
            expect(page).to have_selector('.alert-box.success')                                                                                            
          end                                                                                                                                              
        end                                                                                                                                                
      end                                                                                                                                                  
    end    
  end
  </code></pre>