Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert specs to RSpec 3 syntax with Transpec #619

Merged
merged 1 commit into from
Apr 6, 2014

Conversation

danielspector
Copy link
Contributor

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

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
Copy link
Member

dblock commented Apr 6, 2014

Nice, thanks.

dblock added a commit that referenced this pull request Apr 6, 2014
Convert specs to RSpec 3 syntax with Transpec
@dblock dblock merged commit 8969c05 into ruby-grape:master Apr 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants