waterlink / spec2.cr

Enhanced `spec` testing library for [Crystal](http://crystal-lang.org/).
MIT License
103 stars 22 forks source link

Error when describing multiple array method names like #[] and #[]? #46

Open Papierkorb opened 7 years ago

Papierkorb commented 7 years ago

Hello,

Spec2 seems to mangle "#[]" and "#[]?" into the same module name Spec2___Root::Spec2__Array::Spec2___.

This results in the error already initialized constant Spec2___Root::Spec2__Array::Spec2___::SPEC2_FULL_CONTEXT

Platform Crystal 0.19.4 (2016-10-07) on Linux, Spec2 at eef5144d86f3aadf95811ffc0450be389db36fed

Code snippet

require "spec2"

Spec2.describe Array do
  describe "#[]?" do # Each on their own is fine
    it "returns nil" do
      expect(([ 3, 4 ])[2]?).to be_nil
    end
  end

  describe "#[]" do
    it "raises IndexError" do
      expect{ ([ 3, 4 ])[2] }.to raise_error IndexError
    end
  end
end

Note: This also happens with #[]=

Thanks

waterlink commented 7 years ago

I guess, we ought to transform special symbols into some meaningful words. For example #[]= will become: __sharp____openbrace____closebrace____equals__. Are you up for making a pull request?

Also, it can be worked around in your code with specifying some sort of conceptual description in your describe after the name of the method:

describe "#[] - index accessing operator" do
  # ..
end