progne_tapera-rspec 0.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +7 -0
 - data/Gemfile.lock +1 -1
 - data/README.md +2 -2
 - data/ROADMAP.md +7 -0
 - data/lib/progne_tapera/rspec.rb +1 -0
 - data/lib/progne_tapera/rspec/code_attribute_shared_examples.rb +4 -0
 - data/lib/progne_tapera/rspec/enum_code_shared_examples.rb +54 -0
 - data/lib/progne_tapera/rspec/enum_config_shared_examples.rb +86 -0
 - data/lib/progne_tapera/rspec/version.rb +1 -1
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a200607828901259038a96c4d0ac0501cd7571a8
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9570505b495eaf94601bd19b28192cb9fd6ec7f2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: ea7822cd576ad7264309ecb6dbf608604c47338aa18dffb25fc2f8e857ccd6cdff51a991cbfbfc6272048531a9233052aafe21bd743fae5b7ad8f6b92f3b00bd
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 699fa92fac0d554426408c4861536947c71f18926172cdd59d11b07bf6507c04d8d30e5cbb9e218205c49133bf69701ef7a8f6fbdd60cd81f314f63b16863736
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -8,3 +8,10 @@ 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            ## v0.3
         
     | 
| 
       10 
10 
     | 
    
         
             
            1. Improve the Progne Tapera RSpec module to require the Enum Code shared examples & the Code Attribute shared examples automatically
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            ## v0.3.1
         
     | 
| 
      
 13 
     | 
    
         
            +
            1. Progne Tapera Enum Config shared examples
         
     | 
| 
      
 14 
     | 
    
         
            +
            2. Progne Tapera Enum Code shared examples
         
     | 
| 
      
 15 
     | 
    
         
            +
            3. Deprecate the Enum Code shared examples
         
     | 
| 
      
 16 
     | 
    
         
            +
            4. Deprecate the Code Attribute shared examples
         
     | 
| 
      
 17 
     | 
    
         
            +
            5. Improve the Progne Tapera RSpec module to require the Progne Tapera Enum Config shared examples & the Progne Tapera Enum Code shared examples automatically
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -36,7 +36,7 @@ RSpec.describe Gender, type: :type do 
     | 
|
| 
       36 
36 
     | 
    
         
             
              after :each do
         
     | 
| 
       37 
37 
     | 
    
         
             
              end
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
              it_behaves_like ' 
     | 
| 
      
 39 
     | 
    
         
            +
              it_behaves_like 'ProgneTapera::EnumConfig', 3, [
         
     | 
| 
       40 
40 
     | 
    
         
             
                { code: '1', name: 'male',          localized_name: '男'     },
         
     | 
| 
       41 
41 
     | 
    
         
             
                { code: '2', name: 'female',        localized_name: '女'     },
         
     | 
| 
       42 
42 
     | 
    
         
             
                { code: '9', name: 'not_specified', localized_name: '未指定' } ]
         
     | 
| 
         @@ -62,7 +62,7 @@ describe Person do 
     | 
|
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
              context '#gender' do
         
     | 
| 
       64 
64 
     | 
    
         
             
                @person = Person.new
         
     | 
| 
       65 
     | 
    
         
            -
                it_behaves_like ' 
     | 
| 
      
 65 
     | 
    
         
            +
                it_behaves_like 'ProgneTapera::EnumCode', @person, :gender, Gender
         
     | 
| 
       66 
66 
     | 
    
         
             
              end
         
     | 
| 
       67 
67 
     | 
    
         | 
| 
       68 
68 
     | 
    
         
             
            end
         
     | 
    
        data/ROADMAP.md
    CHANGED
    
    | 
         @@ -8,3 +8,10 @@ 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            ## v0.3
         
     | 
| 
       10 
10 
     | 
    
         
             
            1. Improve the Progne Tapera RSpec module to require the Enum Code shared examples & the Code Attribute shared examples automatically
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            ## v0.3.1
         
     | 
| 
      
 13 
     | 
    
         
            +
            1. Progne Tapera Enum Config shared examples
         
     | 
| 
      
 14 
     | 
    
         
            +
            2. Progne Tapera Enum Code shared examples
         
     | 
| 
      
 15 
     | 
    
         
            +
            3. Deprecate the Enum Code shared examples
         
     | 
| 
      
 16 
     | 
    
         
            +
            4. Deprecate the Code Attribute shared examples
         
     | 
| 
      
 17 
     | 
    
         
            +
            5. Improve the Progne Tapera RSpec module to require the Progne Tapera Enum Config shared examples & the Progne Tapera Enum Code shared examples automatically
         
     | 
    
        data/lib/progne_tapera/rspec.rb
    CHANGED
    
    
