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

Got syntax error converting Factory.stub(:user) #33

Closed
justin808 opened this issue Dec 6, 2013 · 3 comments
Closed

Got syntax error converting Factory.stub(:user) #33

justin808 opened this issue Dec 6, 2013 · 3 comments

Comments

@justin808
Copy link

/Users/justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require': /Users/justin/j/blink/bpos/spec/support/capybara.rb:60: syntax error, unexpected tIDENTIFIER, expecting keyword_end
  current_user = user || allow(Factory).to receive(:user)
                                                  ^ (SyntaxError)

Here is the converted code giving the error:

def as_visitor(user=nil, &block)
  current_user = user || allow(Factory).to receive(:user)
  if request.present?
    sign_out(current_user)
  else
    logout(:user)
  end
  block.call if block.present?
  return self
end

Here is the original code

def as_visitor(user=nil, &block)
  current_user = user || Factory.stub(:user)
  if request.present?
    sign_out(current_user)
  else
    logout(:user)
  end
  block.call if block.present?
  return self
end
@yujinakayama
Copy link
Owner

  • Is the Factory.stub FactoryGirls' one?
  • Did you run Transpec with -s/--skip-dynamic-analysis?

If so, it's expected result. If you run Transpec without -s/--skip-dynamic-analysis, it can discern whether a stub is RSpec's one or not.

@justin808
Copy link
Author

  1. Yes, FactoryGirl old syntax. I fixed that: http://robots.thoughtbot.com/factory-girl-hits-3-0
  2. No, didn't use the -s option.

@yujinakayama
Copy link
Owner

Now I know the problem. Transpec checks if a stub is RSpec's one or not only when the stub is run. However, with your code, I guess the argument user was always passed and the Factory.stub(:user) had never been run.

So, I think I'll let Transpec have a static whitelist.

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

No branches or pull requests

2 participants