zoukankan      html  css  js  c++  java
  • rspec的should方法

    rspec的should方法 - qingling2020 - qingling2020的博客
     
     
          第一行result应该等于5;
     
     
          第二行result应该包含5;
     
     
          第三行result应该响应hello;
     
     
          第四行lambda匿名函数应该抛出错误信息“Nothing find!”;
     
     
          第五行result应该匹配正则表达式;
     
     
          第六行期望代码块能把bug状态从“open”改为“fixed”;
     
     
          第七行result应该为空;
     
     
          Should() 方法表示肯定,还有should_not()方法表示否定,该方法的工作机制是先执行should或者should_not后边的代码,返回一个 match对象,进而把此match对象作为参数传给should()或者should_not()方法,和拥有对象句柄的本地match对象作对比校 验,若匹配不成功,返回相应信息
     
    测试controller
     
    classHomeController<ApplicationController  def login
        @person=Person.where(name: params[:person][:name])if@person.blank?
          redirect_to root_path          
        else
          redirect_to people_path
        end  endend
     
    describe HomeControllerdo
      render_views
      it "Logs in Person with non-blank name"do
        person =Factory(:Person, name:"non-blank name")
        get :login
        response.should redirect_to(people_path)end
      it "does not log in Person with blank name"do
        person =Factory(:Person, name:"")# blank name
        get :login
        response.should redirect_to(root_path)endend
     

    处理文字编码与相应的引用

     
    describe "admin/roles/index"do
    before(:each) do
    @ability = Object.new
     @ability.extend(CanCan::Ability)
     controller.stub(:current_ability) { @ability }
      view.stub(:current_ability) { @ability }
    assign(:roles, Role.paginate(:page => params[:page],:per_page => 10).order("updated_at DESC"))
    end
     
    it "has a create link for that role inside admin" do @ability.can :create, Role render if Role.count > 0 rendered.should have_selector("div") do |new_a| new_a.should have_selector "a", :href => new_admin_role_path, :content => "添加" end end end
     
    it "has a destroy link for that role inside admin" do
      @ability.can :destroy, Role
      render
      if Role.count > 0
        rendered.should have_selector("tr td") do |destroy_a|
          destroy_a.should have_selector "a",
          :href => admin_role_path(Role.first),
          :"data-method" => "delete",
          :"data-confirm" => "删除之后,该角色下的用户将无该角色下的权限。确定删除吗?",
          :rel => "nofollow",
          :content => "删除"
        end
      end
    end
     
    it "has a update link for that role inside admin" do @ability.can :update, Role render if Role.count > 0 rendered.should have_selector("tr td") do |update_a| update_a.should have_selector "a", :href => "/admin/roles/"+Role.first.id+"/edit", :content => "修改" end end end
     
    it "renders a list of admin/roles" do role = Role.first @ability.can :destroy, Role @ability.can :update, Role render # Run the generator again with the --webrat flag if you want to use webrat matchers allow_message_expectations_on_nil assigns[:roles].stub!(:total_pages).and_return(1) assert_select "tr>td", :text => role.name.to_s, :count => 1 assert_select "tr td", :text => role.description.to_s, :count => 1 mycount = Role.count assert_select "a", :html => "修改",:count => mycount < 10?mycount:10 assert_select "a", :html => "删除", :count => mycount < 10?mycount:10 end end
  • 相关阅读:
    不用找了,比较全的signalR例子已经为你准备好了(2)---JqGrid 服务端刷新方式-注释详细-DEMO源码下载
    不用找了,比较全的signalR例子已经为你准备好了.
    26之前,26之后
    SSIS从理论到实战,再到应用(7)----常用的数据类型转换操作
    SSIS从理论到实战,再到应用(6)----SSIS的自带日志功能
    SSIS从理论到实战,再到应用(5)----流程控制之Foreach循环
    SSIS从理论到实战,再到应用(4)----流程控制之For循环
    SSIS从理论到实战,再到应用(3)----SSIS包的变量,约束,常用容器
    SSIS从理论到实战,再到应用(2)----SSIS包的控制流
    Android学习笔记(十二)BroadcastReceiver的有序广播和优先级
  • 原文地址:https://www.cnblogs.com/qinyan20/p/3643234.html
Copyright © 2011-2022 走看看