<commit_before>require 'spec_helper'

describe Github::Result do

  let(:github) { Github.new }
  let(:res)    { github.events.public }

  before do
    stub_get("/events").
      to_return(:body => fixture('events/events.json'),
        :status => 200,
        :headers => {
          :content_type => "application/json; charset=utf-8",
          'X-RateLimit-Remaining' => '4999',
          'X-RateLimit-Limit' => '5000',
          'content-length' => '344'
        })
  end

  it "should read response content_type " do
    res.content_type.should match 'application/json'
  end

  it "should read response content_length " do
    res.content_length.should match '344'
  end

  it "should read response ratelimit limit" do
    res.ratelimit_limit.should == '5000'
  end

  it "should read response ratelimit remaining" do
    res.ratelimit_remaining.should == '4999'
  end

  it "should read response status" do
    res.status.should be 200
  end

  it "should assess successful" do
    res.success?.should be_true
  end

  it "should read response body" do
    res.body.should_not be_empty
  end

  context "pagination methods" do
    let(:env) { {:response_headers => {}}}
    let(:iterator) { mock(Github::PageIterator.new(env)).as_null_object }
    let(:items) { [] }

    before do
      described_class.stub(:page_iterator).and_return iterator
      @items.stub(:env).and_return env
    end

    it "should respond to links" do
      res.links.should be_a Github::PageLinks
    end

    %w[ first next prev last].each do |link|
      it "should return #{link} page if exists" do
        res.send(:"#{link}_page").should eq @items
      end
    end

    it 'checks if there are more pages' do
      res.should_receive(:has_next_page?).and_return true
      res.has_next_page?.should be_true<commit_msg>Add specs to confirm single page retrieval.<commit_after>require 'spec_helper'

describe Github::Result do

  let(:github) { Github.new }
  let(:user)   { 'wycats' }
  let(:res)    { github.events.public }
  let(:pages)  { ['1', '5', '6'] }
  let(:link) {
    "<https://api.github.com/users/wycats/repos?page=6&per_page=20>; rel=\"last\", <https://api.github.com/users/wycats/repos?page=1&per_page=20>; rel=\"first\""
  }

  before do
    stub_get("/events").
      to_return(:body => fixture('events/events.json'),
        :status => 200,
        :headers => {
          :content_type => "application/json; charset=utf-8",
          'X-RateLimit-Remaining' => '4999',
          'X-RateLimit-Limit' => '5000',
          'content-length' => '344',
          'Link' => link
        })

    ['1', '5', '6'].each do |page|
    stub_get("/users/#{user}/repos").
      with(:query => {'per_page' => '20', 'page' => page}).
      to_return(:body => fixture('events/events.json'),
        :status => 200,
        :headers => {
          :content_type => "application/json; charset=utf-8",
          'X-RateLimit-Remaining' => '4999',
          'X-RateLimit-Limit' => '5000',
          'content-length' => '344',
          'Link' => link
        })
    end
  end

  it "should read response content_type " do
    res.content_type.should match 'application/json'
  end

  it "should read response content_length " do
    res.content_length.should match '344'
  end

  it "should read response ratelimit limit" do
    res.ratelimit_limit.should == '5000'
  end

  it "should read response ratelimit remaining" do
    res.ratelimit_remaining.should == '4999'
  end

  it "should read response status" do
    res.status.should be 200
  end

  it "should assess successful" do
    res.success?.should be_true
  end

  it "should read response body" do
    res.body.should_not be_empty
  end

  context "pagination methods" do
    let(:env) { {:response_headers => {}}}
    let(:iterator) { Github::PageIterator.new(env) }
    let(:items) { [] }

    before do
      described_class.stub(:page_iterator).and_return iterator
      @items.stub(:env).and_return env
    end

    it "should respond to links" do
      res.links.should be_a Github::PageLinks
    end

    %w[ next prev ].each do |link|
      it "should return #{link} page if exists" do
        res.send(:"#{link}_page").should eq @items
      end
    end

    %w[ first last].each do |link|
      it "should return #{link} page if exists" do
        res.send(:"#{link}_page").should_not be_empty
      end
    end

    it 'finds single page successfully' do
      iterator.stub(:get_page).and_return res
      res.page(5).should eq res
    end

    it 'checks if there are more pages' do
      res.should_receive(:has_next_page?).and_return true
      res.has_next_page?.should be_true
{'fraction_non_alphanumeric': 0.1346112427309929, 'fraction_numerical': 0.018953262976523798, 'mean_word_length': 2.727126805778491, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 2, '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': '5907948', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1484, 'n_words': 378}