From 0620646c6d7a4dfdfed7a5289b8cf0e07618b496 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Fri, 10 Jun 2016 16:01:30 +0930 Subject: [PATCH] Fix failing specs - Updated assert_select behaviour given this is now based on nokogiri - Adjust some specs not to look for a specific asset name, but a behaviour - Adjust some specs for HTML5 style attributes instead of xhtml style - Fix tests that did not render before --- .../plantings/planting_a_crop_spec.rb | 8 +++----- spec/models/crop_spec.rb | 4 ++-- spec/models/post_spec.rb | 8 ++++---- spec/views/crops/new.html.haml_spec.rb | 2 +- spec/views/forums/show.html.haml_spec.rb | 2 +- spec/views/gardens/show.html.haml_spec.rb | 2 +- spec/views/home/_crops.html.haml_spec.rb | 4 ++-- spec/views/layouts/_header_spec.rb | 18 ++++++++--------- spec/views/layouts/_meta_spec.rb | 6 +++--- .../notifications/show.html.haml_spec.rb | 2 +- spec/views/notifier/notify.html.haml_spec.rb | 8 ++++---- spec/views/orders/index.html.haml_spec.rb | 4 ++-- spec/views/orders/show.html.haml_spec.rb | 2 +- spec/views/photos/new.html.haml_spec.rb | 1 + spec/views/photos/show.html.haml_spec.rb | 4 ++-- spec/views/plantings/_form.html.haml_spec.rb | 2 +- spec/views/plantings/edit.html.haml_spec.rb | 4 ++-- spec/views/plantings/new.html.haml_spec.rb | 4 ++-- spec/views/plantings/show.html.haml_spec.rb | 2 +- spec/views/posts/_single.html.haml_spec.rb | 20 +++++++++---------- spec/views/posts/edit.html.haml_spec.rb | 2 +- spec/views/posts/new.html.haml_spec.rb | 2 +- spec/views/posts/show.html.haml_spec.rb | 2 +- spec/views/products/index.html.haml_spec.rb | 2 +- spec/views/seeds/show.html.haml_spec.rb | 2 +- spec/views/shop/index_spec.rb | 4 ++-- 26 files changed, 60 insertions(+), 61 deletions(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 5ecabef33..7c51af70f 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -231,7 +231,7 @@ feature "Planting a crop", :js do end describe "Planting sunniness" do - it "should show the image sunniness_sun.png" do + it "should show the a sunny image" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do @@ -244,11 +244,10 @@ feature "Planting a crop", :js do click_button "Save" end - expect(page).to have_css("img[src*='sunniness_sun.png']") - expect(page).to have_css("img[alt=sun]") + expect(page).to have_css("img[alt='sun']") end - it "should show the image 'not specified.png'" do + it "should show a sunniness not specified image" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do @@ -260,7 +259,6 @@ feature "Planting a crop", :js do click_button "Save" end - expect(page).to have_css("img[src*='sunniness_not specified.png']") expect(page).to have_css("img[alt='not specified']") end end diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 047ca0c6a..53df996de 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -547,11 +547,11 @@ describe Crop do end it "should delete the association between post and the crop(tomato)" do - expect(Post.find(post).crops).to eq [maize] + expect(Post.find(post.id).crops).to eq [maize] end it "should not delete the posts" do - expect(Post.find(post)).to_not eq nil + expect(Post.find(post.id)).to_not eq nil end end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 45a37c47b..8fa53fffe 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -158,13 +158,13 @@ describe Post do end it "should delete the association" do - expect(Crop.find(tomato).posts).to eq [] - expect(Crop.find(maize).posts).to eq [] + expect(Crop.find(tomato.id).posts).to eq [] + expect(Crop.find(maize.id).posts).to eq [] end it "should not delete the crops" do - expect(Crop.find(tomato)).to_not eq nil - expect(Crop.find(maize)).to_not eq nil + expect(Crop.find(tomato.id)).to_not eq nil + expect(Crop.find(maize.id)).to_not eq nil end end end diff --git a/spec/views/crops/new.html.haml_spec.rb b/spec/views/crops/new.html.haml_spec.rb index 3e217f7d2..8b5484235 100644 --- a/spec/views/crops/new.html.haml_spec.rb +++ b/spec/views/crops/new.html.haml_spec.rb @@ -30,7 +30,7 @@ describe "crops/new" do end it "shows a link to crop wrangling guidelines" do - assert_select "a[href^=http://wiki.growstuff.org]", "crop wrangling guide" + assert_select "a[href^='http://wiki.growstuff.org']", "crop wrangling guide" end end diff --git a/spec/views/forums/show.html.haml_spec.rb b/spec/views/forums/show.html.haml_spec.rb index a012c248e..77ed26382 100644 --- a/spec/views/forums/show.html.haml_spec.rb +++ b/spec/views/forums/show.html.haml_spec.rb @@ -35,7 +35,7 @@ describe "forums/show" do it 'links to new post with the forum id' do render - assert_select "a[href=#{new_post_path(forum_id: @forum.id)}]" + assert_select "a[href='#{new_post_path(forum_id: @forum.id)}']" end it 'has no posts' do diff --git a/spec/views/gardens/show.html.haml_spec.rb b/spec/views/gardens/show.html.haml_spec.rb index 3753e075e..dff7ebefa 100644 --- a/spec/views/gardens/show.html.haml_spec.rb +++ b/spec/views/gardens/show.html.haml_spec.rb @@ -66,7 +66,7 @@ describe "gardens/show" do end it "links to the right crop in the planting link" do - assert_select("a[href=#{new_planting_path}?garden_id=#{@garden.id}]") + assert_select("a[href='#{new_planting_path}?garden_id=#{@garden.id}']") end end diff --git a/spec/views/home/_crops.html.haml_spec.rb b/spec/views/home/_crops.html.haml_spec.rb index 08b0cba01..3009a7cc4 100644 --- a/spec/views/home/_crops.html.haml_spec.rb +++ b/spec/views/home/_crops.html.haml_spec.rb @@ -32,7 +32,7 @@ describe 'home/_crops.html.haml', type: "view" do it 'shows crops section' do assert_select 'h2', text: 'Some of our crops' - assert_select "a[href=#{crop_path(@crop)}]" + assert_select "a[href='#{crop_path(@crop)}']" end it 'shows plantings section' do @@ -45,6 +45,6 @@ describe 'home/_crops.html.haml', type: "view" do end it 'includes a link to all crops' do - assert_select "a[href=#{crops_path}]", text: /View all crops/ + assert_select "a[href='#{crops_path}']", text: /View all crops/ end end diff --git a/spec/views/layouts/_header_spec.rb b/spec/views/layouts/_header_spec.rb index cd531dc71..8742796c1 100644 --- a/spec/views/layouts/_header_spec.rb +++ b/spec/views/layouts/_header_spec.rb @@ -24,7 +24,7 @@ describe 'layouts/_header.html.haml', type: "view" do end it 'shows the brand logo in the navbar' do - assert_select("img[src='/assets/growstuff-brand.png']", href: root_path) + assert_select("a.navbar-brand img[src]", href: root_path) end it 'should have signup/signin links' do @@ -49,19 +49,19 @@ describe 'layouts/_header.html.haml', type: "view" do end it 'links to members' do - assert_select("a[href=#{members_path}]", 'Browse Members') + assert_select("a[href='#{members_path}']", 'Browse Members') end it 'links to posts' do - assert_select("a[href=#{posts_path}]", 'Posts') + assert_select("a[href='#{posts_path}']", 'Posts') end it 'links to forums' do - assert_select("a[href=#{forums_path}]", 'Forums') + assert_select("a[href='#{forums_path}']", 'Forums') end it 'has a crop search' do - assert_select("form[action=#{crops_search_path}]") + assert_select("form[action='#{crops_search_path}']") assert_select("input#term") end @@ -81,16 +81,16 @@ describe 'layouts/_header.html.haml', type: "view" do rendered.should have_content "#{@member.login_name}" end it "should show link to member's gardens" do - assert_select("a[href=#{gardens_by_owner_path(owner: @member.slug)}]", "Gardens") + assert_select("a[href='#{gardens_by_owner_path(owner: @member.slug)}']", "Gardens") end it "should show link to member's plantings" do - assert_select("a[href=#{plantings_by_owner_path(owner: @member.slug)}]", "Plantings") + assert_select("a[href='#{plantings_by_owner_path(owner: @member.slug)}']", "Plantings") end it "should show link to member's seeds" do - assert_select("a[href=#{seeds_by_owner_path(owner: @member.slug)}]", "Seeds") + assert_select("a[href='#{seeds_by_owner_path(owner: @member.slug)}']", "Seeds") end it "should show link to member's posts" do - assert_select("a[href=#{posts_by_author_path(author: @member.slug)}]", "Posts") + assert_select("a[href='#{posts_by_author_path(author: @member.slug)}']", "Posts") end end diff --git a/spec/views/layouts/_meta_spec.rb b/spec/views/layouts/_meta_spec.rb index 8b27d7a8b..716429e37 100644 --- a/spec/views/layouts/_meta_spec.rb +++ b/spec/views/layouts/_meta_spec.rb @@ -23,17 +23,17 @@ describe 'layouts/_meta.html.haml', type: "view" do it 'should have a Posts RSS feed' do posts_rss = url_for(controller: 'posts', format: 'rss', only_path: false) - assert_select "head>link[href=#{posts_rss}]" + assert_select "head>link[href='#{posts_rss}']" end it 'should have a Crops RSS feed' do crops_rss = url_for(controller: 'crops', format: 'rss', only_path: false) - assert_select "head>link[href=#{crops_rss}]" + assert_select "head>link[href='#{crops_rss}']" end it 'should have a Plantings RSS feed' do plantings_rss = url_for(controller: 'plantings', format: 'rss', only_path: false) - assert_select "head>link[href=#{plantings_rss}]" + assert_select "head>link[href='#{plantings_rss}']" end it 'should have a title' do diff --git a/spec/views/notifications/show.html.haml_spec.rb b/spec/views/notifications/show.html.haml_spec.rb index 42b732ad5..a0ca5ec8f 100644 --- a/spec/views/notifications/show.html.haml_spec.rb +++ b/spec/views/notifications/show.html.haml_spec.rb @@ -36,7 +36,7 @@ describe "notifications/show" do end it "includes a reply button" do - assert_select "a[href=#{@reply_link}]", "Reply" + assert_select "a", {href: @reply_link}, "Reply" end end diff --git a/spec/views/notifier/notify.html.haml_spec.rb b/spec/views/notifier/notify.html.haml_spec.rb index 1a4a607bc..5a6c96116 100644 --- a/spec/views/notifier/notify.html.haml_spec.rb +++ b/spec/views/notifier/notify.html.haml_spec.rb @@ -36,17 +36,17 @@ describe 'notifier/notify.html.haml', type: "view" do end it 'should include a reply link' do - assert_select "a[href=#{@reply_link}]", text: /Reply/ + assert_select "a[href='#{@reply_link}']", text: /Reply/ end it 'should contain a link to your inbox' do - assert_select "a[href*=notifications]" + assert_select "a[href*='notifications']" end it 'should have fully qualified URLs' do # lots of lovely fully qualified URLs - assert_select "a[href^=http]", { minimum: 4 } + assert_select "a[href^='http']", { minimum: 4 } # no relative URLs starting with / - assert_select "a[href^=/]", { count: 0 } + assert_select "a[href^='/']", { count: 0 } end end diff --git a/spec/views/orders/index.html.haml_spec.rb b/spec/views/orders/index.html.haml_spec.rb index 3efdce690..297ac9ad4 100644 --- a/spec/views/orders/index.html.haml_spec.rb +++ b/spec/views/orders/index.html.haml_spec.rb @@ -33,7 +33,7 @@ describe "orders/index" do it "renders a list of orders" do render # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "tr>td", text: @order1.id - assert_select "tr>td", text: @order2.id + assert_select "tr>td a/@href", text: "/orders/#{@order1.id}" + assert_select "tr>td a/@href", text: "/orders/#{@order2.id}" end end diff --git a/spec/views/orders/show.html.haml_spec.rb b/spec/views/orders/show.html.haml_spec.rb index c4a2de1cf..10fd2f5d7 100644 --- a/spec/views/orders/show.html.haml_spec.rb +++ b/spec/views/orders/show.html.haml_spec.rb @@ -50,7 +50,7 @@ describe "orders/show" do it "shows a foreign exchange link for the total" do currency = Growstuff::Application.config.currency - assert_select("a[href=http://www.wolframalpha.com/input/?i=198.00+#{currency}]") + assert_select("a[href='http://www.wolframalpha.com/input/?i=198.00+#{currency}']") end it "asks for a referral code" do diff --git a/spec/views/photos/new.html.haml_spec.rb b/spec/views/photos/new.html.haml_spec.rb index 46489e87e..47df538b4 100644 --- a/spec/views/photos/new.html.haml_spec.rb +++ b/spec/views/photos/new.html.haml_spec.rb @@ -32,6 +32,7 @@ describe "photos/new" do context "user has no photosets" do it "doesn't show a dropdown with sets from Flickr" do + render assert_select "select#set", false end end diff --git a/spec/views/photos/show.html.haml_spec.rb b/spec/views/photos/show.html.haml_spec.rb index a7e014eac..055032f76 100644 --- a/spec/views/photos/show.html.haml_spec.rb +++ b/spec/views/photos/show.html.haml_spec.rb @@ -29,7 +29,7 @@ describe "photos/show" do end it "shows the image" do - assert_select "img[src=#{@photo.fullsize_url}]" + assert_select "img[src='#{@photo.fullsize_url}']" end it "links to the owner's profile" do @@ -46,7 +46,7 @@ describe "photos/show" do end it "has a delete button" do - assert_select "a[href=#{photo_path(@photo)}]", 'Delete Photo' + assert_select "a[href='#{photo_path(@photo)}']", 'Delete Photo' end end diff --git a/spec/views/plantings/_form.html.haml_spec.rb b/spec/views/plantings/_form.html.haml_spec.rb index a8565dfda..0d813b678 100644 --- a/spec/views/plantings/_form.html.haml_spec.rb +++ b/spec/views/plantings/_form.html.haml_spec.rb @@ -34,7 +34,7 @@ describe "plantings/_form" do end it "has a free-form text field containing the planting date in ISO format" do - assert_select 'input#planting_planted_at[type=text][value=2013-03-01]' + assert_select "input#planting_planted_at[type='text'][value='2013-03-01']" end end diff --git a/spec/views/plantings/edit.html.haml_spec.rb b/spec/views/plantings/edit.html.haml_spec.rb index b71b34d2a..24b0b81ce 100644 --- a/spec/views/plantings/edit.html.haml_spec.rb +++ b/spec/views/plantings/edit.html.haml_spec.rb @@ -55,7 +55,7 @@ describe "plantings/edit" do end it 'includes helpful links for crops and gardens' do - assert_select "a[href=#{new_garden_path}]", text: "Add a garden." + assert_select "a[href='#{new_garden_path}']", text: "Add a garden." end it "chooses the right crop" do @@ -64,7 +64,7 @@ describe "plantings/edit" do it "chooses the right garden" do assert_select "select#planting_garden_id", - html: /option selected="selected" value="#{@garden.id}"/ + html: /option selected value="#{@garden.id}"/ end end diff --git a/spec/views/plantings/new.html.haml_spec.rb b/spec/views/plantings/new.html.haml_spec.rb index cd3a95445..825d64c5b 100644 --- a/spec/views/plantings/new.html.haml_spec.rb +++ b/spec/views/plantings/new.html.haml_spec.rb @@ -56,12 +56,12 @@ describe "plantings/new" do end it 'includes helpful links for crops and gardens' do - assert_select "a[href=#{new_garden_path}]", text: "Add a garden." + assert_select "a", href: new_garden_path, text: "Add a garden." end it "selects a garden given in a param" do assert_select "select#planting_garden_id", - html: /option selected="selected" value="#{@garden_z.id}"/ + html: /option selected value="#{@garden_z.id}"/ end end end diff --git a/spec/views/plantings/show.html.haml_spec.rb b/spec/views/plantings/show.html.haml_spec.rb index 79faf1d1d..f04604722 100644 --- a/spec/views/plantings/show.html.haml_spec.rb +++ b/spec/views/plantings/show.html.haml_spec.rb @@ -70,7 +70,7 @@ describe "plantings/show" do @photo = FactoryGirl.create(:photo, owner: @member) @p.photos << @photo render - assert_select "img[src=#{@photo.thumbnail_url}]" + assert_select "img[src='#{@photo.thumbnail_url}']" end it "shows a link to add photos" do diff --git a/spec/views/posts/_single.html.haml_spec.rb b/spec/views/posts/_single.html.haml_spec.rb index b3a9c0dd9..14551afc3 100644 --- a/spec/views/posts/_single.html.haml_spec.rb +++ b/spec/views/posts/_single.html.haml_spec.rb @@ -33,11 +33,11 @@ describe "posts/_single" do end it "contains a permanent link to post" do - assert_select "a[href=#{post_path @post}]", "Permalink" + assert_select "a[href='#{post_path @post}']", "Permalink" end it "doesn't contain a link to new comment" do - assert_select "a[href=#{new_comment_path(post_id: @post.id)}]", false + assert_select("a", {href: new_comment_path(post_id: @post.id)}, false) end end @@ -50,11 +50,11 @@ describe "posts/_single" do end it "contains link to new comment" do - assert_select "a[href=#{new_comment_path(post_id: @post.id)}]", "Reply" + assert_select("a", {href: new_comment_path(post_id: @post.id)}, "Reply") end it "does not contain an edit link" do - assert_select "a[href=#{edit_post_path(@post)}]", false + assert_select "a[href='#{edit_post_path(@post)}']", false end end @@ -68,7 +68,7 @@ describe "posts/_single" do end it "contains an edit link" do - assert_select "a[href=#{edit_post_path(@post)}]", "Edit" + assert_select "a[href='#{edit_post_path(@post)}']", "Edit" end end @@ -78,7 +78,7 @@ describe "posts/_single" do end it "renders the number of comments" do - assert_select "a[href=#{post_path(@post)}\#comments]", "0 comments" + assert_select "a[href='#{post_path(@post)}\#comments']", "0 comments" end end @@ -89,7 +89,7 @@ describe "posts/_single" do end it "renders the number of comments" do - assert_select "a[href=#{post_path(@post)}\#comments]", "1 comment" + assert_select "a[href='#{post_path(@post)}\#comments']", "1 comment" end end @@ -101,7 +101,7 @@ describe "posts/_single" do end it "renders the number of comments" do - assert_select "a[href=#{post_path(@post)}\#comments]", "2 comments" + assert_select "a[href='#{post_path(@post)}\#comments']", "2 comments" end end @@ -121,11 +121,11 @@ describe "posts/_single" do end it "does not contain link to post" do - assert_select "a[href=#{post_path @post}]", false + assert_select "a[href='#{post_path @post}']", false end it "does not contain link to new comment" do - assert_select "a[href=#{new_comment_path(post_id: @post.id)}]", false + assert_select "a[href='#{new_comment_path(post_id: @post.id)}']", false end end diff --git a/spec/views/posts/edit.html.haml_spec.rb b/spec/views/posts/edit.html.haml_spec.rb index e0a557db6..bf48f9d88 100644 --- a/spec/views/posts/edit.html.haml_spec.rb +++ b/spec/views/posts/edit.html.haml_spec.rb @@ -55,7 +55,7 @@ describe "posts/edit" do end it 'creates a hidden field' do - assert_select "input#post_forum_id[type=hidden][value=#{@forum.id}]" + assert_select "input#post_forum_id[type='hidden'][value='#{@forum.id}']" end it 'tells the user what forum it will be posted in' do diff --git a/spec/views/posts/new.html.haml_spec.rb b/spec/views/posts/new.html.haml_spec.rb index e9d26ba5e..6352ffabb 100644 --- a/spec/views/posts/new.html.haml_spec.rb +++ b/spec/views/posts/new.html.haml_spec.rb @@ -56,7 +56,7 @@ describe "posts/new" do end it 'creates a hidden field' do - assert_select "input#post_forum_id[type=hidden][value=#{@forum.id}]" + assert_select "input#post_forum_id[type='hidden'][value='#{@forum.id}']" end it 'tells the user what forum it will be posted in' do diff --git a/spec/views/posts/show.html.haml_spec.rb b/spec/views/posts/show.html.haml_spec.rb index e95d888b8..b50812078 100644 --- a/spec/views/posts/show.html.haml_spec.rb +++ b/spec/views/posts/show.html.haml_spec.rb @@ -118,7 +118,7 @@ describe "posts/show" do end it 'shows a comment button' do - assert_select "a[href=#{new_comment_path(post_id: @post.id)}]", "Comment" + assert_select "a", {href: new_comment_path(post_id: @post.id)}, "Comment" end end diff --git a/spec/views/products/index.html.haml_spec.rb b/spec/views/products/index.html.haml_spec.rb index 7fdaa0d20..576e6d3ec 100644 --- a/spec/views/products/index.html.haml_spec.rb +++ b/spec/views/products/index.html.haml_spec.rb @@ -27,6 +27,6 @@ describe "products/index" do # Run the generator again with the --webrat flag if you want to use webrat matchers assert_select "tr>td", text: @product.name, count: 2 assert_select "tr>td", text: @product.description, count: 2 - assert_select "tr>td", text: @product.min_price, count: 2 + assert_select "tr>td", text: @product.min_price.to_s, count: 2 end end diff --git a/spec/views/seeds/show.html.haml_spec.rb b/spec/views/seeds/show.html.haml_spec.rb index db2bae6ce..88f4f32d5 100644 --- a/spec/views/seeds/show.html.haml_spec.rb +++ b/spec/views/seeds/show.html.haml_spec.rb @@ -65,7 +65,7 @@ describe "seeds/show" do it "links to profile to set location" do render - assert_select "a[href=#{url_for(edit_member_registration_path)}]", text: "Set Location" + assert_select "a[href='#{url_for(edit_member_registration_path)}']", text: "Set Location" end end diff --git a/spec/views/shop/index_spec.rb b/spec/views/shop/index_spec.rb index df1f74920..c574f2ac4 100644 --- a/spec/views/shop/index_spec.rb +++ b/spec/views/shop/index_spec.rb @@ -41,7 +41,7 @@ describe 'shop/index.html.haml', type: "view" do it 'should contain an exchange rate link' do currency = Growstuff::Application.config.currency - assert_select("a[href=http://www.wolframalpha.com/input/?i=9.99+#{currency}]") + assert_select("a[href='http://www.wolframalpha.com/input/?i=9.99+#{currency}']") end it 'shows recommended price for products that have it' do @@ -50,7 +50,7 @@ describe 'shop/index.html.haml', type: "view" do it 'should contain an exchange rate link for recommended price' do currency = Growstuff::Application.config.currency - assert_select("a[href=http://www.wolframalpha.com/input/?i=12.00+#{currency}]") + assert_select("a[href='http://www.wolframalpha.com/input/?i=12.00+#{currency}']") end it 'displays the order form' do