<commit_before>require 'spec_helper'
require 'grape_entity'

describe GrapeEntityMatchers do
  before(:all) do
    class PetEntity < Grape::Entity
      expose :name, :age
    end
    class Person
      include Grape::Entity::DSL
      entity :name, :age do
        expose :date_of_birth, :as => :birthday
        expose :cat, :as => :feline, :using => PetEntity
        expose :dog, :using => PetEntity
        expose :secret, :if => lambda{ |person, options| person.authorized? }
        expose :super_dooper_secret, :as => :top_secret, :if => lambda{ |person, options| person.authorized? }
      end
    end
    class Vet < Grape::Entity
      root 'vets', 'vet'
      expose :name
    end
    class ItemEntity < Grape::Entity
      expose :name
      expose :name, as: :title
      expose :sub_items, as: :children, using: ItemEntity
    end
    nil
  end

  context 'matchers' do
    subject(:entity) { Person::Entity }

    # TODO: move the tests to this format to shadow the thoughtbot tests.
    # it { should represent(:name) }
    context "should ensure the representation includes the specified property" do
      it { should represent :name}
    end
    
    it { should represent :name}
    
    it { should represent(:date_of_birth).as(:birthday) }
    
    it { should_not represent(:t_shirt_size) }
    it { should_not represent(:t_shirt_size).as(:birthday) }
    it { should_not represent(:name).as(:brithday) }
    it { should_not represent(:date_of_birth) }
    
    it { should represent(:secret).when( :authorized? => true ) }
    it { should_not represent(:secret).when( :authorized? => false ) }

    it { should represent(:super_dooper_secret).as(:top_secret).when( :authorized? => true ) }
    it { should_not represent(:super_dooper_secret).as(:top_secret).when( :authorized? => false ) }
    it { should_not represent(:super_dooper_secret).when( :authorized? => true ) }
    
    it { should represent(:dog).using(PetEntity) }
    it { should represent(:cat).as(:feline).using(PetEntity) }
    it { should_not represent(:cat).using(PetEntity) }

  end

  context 'matchers within a root' do
    subject(:entity) { Vet }
    it { should represent(:name).with_root('vet') }
  end

  context 'matchers with with a tree structure' do
    subject(:entity) { ItemEntity }
    it { should represent(:name).as(:title) }
    it { should represent(:sub_items).as(:children).using(ItemEntity) }
  end
end
<commit_msg>rewrite tests with expect syntax instead of should<commit_after>require 'spec_helper'
require 'grape_entity'

describe GrapeEntityMatchers do
  before(:all) do
    class PetEntity < Grape::Entity
      expose :name, :age
    end
    class Person
      include Grape::Entity::DSL
      entity :name, :age do
        expose :date_of_birth, :as => :birthday
        expose :cat, :as => :feline, :using => PetEntity
        expose :dog, :using => PetEntity
        expose :secret, :if => lambda{ |person, options| person.authorized? }
        expose :super_dooper_secret, :as => :top_secret, :if => lambda{ |person, options| person.authorized? }
      end
    end
    class Vet < Grape::Entity
      root 'vets', 'vet'
      expose :name
    end
    class ItemEntity < Grape::Entity
      expose :name
      expose :name, as: :title
      expose :sub_items, as: :children, using: ItemEntity
    end
    nil
  end

  context 'matchers' do
    subject(:entity) { Person::Entity }

    # TODO: move the tests to this format to shadow the thoughtbot tests.
    # it { is_expected.to represent(:name) }
    context "ensure the representation includes the specified property" do
      it { is_expected.to represent :name}
    end

    it { is_expected.to represent :name}

    it { is_expected.to represent(:date_of_birth).as(:birthday) }

    it { is_expected.to_not represent(:t_shirt_size) }
    it { is_expected.to_not represent(:t_shirt_size).as(:birthday) }
    it { is_expected.to_not represent(:name).as(:brithday) }
    it { is_expected.to_not represent(:date_of_birth) }

    it { is_expected.to represent(:secret).when( :authorized? => true ) }
    it { is_expected.to_not represent(:secret).when( :authorized? => false ) }

    it { is_expected.to represent(:super_dooper_secret).as(:top_secret).when( :authorized? => true ) }
    it { is_expected.to_not represent(:super_dooper_secret).as(:top_secret).when( :authorized? => false ) }
    it { is_expected.to_not represent(:super_dooper_secret).when( :authorized? => true ) }

    it { is_expected.to represent(:dog).using(PetEntity) }
    it { is_expected.to represent(:cat).as(:feline).using(PetEntity) }
    it { is_expected.to_not represent(:cat).using(PetEntity) }

  end

  context 'matchers within a root' do
    subject(:entity) { Vet }
    it { is_expected.to represent(:name).with_root('vet') }
  end

  context 'matchers with with a tree structure' do
    subject(:entity) { ItemEntity }
    it { is_expected.to represent(:name).as(:title) }
    it { is_expected.to represent(:sub_items).as(:children).using(ItemEntity) }
  end
end

{'fraction_non_alphanumeric': 0.12311058074781225, 'fraction_numerical': 0.0, 'mean_word_length': 3.395979020979021, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, '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': '5895615', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1557, 'n_words': 410}