3

Rails用のtabnavプラグインを使用していますが、rpsecを使用して正しくハイライト表示されることを確認したいと思います。

describe 'account navigation links' do
  it 'should have account settings link' do
   get '/account/settings'
   response.should have_tag("li", :text => "Account Settings")
end

 it 'should be highlighted' do
   get '/account/settings'
   response.should have_tag("li", :color => "Account Settings")
 end
end

ただし、上記のコードは機能していないようです。私はrspecbtwでwebratを使用しています。何か助けはありますか?ありがとう。

4

3 に答える 3

4

ここでテストする唯一の実際のことは、強調表示がクラス名からのものである場合、特定のクラス名が適用されているかどうかです。もしそうなら、あなたはすることができますhave_tag("li.highlighted", :text => "Account Settings")

それ以外の場合は、CSSセレクター自体が正しく適用されているかどうかのテストを自動化するべきではありません。これは純粋にプレゼンテーションの詳細であり、テストスイートがテストするように設計されているものではありません。Webratがわざわざスタイルシートを調べて適用することはないと思うので、その詳細をテストすることは不可能です。もちろん、1ページの読み込みで、機能しているかどうかを確認できます。結局のところ、あなたは間違いなく、スタイルシートを設計するときにテストします。

ともかく。あなたの質問は、あなたが実際に何をテストしようとしているのかを実際には明確にしませんが、とにかく、プレゼンテーションをテストするべきではありません。HTMLドキュメントの構造をテストすることは良いことですが、クライアントプログラムがドキュメントをどのように解釈するかを確認することは、プログラマーではなくデザイナーの役割です。(両方の帽子をかぶっている場合はそうですが、食べ物を混ぜないでください。)

于 2010-05-15T01:38:43.460 に答える
2
describe 'highlighting' do
  it 'should highlight account/settings' do
    get '/account/settings'
    response.should have_tag("a.active[href=?]", account_settings_path, /Account Settings/i)
  end

  it 'should highlight account/profile' do
    get '/account/profile'
    response.should have_tag("a.active[href=?]", account_profile_path, /Profile Information/i)
  end

  it 'should highlight account/picture' do
    get '/account/picture'
    response.should have_tag("a.active[href=?]", account_picture_path, /Profile Picture/i)
  end

  it 'should highlight account/notifications' do
    get '/account/notifications'
    response.should have_tag("a.active[href=?]", account_notifications_path, /Notifications/i)
  end

  it 'should not highlight Profile' do
    get '/account/profile'
    response.should_not have_tag("a.active[href=?]", account_settings_path, /Account Settings/i)
  end

  it 'should not highlight Notifications' do
    get '/account/profile'
    response.should_not have_tag("a.active[href=?]", account_notifications_path, /Notifications/i)
  end

  it 'should not highlight Picture' do
    get '/account/profile'
    response.should_not have_tag("a.active[href=?]", account_picture_path, /Profile Picture/i)
  end
end

特に「間違ったアクションを強調しない」シナリオでは、さらにテストを作成できますが、これで十分だと思います。

于 2010-05-15T02:33:21.037 に答える
1

Sassを使用している場合は、Sassパーサーを使用して解析できます。

root = Sass::SCSS::Parser.new('.error { color: red; }', 'example.scss').parse

それに飛び込むことでテストできる解析ツリーを返します。例えば:

prop = root.children.select {|child| child.rule.flatten.include?('.error')}.first
prop_strings = prop.children.map {|p| [p.name.flatten.first, p.value].join(':')}
prop_strings.should include?('color:red')
于 2012-06-26T20:35:06.283 に答える