| 
         @@ -1,5 +1,9 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # The following shared examples are deprecated.
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            shared_examples 'code attribute' do |model, attribute_name, enum|
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
      
 5 
     | 
    
         
            +
              warn 'The "code attribute" shared examples is deprecated and will be removed since v1.0, please use "ProgneTapera::EnumCode" instead.'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       3 
7 
     | 
    
         
             
              describe "##{attribute_name}" do
         
     | 
| 
       4 
8 
     | 
    
         
             
                it 'exists' do expect(model).to respond_to(attribute_name) end
         
     | 
| 
       5 
9 
     | 
    
         
             
              end
         
     | 
| 
         @@ -1,5 +1,59 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            shared_examples 'ProgneTapera::EnumCode' do |model, attribute_name, enum|
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
              describe "##{attribute_name}" do
         
     | 
| 
      
 4 
     | 
    
         
            +
                it 'exists' do expect(model).to respond_to(attribute_name) end
         
     | 
| 
      
 5 
     | 
    
         
            +
              end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              describe "##{attribute_name}=" do
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                it 'exists' do expect(model).to respond_to("#{attribute_name}=") end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                enum.each do |enum_item|
         
     | 
| 
      
 12 
     | 
    
         
            +
                  it "should be able to assign #{enum_item.inspect} and load by ##{attribute_name}" do
         
     | 
| 
      
 13 
     | 
    
         
            +
                    model.send "#{attribute_name}=", enum_item
         
     | 
| 
      
 14 
     | 
    
         
            +
                    expect(model.send attribute_name).to eq(enum_item)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
                  it "should be able to assign #{enum_item.inspect} and load by ##{attribute_name}_code" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                    model.send "#{attribute_name}=", enum_item
         
     | 
| 
      
 18 
     | 
    
         
            +
                    expect(model.send "#{attribute_name}_code").to eq(enum_item.code)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              describe "##{attribute_name}_code" do
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                it 'exists' do expect(model).to respond_to("#{attribute_name}_code") end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              describe "##{attribute_name}_code=" do
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                it 'exists' do expect(model).to respond_to("#{attribute_name}_code=") end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                enum.each do |enum_item|
         
     | 
| 
      
 35 
     | 
    
         
            +
                  it "should be able to assign #{enum_item.code.inspect} and load by ##{attribute_name}" do
         
     | 
| 
      
 36 
     | 
    
         
            +
                    model.send "#{attribute_name}_code=", enum_item.code
         
     | 
| 
      
 37 
     | 
    
         
            +
                    expect(model.send attribute_name).to eq(enum_item)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
                  it "should be able to assign #{enum_item.code.inspect} and load by ##{attribute_name}_code" do
         
     | 
| 
      
 40 
     | 
    
         
            +
                    model.send "#{attribute_name}_code=", enum_item.code
         
     | 
| 
      
 41 
     | 
    
         
            +
                    expect(model.send "#{attribute_name}_code").to eq(enum_item.code)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            # The shared examples are deprecated.
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
       1 
53 
     | 
    
         
             
            shared_examples 'enum code' do |code_count, enum_list|
         
     | 
| 
       2 
54 
     | 
    
         | 
| 
      
 55 
     | 
    
         
            +
              warn 'The "enum code" shared examples is deprecated and will be removed since v1.0, please use "ProgneTapera::EnumConfig" instead.'
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
       3 
57 
     | 
    
         
             
              describe '.enum_name' do
         
     | 
| 
       4 
58 
     | 
    
         
             
                it 'exists' do expect(described_class).to respond_to(:enum_name) end
         
     | 
| 
       5 
59 
     | 
    
         
             
              end
         
     | 
| 
         @@ -0,0 +1,86 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            shared_examples 'ProgneTapera::EnumConfig' do |code_count, enum_list|
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
              describe '.enum_name' do
         
     | 
| 
      
 4 
     | 
    
         
            +
                it 'exists' do expect(described_class).to respond_to(:enum_name) end
         
     | 
| 
      
 5 
     | 
    
         
            +
              end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              describe '.item_defined?' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                it 'exists' do expect(described_class).to respond_to(:item_defined?) end
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              describe '.add_item' do
         
     | 
| 
      
 12 
     | 
    
         
            +
                it 'exists' do expect(described_class).to respond_to(:add_item) end
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              describe '.safe_add_item' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                it 'exists' do expect(described_class).to respond_to(:safe_add_item) end
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              describe '.enum_constants' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                it 'exists' do expect(described_class).to respond_to(:enum_constants) end
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              describe '.all' do
         
     | 
| 
      
 24 
     | 
    
         
            +
                it 'exists'                      do expect(described_class).to            respond_to(:all) end
         
     | 
| 
      
 25 
     | 
    
         
            +
                it 'returns all values'          do expect(described_class.all).to        be_present       end
         
     | 
