Skip to content

Instantly share code, notes, and snippets.

@nathan-appere
Last active October 11, 2019 16:43
Show Gist options
  • Select an option

  • Save nathan-appere/40603bd71ba6756df94432b740c404e2 to your computer and use it in GitHub Desktop.

Select an option

Save nathan-appere/40603bd71ba6756df94432b740c404e2 to your computer and use it in GitHub Desktop.

Revisions

  1. nathan-appere revised this gist Oct 11, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions contract-example.rb
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,5 @@ def self.rgb_to_hex(r:, g:, b:)

    #RuntimeError:
    # Kit::Contracts | after failure for `Test::RGB.rgb_to_hex`
    # ["/Users/nathan/bootcamp/elearning/code/kit/libs/kit-organizer/spec/rgb_spec.rb", 13] ->(result:) { result.start_with?('#') },
    # {:result=>"+80200c"}
    # ["/Users/nathan/bootcamp/elearning/code/kit/libs/kit-organizer/spec/rgb_spec.rb", 11] ->(result:) { result.start_with?('#') },
    # Called with: {:result=>"+80200c"}
  2. nathan-appere created this gist Oct 11, 2019.
    22 changes: 22 additions & 0 deletions contract-example.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    module Test
    module RGB
    include Kit::Contract

    before ->(r:, g:, b:) { (0..255) === r && (0..255) === g && (0..255) === b }
    after [
    ->(result:) { result.is_a?(String) },
    ->(result:) { result.start_with?('#') },
    ->(result:) { result.length.in?([4, 7]) },
    ]
    def self.rgb_to_hex(r:, g:, b:)
    "+" << [r, g, b].map { |el| el.to_s(16).rjust(2, '0') }.join
    end
    end
    end

    Test::RGB.rgb_to_hex(r: 128, g: 32, b: 12)

    #RuntimeError:
    # Kit::Contracts | after failure for `Test::RGB.rgb_to_hex`
    # ["/Users/nathan/bootcamp/elearning/code/kit/libs/kit-organizer/spec/rgb_spec.rb", 13] ->(result:) { result.start_with?('#') },
    # {:result=>"+80200c"}