Skip to content

Commit

Permalink
Add specs for the it variable in blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
herwinw committed Dec 3, 2024
1 parent 2ca97d4 commit d6d1fb9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions language/it_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative '../spec_helper'

describe "The it parameter" do
it "should use the local variable if exists" do
it = 123
[1, 2, 3].map { it }.should == [123, 123, 123]
end

ruby_version_is ""..."3.4" do
it "should use the method if no local variable exists" do
# This test is hacky: we now depend on the `it` method of the specs
suppress_warning do
-> {
eval("[1, 2, 3].map { it }")
}.should raise_error(ArgumentError, "wrong number of arguments (given 0, expected 1)")
end
end
end

ruby_version_is "3.4" do
it "should act as the first argument if no local variable exists" do
# eval is required for suppress_warning
eval("[1, 2, 3].map { it }").should == [1, 2, 3]
end
end
end

0 comments on commit d6d1fb9

Please sign in to comment.