Testing / TDD

Don’t we have some people for that? I’m “the people”?? Dang it!
Testing is where the rubber meets the road. If your app works today, but not tomorrow, what’s the point? We all test in our own ways, but the industry has standards and expectations for this. And most employers have their own set of expectations around testing, which may pragmatically exceed standards. Testing can involve learning an entire body of new languages and methods. Testing should be learned early, and practiced often. Testing can be tricky, and the syntax is in flux, as this area is currently like the wild west of development. As you begin to figure out what is and is not currently working for you, you will want to document and remember it. This stack is dedicated to anything and everything around testing.

Set up a Ruby project with RSpec

11/12/17  Public, Ruby General, Testing / TDD

First make sure you have rspec and byebug installed:

➜  byebug -v
  Running byebug 9.1.0
➜  rspec -v
RSpec 3.6
  - rspec-core 3.6.0
  - rspec-expectations 3.6.0
  - rspec-mocks 3.6.0
  - rspec-rails 3.6.1
  - rspec-support ...

1 vote - harrylevine

Checking for rubocop offenses in a given file

11/07/17  Public, Testing / TDD

You can check what is/is not passing rubocop for a given file by calling:

rubocop app/whatever/whatever/my_file.rb

You can get even more output by passing it the -D flag, which adds the actual name of the cop.


1 vote - harrylevine

Disabling and re-enabling a rubocop rule for a specific set of code

11/07/17  Public, Testing / TDD

For example, if this rule is in your .rubocop.yml file:

  Description: Don't use self where it's not needed.
  StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-self-unless-required
  Enabled: true

1 vote - harrylevine

Shortened, one line version of a spec

04/25/17  Public, Testing / TDD

Here is the full syntax version of a spec:

it "returns no results" do
  expect(results).to be_nil

Here is the same spec, in the shortened, one line version:

it { expect(results).to be_nil }

1 vote - harrylevine

Controller spec when controller method is being hit through AJAX

07/29/16  Public, Testing / TDD

I had a controller method that is being called via AJAX. This method does not specifically render any pages (i.e. update.html.erb). The controller spec was throwing a missing template error

Failure/Error: put :update,

1 vote - harrylevine