dimanche 17 avril 2016

Dynamically add method in before(:all)

Im testing a Module that can be included in a Controller. Right now the code looks like that:

class GithubAuthorizationController < ApplicationController
  include Frontend::Concerns::GithubAuthorization

  def index
    render inline: "lorem_ipsum"
  end
end

describe GithubAuthorizationController do
  before(:all) do
    @page_content = "lorem_ipsum"
  end
  ...........

As you can see I basically create a Test-Controller before the tests are run. Now I would like to add the module and index method in the before(:all)-block. I tried:

class GithubAuthorizationController < ApplicationController
end

describe GithubAuthorizationController do
  before(:all) do
    @page_content = "lorem_ipsum"

    class < @controller
      include Frontend::Concerns::GithubAuthorization

      def index
        render inline: "lorem_ipsum"
      end
    end
  end
  ...........

As I can see in debugger in the before(:all) block the @controller is defined as <GithubAuthorizationController .... So It is a instance. There Is also no error when running the code, but the tests fails, because of The action 'index' could not be found ...

What do I wrong? How can I move the code to the before(:all) block? Thanks

Aucun commentaire:

Enregistrer un commentaire