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

Consider handling its with hooks #75

Open
yujinakayama opened this issue Jun 26, 2014 · 1 comment
Open

Consider handling its with hooks #75

yujinakayama opened this issue Jun 26, 2014 · 1 comment
Labels

Comments

@yujinakayama
Copy link
Owner

Though currently I'm not sure if Transpec can determine this complex case.

@yujinakayama yujinakayama changed the title Consider handling invalid conversion of its Consider handling its with hooks Jun 26, 2014
@jeremywadsack
Copy link

I ran into a problem with how the its conversion works for this code:

context 'for a nil response' do
  before do
    subject.data = nil
  end

  describe '#data' do
    subject { super().data }
    it { should be_nil }
  end
end

Running rspec returned:

   Failure/Error: subject.data = blank_response
     NoMethodError:
       undefined method `data=' for false:FalseClass

Because the before is being applied after the subject is redefined.

My solution was just to change the spec to use this syntax, which actually I think is easier to read.

context 'for a nil response' do
  before do
    subject.data = nil
  end

  it { expect(subject.data).to be_nil }
end

We use this pattern pretty often such that of the 250 or so errors on a 10k-spec suite, every one of them was an instance of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants