How to resolve Rails model namespace collision

后端 未结 3 1037
别跟我提以往
别跟我提以往 2020-12-15 00:36

The story so far:

I have a rails app with a model named \"Term\". All is well until trying to install Cucumber. Upon running

rake cucumber

相关标签:
3条回答
  • 2020-12-15 00:48

    Two solutions:

    1) Change your app's Term model to be something else.

    2) Patch term-ansicolor to have a namespaced Term and use that gem instead.

    0 讨论(0)
  • 2020-12-15 01:00

    Here's what I did:

    sudo gem uninstall term-ansicolor
    sudo gem uninstall cucumber

    Download sources for term-ansicolor and cucumber from github
    Search term-ansicolor source for "module Term" and replace with "module ANSITerm"
    Search cucumber source for "include Term" and replace with "include ANSITerm"
    Search cucumber source for "::Term" and replace with "::ANSITerm"

    sudo gem install term-ansicolor from my local repository
    sudo gem install cucumber from my local repository

    Now I have two gems to maintain, but that seems easier than changing all the model references in my app.

    Comments/suggestions welcome.

    0 讨论(0)
  • 2020-12-15 01:05

    I did get a namespace collision with my application model Node and Capybara::Node in my specs. It was sufficient for me to explicitly state toplevel namespace in specs to fix the problem:

    it "should find the specified node scoped under the current user" do
      ::Node.should have_received(:find_by_id_for_user).with(node.id, user)
    end
    
    0 讨论(0)
提交回复
热议问题