diff --git a/language/it_spec.rb b/language/it_spec.rb new file mode 100644 index 000000000..388faaaf8 --- /dev/null +++ b/language/it_spec.rb @@ -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