Mar 25, 2017
Test context builder is an npm package I wrote to
complement db-fabricator. The main purpose of db-fabricator
is to setup test context data for integration testing. However, setting up test context data gets repetitive and
verbose for each test. In many cases you have the same basic object that most of your tests need. So it would be
nice to be able to define a set of basic contexts that you often use and be able to build on
top of it. This is what test-context-builder is for.
Mar 12, 2017
It hasn’t been that long since I released DB Fabricator version 1.0. But I quickly realized the limitation as I use it more
on my project. The biggest annoyance is the fact that when you want to fabricate an object that depends on another
fabricated object, you have to fabricate the dependency after resolving the root object promise,
resulting in a somewhat verbose nested code like this:
Jan 16, 2017
When writing end to end tests, we often need to set up a context by creating some data in database.
Each test case should start with a clean slate and have data that are created only for that test.
So it’s important to make creating these test data as simple as possible.
Apr 5, 2016
Shared examples is a great RSpec feature that allows you to reuse test cases in different context.
One use case is when you need to test different access level to a resource depending on the role.
Lets say you have a resource that can have published/draft state. There are several roles with
different access level to this resource.
Mar 15, 2016
Sometime you just want to see the SQL statement that your ActiveRecord magically generate, without going through hundreds of lines in your log file. An easy way to do that is to assign the
ActiveRecord::Base.logger to a new
Logger that prints to the
STDOUT, and then change it back to the old logger so it doesn’t keep printing out SQL for the rest of your code.
Jan 31, 2016
Tempfile gives you an easy way to quickly create a temporary file without having to worry about generating a file name that doesn’t already exist and cleaning up the file after you are done. However, you have to be aware that the temporary file will be deleted when the tempfile instance is garbage collected.
Jan 28, 2016
Grape is a Rack based Ruby framework for building API.
It’s only a few years old and has not reached version 1.0 yet. The main github page has a very good documentation but
is still not as complete as Rails guide. In this post, I will discuss how to test file upload endpoint with RSpec.
Jan 23, 2016
It’s all too common to find the use of backtick to run shell command from Ruby. It’s fine when you just run a command that doesn’t take any user input. But when you start passing input from untrusted source, that’s when the trouble begins.
Sep 13, 2015
When it comes to implementing ActiveRecord nesting, there are a few popular implementations. In this post I will look closer at how Ancestry and Closure tree work and what the pros and cons are.
Sep 7, 2015
After using git for a long time, I thought I knew the basic of gitignore well enough, until I ran into problem with my files not getting committed. There were some basic gitignore patterns that most git users are just not aware of. So some of us might have put something on gitignore without realizing that it does ignore a lot more stuff than we intend.