Skip to content

Instantly share code, notes, and snippets.

@AlexVPopov
Created December 5, 2013 15:31
Show Gist options
  • Save AlexVPopov/7807535 to your computer and use it in GitHub Desktop.
Save AlexVPopov/7807535 to your computer and use it in GitHub Desktop.
Tests for challenge 11 of the FMI ruby course
require 'spec_helper'
ivan = Student.new 'Иван', 10, :second
mariya = Student.new 'Мария', 12, :first
neycho = Student.new 'Нейчо', 9, :third
students = [ivan, mariya, neycho]
describe "Array#to_proc" do
it "works for a single element" do
[:abs].to_proc.call(-42).should eq [42]
end
it 'should work for arrays with multiple elements' do |variable|
[:points, :name].to_proc.call(ivan) # => [10, 'Иван']
end
it "should work with ampersand" do
expect(students.map(&[:name, :rank])).to eq [['Иван', :second],
['Мария', :first],
['Нейчо', :third]]
end
end
describe "Hash#to_proc" do
let(:student) { Class.new { attr_accessor :points, :rank }.new }
it "sets the properties of the object which correspond to its key value pairs" do
{points: 0}.to_proc.call(student)
student.points.should eq 0
end
it "should work with ampersand" do
students.each &{points: 0, rank: :last}
expect(students.map(&:points)).to eq [0, 0, 0]
expect(students.map(&:rank)).to eq [:last, :last, :last]
end
end
@mitio
Copy link

mitio commented Dec 5, 2013

Тук е добра идея да си inline-неш този Student клас. Или дори да го направиш анонимен такъв.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment