<commit_before>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe 'Japanese()' do

    describe 'Argument errors' do

        it 'throws error when arg is not String object' do
            NotString = Class.new
            not_string = NotString.new
            lambda {
                Japanese(not_string)
            }.should raise_error(ArgumentError, 'Not String object')
        end

        it 'throws error when arg is not Japanese' do
            lambda {
              Japanese('This is English.')
            }.should raise_error(ArgumentError, 'Not Japanese')
        end

    end

    describe 'General situation' do

        before do
            @jstr = Japanese('これは日本語です')
        end

        it '#japanese? returns true' do
            @jstr.japanese?.should be_true
        end

        it '#ja? returns true' do
            @jstr.ja?.should be_true
        end

        it 'has singleton methods' do
            expects = ['japanese?', 'ja?', 'words', 'conj', 'associate_hatena_keywords']
            expects.each do |expect|
                @jstr.singleton_methods.include?(expect).should be_true
            end
        end

    end

    describe 'global String class is not polluted' do

        before do
            @str = 'This is just a string'
        end

        it 'String object does not respond to japanese?' do
            @str.respond_to?(:japanese?).should be_false
        end

        it 'String object does not respond to ja?' do
            @str.respond_to?(:ja?).should be_false
        end

        it 'String object does not have any singleton method' do
            @str.singleton_methods.should be_empty 
        end<commit_msg>more DRY.<commit_after>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe 'Japanese()' do

    describe 'Argument errors' do

        it 'throws error when arg is not String object' do
            NotString = Class.new
            not_string = NotString.new
            lambda {
                Japanese(not_string)
            }.should raise_error(ArgumentError, 'Not String object')
        end

        it 'throws error when arg is not Japanese' do
            lambda {
              Japanese('This is English.')
            }.should raise_error(ArgumentError, 'Not Japanese')
        end

    end

    describe 'General situation' do

        before do
            @jstr = Japanese('これは日本語です')
        end

        [:japanese?, :ja?].each do |message|
            it "##{message} returns true" do
                @jstr.send(message).should be_true
            end
        end

        it 'has singleton methods' do
            expects = ['japanese?', 'ja?', 'words', 'conj', 'associate_hatena_keywords']
            expects.each do |expect|
                @jstr.singleton_methods.include?(expect).should be_true
            end
        end

    end

    describe 'global String class is not polluted' do

        before do
            @str = 'This is just a string'
        end

        [:japanese?, :ja?].each do |message|
            it "String object does not respond to #{message}" do
                @str.respond_to?(:message).should be_false
            end
        end

        it 'String object does not have any singleton method' do
            @str.singleton_methods.should be_empty 
        end
{'fraction_non_alphanumeric': 0.08458308338332333, 'fraction_numerical': 0.0, 'mean_word_length': 1.7448559670781894, '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': '1319118', 'n_tokens_mistral': 931, 'n_tokens_neox': 874, 'n_words': 288}