Sha256: 1a36fd06a89cd1b76cb9a1e89b0d29c6ee5cbf36782d12981ed9aa22180d1ffc

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

require 'cucumber/initializer'

module Cucumber
  describe 'generating initializers' do
    class Book
      include Cucumber.initializer(:title, :author)

      def description
        "#{title} by #{author}"
      end

      def upcase!
        @title.upcase!
        @author.upcase!
      end
    end

    let(:cucumber_book) { Book.new('The Cucumber Book', 'Matt Wynne') }

    it 'raises an ArgumentError when initialized with the wrong number of arguments' do
      expect { Book.new() }.to raise_error(ArgumentError, 'wrong number of arguments (0 for 2)')
    end

    it 'creates a private reader for the attributes' do
      expect { cucumber_book.title  }.to raise_error NoMethodError
      expect { cucumber_book.author }.to raise_error NoMethodError
    end

    it 'creates readers for the attributes' do
      expect( cucumber_book.description ).to eq 'The Cucumber Book by Matt Wynne'
    end

    it 'creates instance variables for the attributes' do
      cucumber_book.upcase!
      expect( cucumber_book.description ).to eq 'THE CUCUMBER BOOK by MATT WYNNE'
    end

    context 'with an overridden reader' do
      class Score
        include Cucumber.initializer(:score)
        attr_reader :score
      end

      it 'makes the reader public' do
        expect { Score.new(12).score }.to_not raise_error
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cucumber-core-1.0.0.beta.4 spec/cucumber/initializer_spec.rb
cucumber-core-1.0.0.beta.3 spec/cucumber/initializer_spec.rb
cucumber-core-1.0.0.beta.2 spec/cucumber/initializer_spec.rb
cucumber-core-1.0.0.beta.1 spec/cucumber/initializer_spec.rb
cucumber-core-0.2.0 spec/cucumber/initializer_spec.rb
cucumber-core-0.1.0 spec/cucumber/initializer_spec.rb