Rspec and the Double Dilemma

This week the question came up of doubles with Rspec testing. For those unfamiliar with this concept, a double is a way of creating fake resources that look and act like the resources you expect to be used inside of a class or method. With the newer versions of Rspec this is as simple as the following example:

describe MaintenanceSystem do
let(:bad_spring) { double(type: :general, size: :small, condition: :poor) }
let(:resource) { double(springs: [bad_spring]) }
let(:system) { described_class.new(loaded_resources) }
context 'with a single small spring loaded in resources' do
let(:good_spring) { double(type: :general, size: :small, condition: :good) }
let(:loaded_resources) { { springs: [good_spring] } }
it 'should be able to make the repair' do
expect(system.can_repair? resource).to be(true)
end
context 'but the resource has a large bad spring' do
let(:bad_spring) { double(type: :general, size: :large, condition: :poor) }
it 'should not be able to make the repair' do
expect(system.can_repair? resource).to be(false)
end
end
end
end

Remember to Disconnect

When the weight of the world really seems to squeeze in it becomes more important to disconnect from what “seems” important. Step back and take a few moments to enjoy what is around you! I was able to capture this photo with Cassandra while we walked around the Harlinsdale Farm. It helps me remember work isn’t supposed to be as involved and important as I make it sometimes…

Not a Fan of the Caret in Elixir

Coming from Erlang I’m used to variables being imutable, Elixir doesn’t provide this same level of comfort that I am used to. For instance, when learning Erlang we are taught that once a variable is bound it cannot be changed.

1> A = "Looking good so far!".
"Looking good so far!"
2> A.
"Looking good so far!"
3> A = "Even better?".
** exception error: no match of right hand side value "Even better?"

In Elixir the story is not quite the same…

iex(1)> a = "Looking good so far!"
"Looking good so far!"
iex(2)> a
"Looking good so far!"
iex(3)> a = "Even better?"
"Even better?"

How Versus Why

Solving the question of “How” is only a matter of time. The question of “Why” however; now that can take a lifetime…

Using Curl Against an API

Sometimes you need to make a quick call against an api but may not have the willpower or time to crack open a script to get things done… When those moments hit just fall back on curl!

Hackathon in Nashville

Having a great time at Hack Tennessee! Trying to fiddle with Elixir and build some awesome software.

"Chopping on it"

Undo Git Commits to Wrong Branch Locally

Ever thought you have started commiting work to a new branch and realized your still working off of the wrong branch? Up until today I would normally rewind my commit(s), then switch to the branch I should have had and re-commit my work. It turns out this whole time I could have been doing this…

git branch -m the-branch-i-should-have-been-on

This in no way harms the branch you where on as it will just pull down the remote again that you were on originally on! Meaning the following chain of commands will work out just fine…

# on master when I thought I was on feature-x
git commit -m "Feature X was added because we needed more magic"
# Ahhhh crap, I'm on master!
git branch -m feature-x
git push origin feature-x
git checkout master # it's master from before I commited Feature X!

Shout out to Nola for showing me this.

Truncated Text in the View

If you’ve been in web development for any amount of time, eventually you’ll run into the challenge of shortening the amount of text that is on your website. This will apply for certain areas on your pages and no matter what your software stack is, it seems like the first area to tackle truncating text is on the back-end. I would urge everyone to strongly reconsider not doing this server side because most of the time it is a client-side view’s concern and I’ll explain why…

CSS Z-Index Issue

Up until very recently my blog had a z-index issue where you couldn’t click on my top banner to go back to the root. The canvas was at a higher z-index than the hgroup which holds my text bits of the banner image. I tried all kinds of tricks to get it forward but nothing worked. A big thanks to Dave from work for helping me with this fix. It turns out this is the css I needed to make to get it going:

.header-info {
position: relative;
z-index: 2;
}

The position relative is the magic sauce in this incantation… not fully sure how; but this explains what I cannot: Z-Index Blog.