Autocompletion binding?

I want autocompletion to work for an object that is instantiated in an included module.

Here are my steps.

  1. Create a new rspec test, require and include my module
  2. Call the modle method from the spec test that creates an attribute that will be used by the spec test.
  3. In the below example I call create_selenium_driver that creates the @browser varible
  4. In my test I want autocompetion to work and find all of the methods delevered for the selenium driver  when I type brower.  (ctrl +space)


I know that the problem is that in my rspec file it does not know the type for my instance variable "browser".  Can I add this in configuration to bind   Selenium::Client::Driver to the variable browser?  Or is there something that I can do to help rubymine with the autocompletion?




module MyModule
def create_selenium_driver(target)
    @browser = Selenium::Client::Driver.new(
            :host => ENV['HOST'] || "localhost",
            :port => 4444,
            :browser => ENV['SELENIUM_RC_BROWSER'] || "*firefox",
            :url => target,
            :timeout_in_second => 60)
  end
end

describe "Test something through a browser" do
include MyModule

  it "should open the browser and test the page" do
        create_selenium_driver("some url")
       browser.start_new_browser_session
  end
end

6 comments
Comment actions Permalink

Hi,
Please try: @browser.start_new_browser_session (because RM cannot find local variable or method browser in your context). Type will be inferred if RubyMine understands that Selenium::Client::Driver is defined in context of your rspec file (e.g you write "Selenium::Client::" in your rspec file and check that Driver class will be suggested in autocompletion). Also check View | Quick Documentation Popup, if type has been inferred RubyMine will show type name in the beginning of documentation.

0
Comment actions Permalink

@browser seems to work now.  Thanks for the feedback.

0
Comment actions Permalink

After spending more time with this, I found out that the soulution is partly working.

If I type the method out for my module, I can ctl + b to the method declaration.
So if I type @browser.text(), I can use ctl + to get to the declaration fo the text() method.

The part that is not working is, typing @browser. and ctrl space and getting a list of methods for that object.

I was able to type Selenium::Client and ctl + space to get the suggestion of Driver in  my rpec file.  So this part is working.

How can I get autocompletion to suggest the methods for my module?

0
Comment actions Permalink

The part that is not working is, typing @browser. and ctrl space and getting a list of methods for that object.

Please proved full example, e.g. where @browser is defined and where do you use it.

So if I type @browser.text(), I can use ctl + to get to the declaration fo the text() method.

Autocompletion and Resolve features in RubyMine have a bit different behaviour. We show items in autocompletion only when we are sure in them. Resolve works in both cases (when type was inferred or unknown). If RM doesn't know type of some method/variable (e.g. @browser) then in expression (@browser.te<caret>xt()) RM will try to find all text() methods in context of required files and will show multi resolve dialog.  

0
Comment actions Permalink

Here is the example
The Module File:
module MyModule
def create_selenium_driver(target)
    @browser = Selenium::Client::Driver.new(
            :host => ENV['HOST'] || "localhost",
            :port => 4444,
            :browser => ENV['SELENIUM_RC_BROWSER'] || "*firefox",
            :url => target,
            :timeout_in_second => 60)
  end
end


The test file:

describe "Test something through a browser" do
include MyModule

  it "should open the browser and test the page" do
        create_selenium_driver("some url")
       @browser.start_new_browser_session
  end
end

0
Comment actions Permalink

ssims wrote:

Here is the example
The Module File:
module MyModule
def create_selenium_driver(target)
    @browser = Selenium::Client::Driver.new(
            :host => ENV['HOST'] || "localhost",
            :port => 4444,
            :browser => ENV['SELENIUM_RC_BROWSER'] || "*firefox",
            :url => target,
            :timeout_in_second => 60)
  end
end


The test file:

describe "Test something through a browser" do
include MyModule

  it "should open the browser and test the page" do
        create_selenium_driver("some url")
       @browser.start_new_browser_session
  end
end

RM really doesn't support such situation @browser. Actually such analysis in general will affect type inference performance because RM should trace all calls from current context. Most likely it is possible to fetch instance variables from included modules but type inference for them will be rather complicated and slow.

I think you will get necessary code completion if you simplify your code:

module MyModule
def create_selenium_driver(target)
    @browser = Selenium::Client::Driver.new(
            :host => ENV['HOST'] || "localhost",
            :port => 4444,
            :browser => ENV['SELENIUM_RC_BROWSER'] || "*firefox",
            :url => target,
            :timeout_in_second => 60)
  end
end


The test file:

describe "Test something through a browser" do
include MyModule

  it "should open the browser and test the page" do
        browser = create_selenium_driver("some url")
        browser.start_new_browser_session
  end
end

0

Please sign in to leave a comment.