调试测试时,可以很容易地在其中放置一些IO.inspect
语句来查看正在发生的事情。这很有效,直到对象变得太大。
运行mix
时iex
等同于IEx.configure [inspect: [limit: 1000]]
的{{1}}是什么?
答案 0 :(得分:3)
IEx.configure [inspect: [limit: 1000]]
仅更改inspect
对输入的每个表达式进行的iex
自动IO.inspect
调用的选项,并且不会更改实际IO.inspect
函数的行为。您必须在IO.inspect
周围创建一个包装,然后使用它而不是test "the truth" do
list = Enum.to_list(1..100)
IO.inspect list
i list
end
defp i(item, opts \\ []) do
IO.inspect(item, Keyword.put(opts, :limit, 1000))
end
:
$ mix test
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, ...]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
.
Finished in 0.03 seconds
1 test, 0 failures
输出:
create table user_options
( user_id int auto_increment primary key,
email_sent_at date not null,
days_gap int not null
);
insert user_options values
(1, '2016-07-27', 2),
(2, '2016-07-24', 2),
(3, '2016-07-22', 5),
(4, '2016-07-21', 3);
select * from user_options where email_sent_at < CURRENT_DATE - INTERVAL days_gap DAY;
+---------+---------------+----------+
| user_id | email_sent_at | days_gap |
+---------+---------------+----------+
| 2 | 2016-07-24 | 2 |
| 4 | 2016-07-21 | 3 |
+---------+---------------+----------+