<commit_before>require 'spec_helper'

describe EMDextras::Spec::Spy do
  subject { described_class.new }
  
  describe :"called?" do
    it "should record calls" do
      subject.foo(1, :a => "b")

      subject.called?(:foo, 1, :a => "b").should be_true
      subject.called?(:bar, 1, :a => "b").should be_false
      subject.called?(:foo, 1, :a => "c").should be_false
    end  
  end

  describe "default return value" do
    it "returns nil if no default return value is defined" do
      spy = EMDextras::Spec::Spy.new 
      spy.some_method.should == nil
    end

    it "returns the default value if defined" do
      spy = EMDextras::Spec::Spy.new :default_return => "default"
      spy.some_method.should == "default"
    end
  end

  describe :respond_to? do
    it "will always return true" do
      subject.respond_to?(:any_method_name).should be_true
    end
  end

  describe :received_call! do
    it "should do nothing if the call was really received" do
      EM.run do 
        subject.foo(1, :a => "b")

        subject.received_call!(:foo, 1, :a => "b")
      end
    end

    it "should raise an exception if the call was not received" do
      expect {
        EM.run do 
          subject.foo(1, :a => "b")
        
          subject.received_call!(:bar, 1, :a => "b")
        end
      }.to raise_error(/bar.*foo/)
    end

    it "should accept rspec argument matchers" do
      subject.foo(1, "banana")

      EM.run { subject.received_call!(:foo, 1, /ba(na)*/) } #doesn't raise
      expect {EM.run { subject.received_call!(:foo, 1, /apple/) } }.to raise_error
    end

    context "when the method is triggered asynchronously" do<commit_msg>Test for boundary case<commit_after>require 'spec_helper'

describe EMDextras::Spec::Spy do
  subject { described_class.new }
  
  describe :"called?" do
    it "should record calls" do
      subject.foo(1, :a => "b")

      subject.called?(:foo, 1, :a => "b").should be_true
      subject.called?(:bar, 1, :a => "b").should be_false
      subject.called?(:foo, 1, :a => "c").should be_false
    end  
  end

  describe "default return value" do
    it "returns nil if no default return value is defined" do
      spy = EMDextras::Spec::Spy.new 
      spy.some_method.should == nil
    end

    it "returns the default value if defined" do
      spy = EMDextras::Spec::Spy.new :default_return => "default"
      spy.some_method.should == "default"
    end
  end

  describe :respond_to? do
    it "will always return true" do
      subject.respond_to?(:any_method_name).should be_true
    end
  end

  describe :received_call! do
    it "should do nothing if the call was really received" do
      EM.run do 
        subject.foo(1, :a => "b")

        subject.received_call!(:foo, 1, :a => "b")
      end
    end

    it "should raise an exception if the call was not received" do
      expect {
        EM.run do 
          subject.foo(1, :a => "b")
        
          subject.received_call!(:bar, 1, :a => "b")
        end
      }.to raise_error(/bar.*foo/)
    end

    it "should accept rspec argument matchers" do
      subject.foo(1, "banana")

      EM.run { subject.received_call!(:foo, 1, /ba(na)*/) } #doesn't raise
      expect {EM.run { subject.received_call!(:foo, 1, /apple/) } }.to raise_error
    end

    it "should be able to assert that a method will receive nil" do
      EM.run do 
        subject.foobar(nil)

        subject.received_call!(:foobar, nil)
      end
    end

    context "when the method is triggered asynchronously" do
{'fraction_non_alphanumeric': 0.1225531914893617, 'fraction_numerical': 0.00624113475177305, 'mean_word_length': 2.4773175542406314, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5303034', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1137, 'n_words': 356}