Sha256: 7f7b41f7eabe379c8212fbc9eb6e8cbfa079c1f10a6f306f47c6431cf9bea5b5

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe Vanguard::DSL, 'guard specs' do
  include Spec::Shared::DSL

  before do 
    class_under_test.class_eval do
      def foo?
        !!@foo
      end

      attr_accessor :foo
    end
    builder.validates_presence_of(attribute_name,options) 
  end

  context 'with :if option' do
    let(:options) { { :if => :foo? } }
    
    context 'when predicate is true' do
      before do
        resource.foo = true
      end

      describe 'when validated attribute is present' do
        let(:attribute_value) { :foo }

        it_should_be_a_valid_instance
      end

      describe 'when validated attribute is absent' do
        let(:attribute_value) { nil }

        it_should_be_an_invalid_instance
      end
    end
    
    context 'when predicate is false' do
      before do
        resource.foo = false
      end

      describe 'when validated attribute is present' do
        let(:attribute_value) { :foo }

        it_should_be_a_valid_instance
      end

      describe 'when validated attribute is absent' do
        let(:attribute_value) { nil }

        context 'and options include :if predicate' do
          it_should_be_a_valid_instance
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vanguard-0.0.5 spec/integration/vanguard/dsl/guard_spec.rb
vanguard-0.0.4 spec/integration/vanguard/dsl/guard_spec.rb
vanguard-0.0.3 spec/integration/vanguard/dsl/guard_spec.rb