| 
      
 26 
     | 
    
         
            +
                it "returns #{code_count} items" do expect(described_class.all.length).to eq(code_count)   end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              describe '.selected' do
         
     | 
| 
      
 30 
     | 
    
         
            +
                it 'exists' do expect(described_class).to respond_to(:selected) end
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              describe '.each' do
         
     | 
| 
      
 34 
     | 
    
         
            +
                it 'exists' do expect(described_class).to respond_to(:each) end
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              describe '.form_options' do
         
     | 
| 
      
 38 
     | 
    
         
            +
                it 'exists' do expect(described_class).to respond_to(:form_options) end
         
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              describe '.enum' do
         
     | 
| 
      
 42 
     | 
    
         
            +
                it 'exists' do expect(described_class).to respond_to(:enum) end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              describe '.overload_enum_i18n' do
         
     | 
| 
      
 46 
     | 
    
         
            +
                it 'exists' do expect(described_class).to respond_to(:overload_enum_i18n) end
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
              enum_list.each do |enum_item|
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                const_name = enum_item[:name].upcase
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                describe "::#{const_name}" do
         
     | 
| 
      
 54 
     | 
    
         
            +
                  before :each do @enum_item = described_class.const_get const_name end
         
     | 
| 
      
 55 
     | 
    
         
            +
                  it 'exists'  do expect(@enum_item).to be_present end
         
     | 
| 
      
 56 
     | 
    
         
            +
                  enum_item.each do |key, value|
         
     | 
| 
      
 57 
     | 
    
         
            +
                    it "#{key.to_s.gsub('_', ' ')} is #{value}" do expect(@enum_item.send key.to_sym).to eq(value) end
         
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                describe '.lookup' do
         
     | 
| 
      
 62 
     | 
    
         
            +
                  it "should be able to find the #{enum_item[:name]} enum item per #{enum_item[:code]}" do
         
     | 
| 
      
 63 
     | 
    
         
            +
                    found_enum_item = described_class.lookup enum_item[:code]
         
     | 
| 
      
 64 
     | 
    
         
            +
                    expect(found_enum_item).to                be_present
         
     | 
| 
      
 65 
     | 
    
         
            +
                    expect(found_enum_item.code).to           eq(enum_item[:code])
         
     | 
| 
      
 66 
     | 
    
         
            +
                    expect(found_enum_item.name).to           eq(enum_item[:name])
         
     | 
| 
      
 67 
     | 
    
         
            +
                    expect(found_enum_item.localized_name).to eq(enum_item[:localized_name])
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
              #enum_list.each do |enum_item|
         
     | 
| 
      
 74 
     | 
    
         
            +
              #  it ".lookup('#{enum_item[:code]}')" do expect(described_class.lookup enum_item[:code]).to eq(described_class.const_get enum_item[:name].upcase) end
         
     | 
| 
      
 75 
     | 
    
         
            +
              #end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
              #view_collection_mappings = {} if view_collection_mappings.nil?
         
     | 
| 
      
 78 
     | 
    
         
            +
              #view_collection_mappings[:view_collection] = code_count
         
     | 
| 
      
 79 
     | 
    
         
            +
              #view_collection_mappings.each do |view_collection, expected_count|
         
     | 
| 
      
 80 
     | 
    
         
            +
              #  describe ".#{view_collection}" do
         
     | 
| 
      
 81 
     | 
    
         
            +
              #    it 'exists'                          do expect(described_class).to                              respond_to(view_collection) end
         
     | 
| 
      
 82 
     | 
    
         
            +
              #    it "returns #{expected_count} items" do expect(described_class.send(view_collection).length).to eq(expected_count)          end
         
     | 
| 
      
 83 
     | 
    
         
            +
              #  end
         
     | 
| 
      
 84 
     | 
    
         
            +
              #end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: progne_tapera-rspec
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version:  
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Topbit Du
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-01-07 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -76,6 +76,7 @@ files: 
     | 
|
| 
       76 
76 
     | 
    
         
             
            - lib/progne_tapera/rspec.rb
         
     | 
| 
       77 
77 
     | 
    
         
             
            - lib/progne_tapera/rspec/code_attribute_shared_examples.rb
         
     | 
| 
       78 
78 
     | 
    
         
             
            - lib/progne_tapera/rspec/enum_code_shared_examples.rb
         
     | 
| 
      
 79 
     | 
    
         
            +
            - lib/progne_tapera/rspec/enum_config_shared_examples.rb
         
     | 
| 
       79 
80 
     | 
    
         
             
            - lib/progne_tapera/rspec/version.rb
         
     | 
| 
       80 
81 
     | 
    
         
             
            - progne_tapera-rspec.gemspec
         
     | 
| 
       81 
82 
     | 
    
         
             
            homepage: https://github.com/topbitdu/progne_tapera-rspec
         
     |