Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to spec private functions? #21

Closed
NobbZ opened this issue Apr 24, 2015 · 2 comments
Closed

Is there a way to spec private functions? #21

NobbZ opened this issue Apr 24, 2015 · 2 comments

Comments

@NobbZ
Copy link

NobbZ commented Apr 24, 2015

Consider the following:

defmodule Foo
  defp bar do
    :quux
  end
end

How am I supposed to write a spec against Foo.bar? Obviously the following doesn't work:

defmodule FooSpec do
  use ESpec

  it do
    expect(Foo.bar).to be :quux
  end
end

It does fail with an UndefinedFunctionError.

@antonmi
Copy link
Owner

antonmi commented Apr 24, 2015

There is no way to access private functions in Elixir outside the module where they are defined (as in Erlang too).
But in BDD specs you should test the behavior (which is public) not details of implementation (private functions).
Read the Jose Valim answer here: http://stackoverflow.com/questions/20949358/is-there-a-way-to-test-private-functions-in-modules-in-exunit-of-elixir

@antonmi antonmi closed this as completed Apr 24, 2015
@NobbZ
Copy link
Author

NobbZ commented Apr 24, 2015

OK. Im fine with that and already used to it from other languages. But
since I'm trying to use elixir for a project at university I have to test
as much as possible directly. Since it is not possible I don't have to :-D
Am 24.04.2015 11:41 schrieb "Anton Mishchuk" notifications@github.com:

Closed #21 #21.


Reply to this email directly or view it on GitHub
#21 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants