Created
December 5, 2013 15:31
-
-
Save AlexVPopov/7807535 to your computer and use it in GitHub Desktop.
Tests for challenge 11 of the FMI ruby course
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Тук е добра идея да си inline-неш този
Student
клас. Или дори да го направиш анонимен такъв.