Rspec& Rails创建测试Rspec的动作

时间:2015-08-27 12:07:57

标签: ruby-on-rails ruby testing rspec controller

嘿伙计们我试图在控制器规范中测试这个创建方法:

def create
    @user = User.new(user_params)
    if @user.save
      UserMailer.account_activation(@user).deliver_now
      flash[:info] = "Please check your email to activate your account."
      redirect_to root_url
    else
      render 'new'
    end
  end

我尝试了这个,但用户模型似乎没有增加,此外我还想测试邮件帐户激活:

  it "creates a new user" do
    expect{
      post :create, user: FactoryGirl.attributes_for(:user)
    }.to change(User,:count).by(1)
  end

0 个答案:

没有答案