Sha256: 71f321c8321fb34771c713fab58fb83b9cb1e83fc77b4ce6604054de49d9e360

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require "assert"
require "much-rails/input_value"

module MuchRails::InputValue
  class UnitTests < Assert::Context
    desc "MuchRails::InputValue"
    subject{ unit_class }

    let(:unit_class){ MuchRails::InputValue }
    let(:non_blank_but_empty_to_s_object) do
      Class
        .new{
          def to_s
            ["", " "].sample
          end
        }
        .new
    end

    should have_imeths :strip, :strip_all

    should "know its attributes" do
      # strip
      input_value = [nil, "", " ", non_blank_but_empty_to_s_object].sample
      assert_that(subject.strip(input_value)).is_nil

      input_value = [" VALUE  ", "\r VALUE\n"].sample
      assert_that(subject.strip(input_value)).equals("VALUE")

      assert_that(subject.strip([])).is_nil
      assert_that(subject.strip({})).is_nil

      # strip_all
      input_values = [nil, "", " ", " VALUE  "]
      assert_that(subject.strip_all(input_values)).equals(["VALUE"])

      input_values = [" VALUE1  ", "\r VALUE2\n"]
      assert_that(subject.strip_all(input_values)).equals(["VALUE1", "VALUE2"])
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
much-rails-0.4.3 test/unit/input_value_tests.rb
much-rails-0.4.2 test/unit/input_value_tests.rb
much-rails-0.4.1 test/unit/input_value_tests.rb
much-rails-0.4.0 test/unit/input_value_tests.rb
much-rails-0.3.0 test/unit/input_value_tests.rb
much-rails-0.2.8 test/unit/input_value_tests.rb
much-rails-0.2.7 test/unit/input_value_tests.rb
much-rails-0.2.6 test/unit/input_value_tests.rb