require 'spec_helper'
require 'monad_integration'

describe :return do
	it 'should not change result of function with no arguments' do
		func = MonadIntegration::return do |operations|
			123
		end

		expect(func.call).to equal(123)
	end

	it 'should return from a function with no arguments' do
		func = MonadIntegration::return do |operations|
			operations.return 123
			456
		end

		expect(func.call).to equal(123)
	end

	it 'should return from nested calls' do
		func = MonadIntegration::return do |operations|
			[123].each do |item|
				operations.return item
			end
		end

		expect(func.call).to equal(123)
	end

	it 'nested monads should return where appropriate' do
		func = MonadIntegration::return do |operations1|
			func2 = MonadIntegration::return do |operations2|
				operations1.return 123
				operations2.return 456
			end
			func2.call + 4
		end

		expect(func.call).to equal(123)
	end
end