thoughtbot/shoulda-matchers · error · NonNullableBooleanError

You have specified that your model's #{attribute} should ens

Error message

You have specified that your model's #{attribute} should ensure inclusion of nil.
However, #{attribute} is a boolean column which does not allow null values.
Hence, this test will fail and there is no way to make it pass.

What it means

Error "You have specified that your model's #{attribute} should ensure inclusion of nil. However, #{attribute} is a boolean column which does not allow null values. Hence, this test will fail and there is no way to make it pass." thrown in thoughtbot/shoulda-matchers.

Source

Thrown at lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:532

        def disallows_any_values_in_array?
          @array.any? do |value|
            disallows_value_of(value, @low_message)
          end
        end

        def allows_any_value_outside_of_array?
          if attribute_type == :boolean
            case @array
            when [false, true], [true, false]
              Shoulda::Matchers.warn boolean_allows_boolean_message
              return true
            when [nil]
              if attribute_column.null
                Shoulda::Matchers.warn boolean_allows_nil_message
                return true
              else
                raise NonNullableBooleanError.create(@attribute)
              end
            end
          end

          values_outside_of_array.any? do |value|
            allows_value_of(value, @low_message)
          end
        end

        def disallows_all_values_outside_of_array?
          if attribute_type == :boolean
            case @array
            when [false, true], [true, false]
              Shoulda::Matchers.warn boolean_allows_boolean_message
              return true
            when [nil]
              if attribute_column.null
                Shoulda::Matchers.warn boolean_allows_nil_message

View on GitHub (pinned to 79cdfbc326)

When it happens

Trigger: Thrown at lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:532 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of thoughtbot/shoulda-matchers@79cdfbc326 (2026-08-23). Data as JSON: /api/errors/a376781a185c2ded. Report an issue: GitHub.