germsvel

germsvel

Test-Driven Development with Phoenix (self-published) (free)

:waving_hand: Hi there,

I’ve been working on a Test-Driven Development with Phoenix book. It teaches TDD and BDD by building a chat app from the outside-in. It’s still a work in progress, but the overall TDD process is clear, and the application that we build throughout the book is fully functional. So, I believe people can already benefit from it.

The book is freely available online at tddphoenix.com.

If you’re interested in the process of writing it, I talked some about it in episode 18 of the Thinking Elixir podcast

I hope some find it helpful.

First 10 of 44 Posts Switch mode

imartinat

imartinat

It seems awesome. Thanks for this great free book.

imartinat

imartinat

I really like your book and the explanations. The first time I tried to use Wallaby, I had an error "
Wallaby can’t find phantomjs" . So I installed chromedriver and I setup Wallaby using chromedriver. It might be good to update your book to setup Wallaby with phantomjs or chromedriver. Thanks again for your book.

joelwallis

joelwallis

This is awesome! I’m learning Phoenix and I currently struggle to put TDD into practice.

I’ll definitely be reading your book. Thank you!

germsvel

germsvel OP

Thanks! I definitely need to add a little note about that at the beginning. It’ll be there when I push the next set of changes.

idlehands

idlehands

Author of Testing Elixir

Fantastic! I will try to take a look soon and then share it out as a resource. Thank you!

Qqwy

Qqwy

TypeCheck Core Team

Thank you very much for creating this!

Before parting, let’s take a moment to see what we have accomplished. We’ve written an entire application without opening our browsers. When was the last time you did that?

Very nice :grin:

The one piece of feedback I would like to share after reading through it (some sections thoroughly, some sections skimmingly) is that you do not mention property-based testing. Even if only as a footnote, mentioning it might help people to discover it as one more cool tool for their testing toolbox.

mstibbard

mstibbard

I can’t seem to get this working at all… Even with chromedriver and phantomjs installed.

imartinat

imartinat

I am on a mac, I installed Chromedriver and moved it to /usr/local/bin (or you need to add it to your PATH).
And in config.exs, I added

config :wallaby,
  driver: Wallaby.Experimental.Chrome,
  chromedriver: [headless: true]
mstibbard

mstibbard

Thanks, adding that to config/test.exs & chromedriver to PATH changed the error message at least!!

$ mix test
Compiling 18 files (.ex)
Generated chatter app
** (MatchError) no match of right hand side value: {:error, {:wallaby, {{:shutdown, {:failed_to_start_child, Wallaby.Experimental.Chrome, {:shutdown, {:failed_to_start_child, Wallaby.Experimental.Chrome.Chromedriver, {:eacces, [{:erlang, :open_port, [{:spawn_executable, "c:/projects/chatter/_build/test/lib/wallaby/priv/run_command.sh"}, [:binary, :stream, :use_stdio, :stderr_to_stdout, :exit_status, {:args, ["c:/tools/chromedriver/chromedriver.exe", "--log-level=OFF", "--port=57042"]}]], [file: 'erlang.erl', line: 2215]}, {Wallaby.Experimental.Chrome.Chromedriver, :init, 1, [file: 'lib/wallaby/experimental/chrome/chromedriver.ex', line: 22]}, {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 374]}, {:gen_server, 
:init_it, 6, [file: 'gen_server.erl', line: 342]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}}}}}, {Wallaby, :start, [:normal, []]}}}}
    test/test_helper.exs:4: (file)
    (elixir 1.10.2) lib/code.ex:917: Code.require_file/2
    (elixir 1.10.2) lib/enum.ex:783: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir 1.10.2) lib/enum.ex:783: Enum.each/2
germsvel

germsvel OP

What version of Wallaby are you using?

In version 0.25 and newer, Chrome stopped being experimental, so the config changes to

config :wallaby, driver: Wallaby.Chrome

If that doesn’t fix the issue, make sure you include the following in your test/test_helper.exs:

{:ok, _} = Application.ensure_all_started(:wallaby)
Application.put_env(:wallaby, :base_url, YourApplication.Endpoint.url)

That your config/test.exs file has server: true and the sql_sandbox flag:

config :chatter, Chatter.Endpoint,
  server: true

config :chatter, :sql_sandbox, true

And then use that flag in your endpoint:

  use Phoenix.Endpoint, otp_app: :chatter

  if Application.get_env(:chatter, :sql_sandbox) do
    plug Phoenix.Ecto.SQL.Sandbox
  end

Hopefully, just one of those steps is missing. Wallaby’s setup docs are pretty good. So check them out if you still have problems.

Where Next?

Trending in Books Top

PragmaticBookshelf
Bruce A. Tate @redrapids and Sophie DeBenedetto @SophieDeBenedetto edited by Jacquelyn Carter @jkcarter The days of the traditional requ...
New
PragmaticBookshelf
Isaak Tsalicoglou Built for the curious, this isn’t your average programming book—it’s nearly 500 pages of hands-on mentorship beyond cod...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement