Skip to content

Commit

Permalink
Naming things
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Zelazny committed Jan 10, 2015
1 parent 92fa861 commit 59167b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ Here is a basic test with independent givens:

```erlang

bddr:test([given_app_started(),
given_user_in_db("user", "password")],
bddr:test([given_app_started(),
given_user_in_db("user", "password")],

fun([App,{User,Pass}]) ->
when_user_logs_in(App, User, Pass) end,
fun([App,{User,Pass}]) ->
when_user_logs_in(App, User, Pass) end,

fun(Screen) ->
"Welcome, User!" = welcome_text(Screen) end).
fun(Screen) ->
"Welcome, User!" = welcome_text(Screen) end).

```

## ...it doesn't do XYZ?

No, the implementation is four lines of code. No parse transforms, no macros.
It's the developer's responsibility to provide his/her abstractions for the
tested components. Remember, your tests are just Erlang code. Make it readable
and extensible for others. Be humane.
No, the implementation is four lines of code. No parse transforms, no
macros. It's the developer's responsibility to provide his/her abstractions for
the tested components. Remember, your tests are just Erlang code. Make it
readable and extensible for others. Be humane.

----------

Expand Down
14 changes: 6 additions & 8 deletions test/bddr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ when_clause_can_access_givens(_) ->
fun(_) -> ok end).

when_cannot_access_givens_bindings(_) ->
%% This code will not compile, producing the compiler error:
%% bddr_SUITE.erl:23: variable 'AGiven' is unbound
%% bddr_SUITE.erl:22: Warning: variable 'AGiven' is unused

%% Below we prove it, using dynamic_compile.
%% The BadTest code will not compile, producing a compiler error like:
%% your_SUITE.erl:99: variable 'AGiven' is unbound
%% your_SUITE.erl:98: Warning: variable 'AGiven' is unused
%% We prove it below, using dynamic_compile.
true = compiles(
"-module(good_test).\n"
"-export([good_test/0]).\n"
Expand All @@ -55,16 +54,14 @@ when_cannot_access_givens_bindings(_) ->
"-module(bad_test).\n"
"-export([bad_test/0]).\n"
"bad_test() ->\n"
" bddr:test([G = 1],fun(_)-> G end,fun(R)-> 1 = R end).\n").

" bddr:test([AGiven = 1],fun(_)-> AGiven end,fun(R)-> 1 = R end).\n").

when_with_unexpected_givens_raises_function_clause(_) ->
true = ?raises_function_clause(
bddr:test([1,2,3],
fun([wrong,args]) -> nay end,
fun(_) -> ok end)).


then_clause_can_access_action_result(_) ->
bddr:test(
[1],
Expand All @@ -86,6 +83,7 @@ then_with_unexpected_result_raises_function_clause(_) ->

%% Non-test functions


compiles(Source) ->
try {ModName, Bin} = dynamic_compile:from_string(Source),
is_atom(ModName) andalso is_binary(Bin)
Expand Down

0 comments on commit 59167b9

Please sign in to comment.