【问题标题】:Rails 4 Rspec test session when assigned in spec在规范中分配时的 Rails 4 Rspec 测试会话
【发布时间】:2015-03-02 17:07:31
【问题描述】:

在我的测试中,我将会话分配给特定值,但是当我从我的应用控制器运行测试并打印时,会话为零。知道我该怎么做吗?

这是我的规格:

RSpec.describe "welcome/index.html.haml", type: :view do
  before(:each) do
    session[:followed_repos] = ["rails/rails"]
  end

  context "when visitor tracked repositories" do
    it "should see tracked repository list" do
      visit root_path
      expect(page).to have_no_content("You are tracking 0 repositories. Search for more here")
      expect(page).to render_template(:partial => "_tracked_repo")
    end
  end
end

这是我打印值的控制器:

  def index
    puts session[:followed_repos].inspect
  end

感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails-4 rspec capybara


    【解决方案1】:

    我发现 2 个答案可能有助于人们尝试使用 session in type: :view :

    1. 你可以使用那个宝石:rack_session_access
    2. 您别无选择,然后重现所有需要的步骤来获得您需要的会话

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多