Rubymine is not able to find a step definition, located inside a gem

怎甘沉沦 提交于 2019-12-23 22:30:23

问题


Rubymine returns an alert of "Undefined step reference" for the two steps of this scenario. This cucumber test is like this:

 @smoke
  Scenario: Update profile Smoke test.
    Given I navigate to this test webpage
      And In Test, I click the element of "test_link"

This 2 steps are located inside a gem, following this structure: gemname/lib/features/step_definitions/web_shared_steps.rb

And (/^I navigate to this (.*?)$/) do |web|
  web = '$' + web.downcase.gsub(' ', '_')
  @browser.goto eval(web)
end

Then (/In (.*?), I click the element of "(.*?)"$/) do |page, element|
  on_page(page + 'Page').click_element(element)
end

And the methods are also in the gem, following this structure: gemname/lib/basic_methods.rb

module BasicMethods

  include PageObject
  include PageObject::PageFactory


  def click_element (element)
    element = element.downcase.gsub(' ', '_')
    wait_until{send("#{element}?")}

    select = send("#{element}_element")
    wait_until{select.visible?}

    select.click
  end

So, If I execute with the command line "bundle exec cucumber", the test is able to find the step definitions in the gem, and the methods in the gem, and everything is executed correctly.

But, Rubymine is still giving an alert of "Undefined Step reference" for the two steps of the scenario, and I am unable to "command click" in those steps in order to navigate to the step definition.

QUESTION: Since the test in working, how is possible to "tell" Rubymine the folder/location where it has to search for the step definitions?


回答1:


I don't have Rubymine so I can't verify this answer but it sounds very similar to a problem I had with Syntastic under Vim.

Try creating a file called features/support/external.rb containing:

require "lib/features/step_definitions/web_shared_steps.rb"

Actually it doesn't have to be called external.rb, it can be called anything except env.rb.

I'm guessing that Rubymine is calling cucumber with the --dry-run option to generate its warnings. See this answer for details.




回答2:


try putting the gem source on your machine and then add this to your gemfile
gem 'gem', :path => 'path/to/gem-source'

I've had a similar problem with trying to use my own fork of a gem
When i did gem 'my-gem', :git => 'my-repo.git' i had the same problem as you, but by using :path I got rubyMine to recognise my step definitions.

I need to switch back to :git in production but at least i have a solution for my dev environment



来源:https://stackoverflow.com/questions/24686158/rubymine-is-not-able-to-find-a-step-definition-located-inside-a-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!