Convert specs to RSpec 3 syntax with Transpec #619

Merged
merged 1 commit into from Apr 6, 2014

Conversation

Projects
None yet
2 participants
@danielspector
Contributor

danielspector commented Apr 6, 2014

Converted suite to RSpec 3 syntax with Transpec.

Additionally, I updated a test from endpoint_spec.rb on Line 108. Test checks whether response cookies are set. Appropriate test would be to check for nil rather than using a match keyword. Previous versions of RSpec would allow checking against nil using the =~ syntax. RSpec 3 does not allow nil to be checked with the match matcher. The test was updated to reflect this change.

Test Before Change:

it 'sets browser cookies and does not set response cookies' do
      subject.get('/username') do
        cookies[:username]
      end
      get('/username', {}, 'HTTP_COOKIE' => 'username=mrplum; sandbox=true')

      last_response.body.should == 'mrplum'
      last_response.headers['Set-Cookie'].should_not =~ /username=mrplum/
      last_response.headers['Set-Cookie'].should_not =~ /sandbox=true/
    end

Test After Change:

it 'sets browser cookies and does not set response cookies' do
      subject.get('/username') do
        cookies[:username]
      end
      get('/username', {}, 'HTTP_COOKIE' => 'username=mrplum; sandbox=true')

      expect(last_response.body).to eq('mrplum')
      expect(last_response.headers['Set-Cookie']).to be_nil
    end

This conversion is done by Transpec 1.10.4 with the following command:
transpec

  • 826 conversions
    from: obj.should
    to: expect(obj).to
  • 572 conversions
    from: == expected
    to: eq(expected)
  • 23 conversions
    from: obj.stub(:message)
    to: allow(obj).to receive(:message)
  • 17 conversions
    from: obj.should_receive(:message)
    to: expect(obj).to receive(:message)
  • 8 conversions
    from: obj.should_not
    to: expect(obj).not_to
  • 8 conversions
    from: =~ /pattern/
    to: match(/pattern/)
  • 6 conversions
    from: lambda { }.should
    to: expect { }.to
  • 3 conversions
    from: lambda { }.should_not
    to: expect { }.not_to
  • 2 conversions
    from: > expected
    to: be > expected
  • 2 conversions
    from: obj.should_not_receive(:message)
    to: expect(obj).not_to receive(:message)
  • 1 conversion
    from: >= expected
    to: be >= expected
Convert specs to RSpec 3 syntax with Transpec
Converted specs to 3 syntax using the Transpec gem. Additionally, updated test in endpoint_spec.rb on Line 108 to check for nil rather than attempting to match on nil.
@dblock

This comment has been minimized.

Show comment
Hide comment
@dblock

dblock Apr 6, 2014

Member

Nice, thanks.

Member

dblock commented Apr 6, 2014

Nice, thanks.

dblock added a commit that referenced this pull request Apr 6, 2014

Merge pull request #619 from danielspector/transpec-rspec-update
Convert specs to RSpec 3 syntax with Transpec

@dblock dblock merged commit 8969c05 into ruby-grape:master Apr 6, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment