<commit_before>require 'spec_helper'

class FooController < ActionController::Base
  before_filter :before_for_all_methods
  after_filter :after_for_all_methods

  after_filter :after_filter_only_create, :only => :create
  after_filter :after_filter_only_show, :only => :show
  after_filter :after_filter_only_show_and_create, :only => [:show, :create]
  after_filter :after_filter_except_show, :except => :show
  after_filter :after_filter_except_create, :except => :create
  after_filter :after_filter_except_show_and_create, :except => [:show, :create]

  before_filter :before_filter_only_create, :only => :create
  before_filter :before_filter_only_show, :only => :show
  before_filter :before_filter_only_show_and_create, :only => [:show, :create]
  before_filter :before_filter_except_show, :except => :show
  before_filter :before_filter_except_create, :except => :create
  before_filter :before_filter_except_show_and_create, :except => [:show, :create]
end

class BarController < ActionController::Base ; end

describe 'FilterMatcher' do
  before do
    @foo = FooController.new
    @to = CustomRspecMatchers::Matchers::FilterMatcher.new :before, :before_for_all_methods
    @bar = BarController.new
  end
  
  it { @to.description.should == "include before filter: before_for_all_methods" }
  it { @to.matches?(@foo).should == true }
  it { @foo.should include_before_filter(:before_for_all_methods) }
  
  describe 'failure message' do
    before do
      @to.matches?(@bar)
    end
    it { @to.failure_message.should == " expected to include before filter before_for_all_methods but not found in []" }
  end
end<commit_msg>Make test for FilterMatcher be more readable and arranged better<commit_after>require 'spec_helper'

describe 'FilterMatcher' do
  describe "matcher for a before filter" do
    before do
      @filter_under_test = :some_before_filter
      @matcher = FilterMatcher.new :before, @filter_under_test
    end
    
    it "has the correct description" do
      @matcher.description.should == "include before filter: some_before_filter"
    end
    
    describe "calling matches? on the matcher with a controller that doesn't have any filters" do
      before do
        class TestController < ActionController::Base; end
        @test_object = @matcher.matches? TestController.new
      end
      
      it "returns false" do
        @test_object.should == false
      end
      it "has the correct failure message" do
        @matcher.failure_message.should == " expected to include before filter some_before_filter but not found in []"
      end
    end
    
    describe "calling matches? on the matcher with a controller that doesn't have any before filters" do
      before do
        class TestController < ActionController::Base
          after_filter :awesome_after_filter
        end
        @test_object = @matcher.matches? TestController.new
      end
      
      it "returns false" do
        @test_object.should == false
      end
      it "has the correct failure message" do
        @matcher.failure_message.should == " expected to include before filter some_before_filter but not found in []"
      end
    end
    
    describe "calling matches? on the matcher with a controller that doesn't have the before filter" do
      before do
        class TestController < ActionController::Base
          before_filter :awesome_after_filter
        end
        @test_object = @matcher.matches? TestController.new
      end
      
      it "returns false" do
        @test_object.should == false
      end
      it "has the correct failure message" do
        @matcher.failure_message.should == " expected to include before filter some_before_filter but not found in [:awesome_after_filter]"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07680042519266543, 'fraction_numerical': 0.0, 'mean_word_length': 3.551390568319226, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1215357', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1072, 'n_words': 320}