Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.46 KB | None | 0 0
  1. require 'rspec'
  2. require_relative 'implementations.rb'
  3.  
  4. RSpec.describe Implementations do
  5.   subject { described_class.new([1, 2, 3]) }
  6.  
  7.   describe '#valid?' do
  8.     context 'when array is not empty' do
  9.       it 'array valid' do
  10.         expect(subject.valid?).to eq true
  11.       end
  12.     end
  13.  
  14.     context 'when array empty' do
  15.       subject { described_class.new([]) }
  16.       it 'array nill' do
  17.         expect(subject.valid?).to eq false
  18.       end
  19.     end
  20.   end
  21.  
  22.   describe '#if_block_given?' do
  23.     context 'when block is given' do
  24.       it 'block given' do
  25.         expect(subject.if_block_given?).to eq true
  26.       end
  27.     end
  28.  
  29.     context 'when block is not given' do
  30.       it 'block is not given' do
  31.         expect(subject.if_block_given?).to eq false
  32.       end
  33.     end
  34.   end
  35.  
  36.   describe '#my_map' do
  37.     context 'when array valid' do
  38.       it 'should return right array' do
  39.         expect(subject.my_map { |element| element + 1}).to eq [2, 3, 4]
  40.       end
  41.     end
  42.   end
  43.  
  44.   describe '#my_select' do
  45.     context 'when array valid' do
  46.       it 'should return right array' do
  47.         expect(subject.my_select { |element| element > 2}).to eq [3]
  48.       end
  49.     end
  50.   end
  51.  
  52.   describe '#my_each' do
  53.     context 'when strings valid' do
  54.       it 'should return right string' do
  55.         expectation = expect do (subject.my_each { |element| puts element * 2 }) end
  56.         expectation.to output("2\n4\n6\n").to_stdout
  57.       end
  58.     end
  59.   end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement