The First Feature is the Hardest | Upcase

Ben joins Joe and build out the first feature in a Rails application, from scratch. Learn our process for jump-starting new applications using Suspenders. We'll also use our first integration test to help sketch out the first interactions in the a...
This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/the-first-feature-is-the-hardest

I like the use of the snippets @jferris. In your dotfiles it looks like youā€™re using snippetsEmu, but it seems that plug-in hasnā€™t been updated for several years, would you still recommend it?

Itā€™s still working fine, but it does have some rough edges. I havenā€™t looked around in a long time to see if there are better snippets plugins, so it may be worth a check before using snippetsEmu.

Did you somehow automatically switch from full-screen terminal to a split between half-browser and half-terminal there? Or was that just video magic?

At what part (or parts) would you commit and push your progress?
In this case itā€™s a very straightforward example, but what would your commit strategy be in general? commit/push on every change, every time the tests are green, other times?

1 Like

I commit and push (to a new branch, not master) pretty often. It probably averages out to every 5-10 minutes.

I donā€™t really have a strategyā€“I just donā€™t want to lose any work.

Later, I squash all my commits down to one and write a great commit message. But while Iā€™m working, Iā€™ll write very short messages, and sometimes just commit with a message of ā€œWIPā€ (work in progress).

Great video, guys.

@jferris when you finished with the feature, you mentioned that you would open a PR and then take the next feature/story/card from the list.

This is an interesting one for me and my team; Iā€™m in two minds about whether someone should go on to the next card straight away, or wait for the first cardā€™s PR to get merged.

What are your thoughts on this, guys? Is there a thoughtbot protocol here?

My strategy is similar to Benā€™s.

Even if things are broke I donā€™t want to lose the work I will commit and push that up to a branch. At the end rebase it on master and squish any useless commits down and force push over my old branch, then submit a pull request.

This is mostly so my git repo is always in sync with my latests changes and if I switch to my home computer or to my work computer from my home computer I always have a copy of the code I need.

@jferris Why did you use :string when running rails g model? Rails infers a string type when none is supplied. Is there some advantage to explicitly declaring the string type?

Didnā€™t know that!

Still, I think itā€™s generally better to be explicit rather than relying on implicit behavior, unless that behavior is very well known.

1 Like

Agreed. Especially when doing a tutorial type of video.

Awesome! Just wanted to make sure I wasnā€™t missing out on some magic. :smile:

We try to have as little in flight as possible. This means that, before I start on another card, Iā€™ll poke somebody to get a review and try to wait until it can be fully deployed, even if this means I need to pause work for a bit. Iā€™ll generally use this down time to catch up on email and so on.

Iā€™m very careful about having several stories going on at once.

1 Like

I didnā€™t know it was inferred!

1 Like

Nice - makes sense. Thanks, @jferris.

Hey guys,

Great video!

One thing I noticed was that in the feature spec you were hardcoding the content that you expected to see on the page (e.g. ā€œPaste It!ā€ and ā€œcanā€™t be blankā€). I know that in one of TBā€™s blog posts titled Better Tests Through Internationalization (link), itā€™s recommended to use i18n in those places rather than hardcoded strings in order to make the tests more resilient to copy changes. For example,

click_on "Paste It!"

would become

click_on t("helpers.submit.paste.create")

@jferris @benorenstein Which one do you prefer to use in practice?

I have mixed feelings about the i18n approachā€¦ On the one hand, it definitely makes the tests less brittle; I can go in and make an innocuous copy change and not have to also change any of the tests. On the other hand, it abstracts (or completely hides away) the actual content so itā€™s unclear from looking at the test what it will be. This is especially troublesome if you donā€™t have exceptions turned on for missing translations because your test can pass while the user sees a ā€œmissing translationā€¦ā€ error on the page itself.

What does everyone think?

1 Like

Weā€™ve gone back and forth on this a bit at thoughtbot.

The dominant opinion seems to be that using I18n in both views and tests is preferred. It does add some abstraction, but it prevents fragile tests or tests which no longer actually test anything. It also adds the benefit of not being tied to a particular language.

I used plain text in the video for the sake of clarify, simplicity, and time.

Makes sense. Thanks for the explanation Joe!

I agree, click_on t("helpers.submit.paste.create") isnā€™t particularly readable. But this might be an indication that the test could be written at a higher level of abstraction. If you focus on the business rule being described, then the exact text on the submit button is usually an incidental detail.

One way around this could be to move the call to click_on t(...) to behind a method, e.g. submit_paste.

Or you could use a Page Object, and call it with something like new_paste_form.submit.

3 Likes

@jferris Iā€™d love to know how to do this too.