THE BITESITE BLOG
Rspecrabljsonresponses

Failing RSpec Tests when using RABL for JSON Responses

rabl rspec ruby on rails software coding

After about 5 years of doing Ruby on Rails development, there is one aspect that for the longest time never seemed to sit well with me: TDD. It wasn't that I didn't understand the benefits, and it wasn't that I didn't believe in it, but unlike many things Rails, there wasn't enough concrete motivation to do it. Over the past few months I finally started to get into it and I'll write all about my experiences in another post, but for now, I wanted to let you guys know about a specific problem I was having with TDD'ing an API I built.

I was building an API for a app using Ruby on Rails and following the http://apionrails.icalialabs.com/.

To render my JSON responses, I almost always use RABL now. I tried activemodelserializers when I was experimenting with Ember, but I quickly switched back to RABL.

Anyway, I was writing my tests I was having issues testing my JSON response. My typically test would look something like this:

it "renders a response" do create(:route) get :index, format: :json response_object = JSON.parse(response.body) expect(response_object.size).to eq(1) end

The issue is that no matter what I did, it seemed that my tests would fail. Upon further inspection, it looked like the response.body was empty. I was getting really frustrated so what I did was I abandoned my TDD and just tried it in the browser (well, more accurately in Postman). To my surprise, it was working.

So why were my tests failing and why was the response.body empty?

It all has to do with the fact that I was using RABL for the JSON responses. Because RABL uses Rails view rendering and by default Controller specs don't render views - the response.body was empty.

So the solution was as simple as adding

render_views

to the top of my specs so I had the followiing:

require 'spec_helper' describe Api::V1::MyController, type: :controller do render_views ... end

Alright, that's it for now. Hopefully this helps some peeps.

Caseyli
Casey Li
CEO & Founder, BiteSite
Rspecgemfilelock

Rails 4, Rspec not letting go of Gemfile.lock, can't Git Pull, can't checkout

rspec software coding

Alright, this is going to be a super quick post but thought I'd let people know as this has come up a couple of times.

The environment is

  • Rails 4 or above
  • Git
  • Rspec for testing

So here's the issue. Every now and then, I try to do a Git Pull (say after a pull request has been merged) and Git won't let me because it seems my Gemfile.lock has some local changes that would be overwritten.

Easy enough, right? Just stash, or discard the changes. So I tried running 'git stash', or 'git checkout Gemfile.lock'. But then right after, I do a 'git status', and low and behold, the Gemfile.lock still has local changes. What the hell? Why isn't Git letting me stash the changes.

Well, it turns out, Git is letting me stash the changes, but very shortly after, something is changing the Gemfile.lock file right away. So right after I stash my changes, or discard, something comes right back and makes the changes again.

The culprit? Rpsec- well more specifically spring. So after running rspec, spring continues to run. As far as I understand, spring keeps your Rails environment running so you don't have to reload it on every rspec run (as far as I know, I could be way off). But the short of it is, the first time your run rspec, it fires up spring, and spring holds onto your Gemfile.lock.

So after you discard your changes, spring will apply the changes right again on Gemfile.lock (and perhaps other files).

How to solve it?

Simply stop spring by running "spring stop". At that point, you should have no issue discarding your changes using Git.

Worried about spring being stopped? Don't worry, it starts up again the next time you run rspec.

Alright, that's it for now. Hope that helps some peeps!

Caseyli
Casey Li
CEO & Founder, BiteSite
Railsnamecheapemail

Ruby on Rails ActionMailer Configuration for Namecheap Private E-mail

software coding

Ever try setting up Ruby on Rails to use Namecheap's private e-mail to no avail. Me too. Finally figured out some settings that made things work.

First off, for your smtp settings:

config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => 'mail.privateemail.com', :port => 26, :user_name => 'username@domain.com, :password => 'yourpassword, :authentication => :plain, :enable_starttls_auto => true }

Of course, you can throw everything into environment variables.

config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => ENV['SMTP_SERVER'], :port => ENV['SMTP_PORT'], :user_name => ENV['SMTP_USER'], :password => ENV['SMTP_PASSWORD'], :authentication => :plain, :enable_starttls_auto => true }

But the key thing here, or at least the thing that's unusual is PORT 26!!! It's right there in Namecheap's documentation but they say if you're going to use starttls - you must use port 26. That was the main thing that I seemed to stumble on. The other settings are very similar to say GMail settings.

Also, I did set my "from" address in my Mailer class to match my domain which may or may not have helped - I was too lazy to do a controlled experiment on that.

Anyway, hope that helps some peeps.

Caseyli
Casey Li
CEO & Founder, BiteSite
Aeeditingmaskpaths

After Effects Editing Mask Path (moving individual points)

film after effects motion graphics

Alright, this was frustrating the hell out of me - especially considering most posts and forum responses had the right idea but were missing one key element.

The issue is in Adobe After Effects and Masks.

Here's the setup

  • You have some layer (shape, picture, footage, whatever)
  • You add a layer Mask
  • You edit the Mask over time by setting keyframes on the Mask Path property

The issue

Anytime you try to move a single point on the Mask Path - the entire mask path moves - regardless of if you have the Pen Tool or Selection Tool selected

So yes - most posts ands forum responses I've seen talk about - "Make sure you have the Pen Tool" selected - so that way you're in path editing mode and then you should be able to move the individual points. I tried ad nausea and I couldn't get this to work.

Solution

  • It all had to do with what was selected in the timeline. I had the Mask selected (that is, the Mask property that shows up when you twirl down the layer itself) - which is wrong. This was the issue.
  • Once I selected the layer itself and NOT the mask, I could then select the Pen Tool and edit the points individually. Kind of strange - but yeah - select the Layer and not its mask if you want to edit the Mask points individually. And yes - use the Pen Tool.

(note this is in Adobe After Effects CS6 - not sure about other versions).

Hope this helps out some peeps.

Caseyli
Casey Li
CEO & Founder, BiteSite