<commit_before>require 'spec_helper'

describe "using the rspec extensions" do
  it "should be able to determine if a call has not been made" do
    item = fake
    item.hello
    item.last("other")

    item.should_not have_received(:hello,"world")
    item.should have_received(:hello)
    item.should_not have_received(:once_more)
    item.should_not have_received(:last,"hello")
    item.should have_received(:last,"other")
  end

  it "should be able to determine if a call has been made a certain number of times" do
    item = fake
    item.hello
    item.hello
    item.last("other")

    item.should_not have_received(:hello,"world")
    item.should have_received(:hello).twice
    item.should have_received(:hello)
    item.should_not have_received(:once_more)
    item.should_not have_received(:last,"hello")
    item.should have_received(:last,"other").once
    item.should_not have_received(:last).twice
  end

  it "should be able to determine if a call was made once" do
    item = fake
    item.hello

    item.should have_received(:hello).once
  end

  it "should be able to determine if a call was made twice" do
    item = fake
    item.hello
    item.hello

    item.should have_received(:hello).twice
  end

  it "should be able to determine if a call was made at least once" do
    item = fake
    item.hello
    item.hello

    item.should have_received(:hello).at_least_once
  end

  it "should be able to determine if a call was made at least twice" do
    item = fake
    item.hello
    item.hello
    item.hello

    item.should have_received(:hello).at_least_twice
    item.should have_received(:hello).at_least_twice
  end
  
  
  it "should be able to determine if a call was made at most once" do
    item = fake
    item.hello
    item.goodbye
    item.goodbye

    item.should have_received(:hello).at_most_once
    item.should_not have_received(:goodbye).at_most_once
  end

  it "should be able to determine if a call was made at most twice" do
    item = fake
    item.hello
    item.goodbye
    item.goodbye
    item.goodbye

    item.should have_received(:hello).at_most_twice
    item.should_not have_received(:goodbye).at_most_twice
  end

  it "should be able to determine if a call was made at least a specified number of times" do
    item = fake
    item.hello
    item.goodbye
    item.goodbye
    item.goodbye

    item.should have_received(:hello).at_most(1)
    item.should_not have_received(:goodbye).at_most(1)
  end
  context "using the arg matching style" do
    it "should be able to determing if a call was made using arg matchers" do
      item = fake
      item.hello("Yes")

      item.should have_received(:hello,matches.any)
    end

    it "should be able to determing if a call was made using a combination of arg matchers and explicit values" do
      item = fake
      item.hello("Yes",2)

      item.should have_received(:hello,matches.regex(/Y/),2)
    end
  end
end
<commit_msg>Added a demo showing how to fake class methods<commit_after>require 'spec_helper'

describe "using the rspec extensions" do
  it "should be able to determine if a call has not been made" do
    item = fake
    item.hello
    item.last("other")

    item.should_not have_received(:hello,"world")
    item.should have_received(:hello)
    item.should_not have_received(:once_more)
    item.should_not have_received(:last,"hello")
    item.should have_received(:last,"other")
  end

  it "should be able to determine if a call has been made a certain number of times" do
    item = fake
    item.hello
    item.hello
    item.last("other")

    item.should_not have_received(:hello,"world")
    item.should have_received(:hello).twice
    item.should have_received(:hello)
    item.should_not have_received(:once_more)
    item.should_not have_received(:last,"hello")
    item.should have_received(:last,"other").once
    item.should_not have_received(:last).twice
  end

  it "should be able to determine if a call was made once" do
    item = fake
    item.hello

    item.should have_received(:hello).once
  end

  it "should be able to determine if a call was made twice" do
    item = fake
    item.hello
    item.hello

    item.should have_received(:hello).twice
  end

  it "should be able to determine if a call was made at least once" do
    item = fake
    item.hello
    item.hello

    item.should have_received(:hello).at_least_once
  end

  it "should be able to determine if a call was made at least twice" do
    item = fake
    item.hello
    item.hello
    item.hello

    item.should have_received(:hello).at_least_twice
    item.should have_received(:hello).at_least_twice
  end
  
  
  it "should be able to determine if a call was made at most once" do
    item = fake
    item.hello
    item.goodbye
    item.goodbye

    item.should have_received(:hello).at_most_once
    item.should_not have_received(:goodbye).at_most_once
  end

  it "should be able to determine if a call was made at most twice" do
    item = fake
    item.hello
    item.goodbye
    item.goodbye
    item.goodbye

    item.should have_received(:hello).at_most_twice
    item.should_not have_received(:goodbye).at_most_twice
  end

  it "should be able to determine if a call was made at least a specified number of times" do
    item = fake
    item.hello
    item.goodbye
    item.goodbye
    item.goodbye

    item.should have_received(:hello).at_most(1)
    item.should_not have_received(:goodbye).at_most(1)
  end
  context "using the arg matching style" do
    it "should be able to determing if a call was made using arg matchers" do
      item = fake
      item.hello("Yes")

      item.should have_received(:hello,matches.any)
    end

    it "should be able to determing if a call was made using a combination of arg matchers and explicit values" do
      item = fake
      item.hello("Yes",2)

      item.should have_received(:hello,matches.regex(/Y/),2)
    end
  end
  context "using class swapping" do
    it "should be able to fake out behaviour of singleton methods" do
      fake_class Dir

      Dir.stub(:exist?).and_return false

      Dir.exist('/').should be_false
    end

    it "should be able to determing if a call was made using a combination of arg matchers and explicit values" do
      item = fake
      item.hello("Yes",2)

      item.should have_received(:hello,matches.regex(/Y/),2)
    end
  end
end

{'fraction_non_alphanumeric': 0.07799748901443816, 'fraction_numerical': 0.001569365976145637, 'mean_word_length': 3.0489199491740786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1274801', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1921, 'n_words': 658}