RSpec - Collection Matchers

03/05/15  Public, Testing / TDD

describe 'collection matchers' do

  it 'will match arrays' do
    array = [1,2,3]

    expect(array).to include(3)
    expect(array).to include(1,3)

    expect(array).to start_with(1)
    expect(array).to end_with(3)
   ...

1 vote - harrylevine

RSpec - Numeric Comparison Matchers

03/05/15  Public, Testing / TDD

describe 'numeric comparison matchers' do

  it 'will match less than/greater than' do
    expect(10).to be > 9
    expect(10).to be >= 10
    expect(10).to be <= 10
    expect(9).to be < 10
  end

  it 'will match numeric ranges...

1 vote - harrylevine

RSpec - Truthiness Matchers

03/05/15  Public, Testing / TDD

describe 'truthiness matchers' do

  it 'will match true/false' do
    expect(1 < 2).to be(true)       # do not use 'be_true'
    expect(1 > 2).to be(false)      # do not use 'be_false'

    expect('foo').not_to be(true)   # the str...

1 vote - harrylevine

RSpec - Equivalence Matchers

03/05/15  Public, Testing / TDD

describe 'equivalence matchers' do

  it 'will match loose equality with #eq' do
    a = "2 cats"
    b = "2 cats"
    expect(a).to eq(b)
    expect(a).to be == b      # synonym for #eq

    c = 17
    d = 17.0
    expect(c).to ...

1 vote - harrylevine

Using the .class method to determine if an object is what you are looking for

05/28/15  Public, Tricks, Ruby General

Let's say that you want to use a given object if the object is an array; however, if the object is not an array (meaning it is a string, or a fixnum, etc.), then you do not want to use it.

You can use the .class method with conditional l...

1 vote - harrylevine

Great tutorial on Regular Expressions

12/10/14  Public, Ruby General

RubyLearning.com tutorial on Regular Expressions

1 vote - harrylevine

Gem to help with Rails Errors

05/10/15  Public, Rails Errors, Gems

When dealing with a particularly complex bug, logging and raising errors can become tedious or imprecise. The better_errors gem is there to help. The gem transforms your in-browser error page, add...

0 votes - harrylevine

Viewing the available methods for a given object

12/10/14  Public, Ruby General

As soon as an object comes into existence, it already responds to a number of messages. Every object is "born" with certain innate abilities. For example, if you have a class called Dog, and you create a new object like this, from the command ...

1 vote - harrylevine

How to remove any non-alpha characters (a to z) from a string using gsub and RegEx

12/05/14  Public, Tricks, Ruby General

For example, let's say that you have a method that determines if a particular word (string) is a palindrome or not. As a fringe case, what if the string happens to contain characters like . or...

1 vote - harrylevine

Command to create a new controller in Rails

12/01/14  Public, Command Line, Rails General

Here's the command to create a new controller in rails, from the command line.

$ rails g controller welcome index about

This example will be for a controller called welcome. In addition to the controller file, it will create two defau...

1 vote - harrylevine