Sha256: 6d37f0b0b6e1285ffa7c60f6f00fbf3e49fdc323b9cb7fd686fc99951e73a3c7

Contents?: true

Size: 1.68 KB

Versions: 17

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

require "assert"
require "much-rails/config"

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

    let(:unit_class){ MuchRails::Config }

    should "include MuchRails::Mixin" do
      assert_that(subject).includes(MuchRails::Mixin)
    end
  end

  class ReceiverTests < UnitTests
    desc "receiver"
    subject{ receiver_class }

    setup do
      class receiver_class::Config
        attr_accessor :value
      end

      class receiver_class::AnotherConfig
        include MuchRails::Config

        add_instance_config :sub, method_name: :sub

        attr_accessor :another_value

        class SubConfig
          attr_accessor :sub_value
        end
      end
    end

    let(:receiver_class) do
      Class.new do
        include MuchRails::Config

        add_config
        add_config :another
      end
    end

    should have_imeths :config, :another_config

    should "know its attributes" do
      assert_that(subject.config).is_instance_of(subject::Config)
      subject.configure{ |config| config.value = "VALUE 1" }
      assert_that(subject.config.value).equals("VALUE 1")

      assert_that(subject.another_config).is_instance_of(subject::AnotherConfig)
      subject.configure_another{ |config| config.another_value = "VALUE 2" }
      assert_that(subject.another_config.another_value).equals("VALUE 2")

      assert_that(subject.another_config.sub)
        .is_instance_of(subject::AnotherConfig::SubConfig)
      subject.another_config.configure_sub do |sub|
        sub.sub_value = "VALUE 3"
      end
      assert_that(subject.another_config.sub.sub_value).equals("VALUE 3")
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
much-rails-0.4.2 test/unit/config_tests.rb
much-rails-0.4.1 test/unit/config_tests.rb
much-rails-0.4.0 test/unit/config_tests.rb
much-rails-0.3.0 test/unit/config_tests.rb
much-rails-0.2.8 test/unit/config_tests.rb
much-rails-0.2.7 test/unit/config_tests.rb
much-rails-0.2.6 test/unit/config_tests.rb
much-rails-0.2.5 test/unit/config_tests.rb
much-rails-0.2.4 test/unit/config_tests.rb
much-rails-0.2.3 test/unit/config_tests.rb
much-rails-0.2.2 test/unit/config_tests.rb
much-rails-0.2.1 test/unit/config_tests.rb
much-rails-0.2.0 test/unit/config_tests.rb
much-rails-0.1.3 test/unit/config_tests.rb
much-rails-0.1.2 test/unit/config_tests.rb
much-rails-0.1.1 test/unit/config_tests.rb
much-rails-0.1.0 test/unit/config_tests.rb