Ruby on rails 使用Ruby和assigns关键字进行集成测试

Ruby on rails 使用Ruby和assigns关键字进行集成测试,ruby-on-rails,Ruby On Rails,我正在尝试执行一些集成测试,以查看文章是否得到更新。以下是我的集成测试: test "update existing article" do # create an article @article = Article.new @article.title = "title" @article.abstract = "abstract" @article.description = "description" if @article.s

我正在尝试执行一些集成测试,以查看文章是否得到更新。以下是我的集成测试:

test "update existing article" do 

    # create an article 
    @article = Article.new 
    @article.title = "title"
    @article.abstract = "abstract"
    @article.description = "description" 

    if @article.save 

      post "/articles/edit", :id => @article.id

      assert assigns(:article)

    end

  end
以下是我关于控制器实现的文章:

def edit

    @article = Article.find(params[:id])

    respond_to do |format|
      format.html 
      format.xml { render :xml => @article }
    end

  end

测试中关于分配的最后一行失败。根据我的理解,赋值(:article)意味着将填充变量@article

看看这一行:

post "/articles/edit", :id => @article.id
问题是编辑操作采用的是
GET
,而不是
POST
,因此它可能永远不会被调用。尝试:

get edit_article_path, :id => @article.id

(请注意,如果正在运行控制器测试,最好使用符号作为操作名称。)

通过使用get:edit,我会出现以下错误:1)错误:test\u update\u existing\u article(ArticleFlowsTest):ArgumentError:错误参数(预期的URI对象或URI字符串)/test/integration/adding_article_flows_test.rb:30:在'test_update_existing_article'中,我正在运行集成测试!啊,对不起!请尝试使用上面的“我的更新”,并为
:edit
添加子Bing
edit\u article\u path
。谢谢!我去看看。嘿,我在哪里可以找到所有的助手路径方法,比如你列出的edit_article_path。只需在命令行中的项目目录中运行“rake routes”。祝你好运