Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@keating
Last activeDecember 11, 2015 09:28
    • Star(0)You must be signed in to star a gist
    • Fork(0)You must be signed in to fork a gist
    Save keating/4579677 to your computer and use it in GitHub Desktop.
    #1
    # 测试登录,omniauth-identity
    it"will show save search button in home"do
    OmniAuth.config.test_mode=false
    user ||=FactoryGirl.create(:identity_first)
    visitlogin_path
    within("form")do
    fill_in'auth_key',with:user.email
    fill_in'password',with:user.password
    click_button"LogIn"
    end
    page.current_path.shouldeqroot_path
    page.shouldhave_button"Save Search"
    end
    #2
    #常写的controller测试
    describePagesControllerdo
    context"Anonymous user"do
    [:about,:advertise,:contact,:disclaimer,
    :help,:home,:service,
    ].eachdo |action|
    describe"GET#{action}"do
    before(:each){getaction}
    it"renders the#{action} page"do
    response.shouldbe_success
    response.shouldrender_templateaction
    end
    end
    end
    end
    end
    #3
    #下面用来测试页面中是否存在字母,在非英文环境下偶尔会需要
    context"anonymous non-English users, untranslated text in"do
    before(:all){stub_translate}
    after(:all){unstub_translate}
    [:about,:help].eachdo |action|
    describe"GET#{action}'s"do
    before(:each)do
    getaction
    exceptions=[]
    s=strip_from_responseexceptions
    @doc=expect_no_letters_docs
    end
    it"title"do
    expect_no_letters@doc.title
    end
    it"body"do
    expect_no_letters@doc
    end
    end
    end
    end
    #需要 include下面的 module
    moduleExpectNoLetters
    defexpect_no_letters(v)
    (v.kind_of?Nokogiri::HTML::Document) ?
    (expect_no_letters_in_docv) :
    (expect_no_letters_in_string_array[*v])
    nil
    end
    defexpect_no_letters_doc(s)Nokogiri::HTMLsend
    # Exceptions is an array of fixed strings and regexes
    defstrip_from_response(exceptions)
    s=response.body
    [*exceptions].each{|e|s=s.gsube,''}
    s
    end
    defstub_translate() $translate_stubbed=true;nilend
    defunstub_translate() $translate_stubbed=false;nilend
    defexpect_no_letters_in_doc(doc)
    exceptions=%w[prescriptstyle]
    nodes=doc.css'body, body *'
    nodes.each{|e|e.content=''ifexceptions.include?e.name}
    expect_no_letters_in_string_arraynodes.map &:content
    nil
    end
    defexpect_no_letters_in_string_array(a)
    big=a.map{|e|e.gsub/\s/,''}.join' '
    letters_regex=/[a-zA-Z]/
    show_length=30
    m=big =~letters_regex
    s=m.nil? ?'' :"Untranslated text starts: `#{big.slicem,show_length}'"
    m.nil?.shouldbe(true),s
    nil
    end
    end
    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp