{"action":"created","issue":{"url":"https://api.github.com/repos/antonmi/espec/issues/102","repository_url":"https://api.github.com/repos/antonmi/espec","labels_url":"https://api.github.com/repos/antonmi/espec/issues/102/labels{/name}","comments_url":"https://api.github.com/repos/antonmi/espec/issues/102/comments","events_url":"https://api.github.com/repos/antonmi/espec/issues/102/events","html_url":"https://github.com/antonmi/espec/issues/102","id":154830538,"number":102,"title":"`let` regression for nested scopes","user":{"login":"asaaki","id":446613,"avatar_url":"https://avatars.githubusercontent.com/u/446613?v=3","gravatar_id":"","url":"https://api.github.com/users/asaaki","html_url":"https://github.com/asaaki","followers_url":"https://api.github.com/users/asaaki/followers","following_url":"https://api.github.com/users/asaaki/following{/other_user}","gists_url":"https://api.github.com/users/asaaki/gists{/gist_id}","starred_url":"https://api.github.com/users/asaaki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asaaki/subscriptions","organizations_url":"https://api.github.com/users/asaaki/orgs","repos_url":"https://api.github.com/users/asaaki/repos","events_url":"https://api.github.com/users/asaaki/events{/privacy}","received_events_url":"https://api.github.com/users/asaaki/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/antonmi/espec/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/antonmi/espec/labels/ready%20to%20close","name":"ready to close","color":"fef2c0"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-05-14T02:54:53Z","updated_at":"2016-05-15T18:45:34Z","closed_at":"2016-05-15T18:45:34Z","body":"Following example spec will fail if a `let` function name is used in another scope as variable name again:\r\n\r\n#### Example spec\r\n\r\nSmallest possible code to reproduce the regression:\r\n\r\n```elixir\r\ndefmodule ExampleSpec do\r\n  use ESpec\r\n\r\n  describe \"let and nesting\" do\r\n    describe \"use let val\" do\r\n      let :result, do: 42\r\n\r\n      it \"is okay\" do\r\n        expect(result) |> to(eq 42)\r\n      end\r\n    end\r\n\r\n    describe \"use let name in example\" do\r\n      it \"is not okay\" do\r\n        result = 23 # error!\r\n        expect(result) |> to(eq 23)\r\n      end\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nSteps for a reproducible project:\r\n\r\n```\r\nmix new espec_let_regression && cd espec_let_regression\r\n# add espec dependency to mix.exs\r\nmix deps.get\r\nMIX_ENV=test mix espec.init\r\n# replace example spec with code above\r\nMIX_ENV=test mix espec\r\n```\r\n\r\n#### Error message\r\n\r\n```\r\nF.\r\n\r\n\t1) ExampleSpec ExampleSpec use let name in example is not okay\r\n\t/Users/chris/Development/PLAYGROUND/espec_let_regression/spec/example_spec.exs:14\r\n\t** (ESpec.LetError) The let function `result/0` is not defined in the current scope!\r\n    (espec) lib/espec/let/checker.ex:12: ESpec.Let.Checker.check/3\r\n    spec/example_spec.exs:14: ExampleSpec.example_is_not_okay_zrvdskjhfmyiaqcxwlptoneubg/1\r\n    (espec) lib/espec/example_runner.ex:62: ESpec.ExampleRunner.try_run/3\r\n    (espec) lib/espec/example_runner.ex:39: ESpec.ExampleRunner.run_example/2\r\n    (elixir) lib/enum.ex:1088: Enum.\"-map/2-lists^map/1-0-\"/2\r\n    (espec) lib/espec/runner.ex:71: ESpec.Runner.run_examples/1\r\n    (espec) lib/espec/runner.ex:44: ESpec.Runner.do_run/2\r\n    (espec) lib/espec/runner.ex:30: ESpec.Runner.handle_call/3\r\n\r\n\r\n\t2 examples, 1 failures\r\n\r\n\tFinished in 0.17 seconds (0.14s on load, 0.02s on specs)\r\n\r\n\tRandomized with seed 457604\r\n```\r\n\r\nThis error occurs also if the `let` and variable are spread across more levels of nesting, so I guess the `let`s are defined only globally for the spec module.\r\n\r\n#### Expectation\r\n\r\nEspec should respect the scoping and not try to use a `let` function name of another (not reachable) scope like seen above (sibling scopes).\r\n\r\nI organize tests in nested scopes heavily and always try to define `let`s in the deepest level possible. I use common names (like _result_) quite often, but had to do renaming for examples which defined a variable name used already in another scope's `let`.\r\n\r\n#### Environment\r\n\r\n- **Espec: 0.8.18**\r\n  (regression was introduced with 0.8.17; **0.8.16** and below are working!)\r\n- Elixir: 1.2.5\r\n- Erlang: 18.3\r\n- System: OSX 10.10\r\n"},"comment":{"url":"https://api.github.com/repos/antonmi/espec/issues/comments/219303122","html_url":"https://github.com/antonmi/espec/issues/102#issuecomment-219303122","issue_url":"https://api.github.com/repos/antonmi/espec/issues/102","id":219303122,"user":{"login":"asaaki","id":446613,"avatar_url":"https://avatars.githubusercontent.com/u/446613?v=3","gravatar_id":"","url":"https://api.github.com/users/asaaki","html_url":"https://github.com/asaaki","followers_url":"https://api.github.com/users/asaaki/followers","following_url":"https://api.github.com/users/asaaki/following{/other_user}","gists_url":"https://api.github.com/users/asaaki/gists{/gist_id}","starred_url":"https://api.github.com/users/asaaki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asaaki/subscriptions","organizations_url":"https://api.github.com/users/asaaki/orgs","repos_url":"https://api.github.com/users/asaaki/repos","events_url":"https://api.github.com/users/asaaki/events{/privacy}","received_events_url":"https://api.github.com/users/asaaki/received_events","type":"User","site_admin":false},"created_at":"2016-05-15T18:45:34Z","updated_at":"2016-05-15T18:45:34Z","body":"I also confirm that the published version is working. Closing this issue."}}