factory(factory_name)
to define a factory
factory(:user) do
%User{name: "John"}
end
create(:user, name: "Jane")
build(:user, name: "Jane")
assoc(:author, factory: :user)
(can only be used inside factory definition)
def render(conn, assigns \\ []), do: render(conn, action_name(conn), assigns) |
exports.config = { | |
// See http://brunch.io/#documentation for docs. | |
files: { | |
javascripts: { | |
joinTo: 'js/app.js', | |
// To use a separate vendor.js bundle, specify two files path | |
// https://github.com/brunch/brunch/blob/stable/docs/config.md#files | |
// joinTo: { | |
// 'js/app.js': /^(web\/static\/js)/, | |
// 'js/vendor.js': /^(web\/static\/vendor)/ |
defmodule MyApp.Fixtures do | |
alias MyApp.Repo | |
alias MyApp.User | |
def fixture(:user) do | |
%User{name: "Daniel Berkompas", email: "[email protected]"} | |
end | |
# Example: create(:user) | |
def create(record) do |
So the proposed solution is to change production code to be "testable" and making production code to call Application configuration for every function call? This doesn't seem like a good option as it's including a unnecessary overhead to make something "testable". | |
It is improving the design of your code. | |
A test is a user of your API like any other code you write. One of the ideas behind TDD is that tests are code and no different from code. If you are saying "I don't want to make my code testable", you are saying "I don't want to decouple some modules" or "I don't want to think about the contract behind these components". | |
Just to clarify, there is nothing wrong with "not wanting to decouple some modules". You don't want to decouple every time you call the URI module, for example. But if we are talking about something as complex as an external API, a SSH connection or such, defining a explicit contract and passing the contract as argument is going to make your code wonders and make it easier to manage your |
factory(factory_name)
to define a factoryfactory(:user) do
%User{name: "John"}
end
create(:user, name: "Jane")
build(:user, name: "Jane")
assoc(:author, factory: :user)
(can only be used inside factory definition)
# This is a bit more flexible. Worried people will try to call it directly :S | |
# Also throws warnings if you put functions in between the function definitions | |
def factory(:user, attrs) do | |
%User{ | |
first_name: "Paul" , | |
last_name: "Smith" | |
email: put_new_email(attrs) | |
} | |
end |
defmodule MyApp.Factory do | |
use ExMachina.Ecto, repo: MyApp.Repo | |
def factory(:interest, attrs) do | |
%Interest{ | |
name: sequence(:interest_name, &"interest-#{&1}") | |
} | |
end | |
def factory(:user, attrs) do |
defmodule MyApp.AnnouncementTraits do | |
def with_subscriber(announcement, user) do | |
create(:subscription, announcement: announcement, user: user) | |
announcement | |
end | |
def tag_with_interest(announcement, interest) do | |
create(:announcement_interest, announcement: announcement, interest: interest) | |
announcement | |
end |
Bypass fake_stripe do | |
get "soemthing" do | |
send_resp conn, "" | |
end | |
end |