Skip to content

Instantly share code, notes, and snippets.

@themoxman
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themoxman/8939152 to your computer and use it in GitHub Desktop.
Save themoxman/8939152 to your computer and use it in GitHub Desktop.

Annoying Random Spec Failure

No rhyme or reason as to failure. Just depends on the order of the specs.

~/Desktop/coding_resources/programs/md_notes
21:38:26 davemox@Daves-MacBook-Pro $ bundle exec rspec
...........F.*................................................................*...............................................

Pending:
  Find notes search for note with invalid tags
    # Temporarily disabled with xit
    # ./spec/features/search_spec.rb:60
  SearchHandler find_notes does not return Notes not in the current collection
    # Not yet implemented
    # ./spec/models/search_handler_spec.rb:58

Failures:

  1) Find notes revise last search
     Failure/Error: expect(current_path).to eq collection_revise_search_path(@collection)

       expected: "/collections/1/search/revise"
            got: "/collections/1/search/results"

       (compared using ==)
     # ./spec/features/search_spec.rb:94:in `block (2 levels) in <top (required)>'

Finished in 28.86 seconds
126 examples, 1 failure, 2 pending

Failed examples:

rspec ./spec/features/search_spec.rb:86 # Find notes revise last search

Randomized with seed 12186


-------------------------
~/Desktop/coding_resources/programs/md_notes
21:55:01 davemox@Daves-MacBook-Pro $ bundle exec rspec
.......................................*..................................................................................*...

Pending:
  Find notes search for note with invalid tags
    # Temporarily disabled with xit
    # ./spec/features/search_spec.rb:60
  SearchHandler find_notes does not return Notes not in the current collection
    # Not yet implemented
    # ./spec/models/search_handler_spec.rb:58

Finished in 28.6 seconds
126 examples, 0 failures, 2 pending

Randomized with seed 9250

Here is another failure with some database info.

~/Desktop/coding_resources/programs/md_notes
21:56:04 davemox@Daves-MacBook-Pro $ bundle exec rspec
....*..............................
An error occurred in an after hook
  ActionView::Template::Error: undefined method `fields' for nil:NilClass
  occurred at /Users/davemox/.rvm/gems/ruby-2.0.0-p353@md_notes/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:142:in `block in exec_query'

F.*........................................................................................

Pending:
  SearchHandler find_notes does not return Notes not in the current collection
    # Not yet implemented
    # ./spec/models/search_handler_spec.rb:58
  Find notes search for note with invalid tags
    # Temporarily disabled with xit
    # ./spec/features/search_spec.rb:60

Failures:

  1) Find notes revise last search
     Failure/Error: expect(current_path).to eq collection_revise_search_path(@collection)

       expected: "/collections/1/search/revise"
            got: "/collections/1/search/results"

       (compared using ==)
     # ./spec/features/search_spec.rb:94:in `block (2 levels) in <top (required)>'

Finished in 29.49 seconds
126 examples, 1 failure, 2 pending

Failed examples:

rspec ./spec/features/search_spec.rb:86 # Find notes revise last search

Randomized with seed 40963

instance method availability

It's interesting that active_class is available to be called here. I presume ApplicationHelper gets mixed in to ApplicationController and so is available to all the other controllers/views. HOWEVER, here in my spec, I call the method alone. I don't it as an instance method, ApplicationController.new.active_class(tag). Will have to dig into this more. Wanted to make a note here tho.

require 'spec_helper'

describe ApplicationHelper do
  describe "#active_class", unit: true do
    let(:tag) { create(:tag) }

    context "when a Tag's 'id' is included the @tag_ids string" do
      it "returns the text 'active'" do
        @tag_ids = "#{tag.id}, 4, 67, "
        expect(active_class(tag)).to eq 'active'
      end
    end

    context "when a Tag's 'id is not included in the @tag_ids string" do
      it "returns nil" do
        @tag_ids = "tag ids that don't match "
        expect(active_class(tag)).to be_nil
      end
    end
  end
end

Stubbing Controller Actions

I stubbed a before_action and also the SearchHandler.find_notes() method. This kinda messy?

The only other way this test passes is if I create real objects. Or, I could roll the expectation into a different test. You know, have a test with two expectations...

describe SearchController do

  ...

  describe "GET #revise" do
    it "assigns tag query string to @tag_ids" do
      tag_ids = "1, 3, 5, 8, "
      SearchController.any_instance.stub(:verify_tags)
      SearchHandler.stub(:find_notes)
      get :revise, collection_id: collection, tag_list: tag_ids
      expect(assigns(:tag_ids)).to eq tag_ids
    end
  end

Authenticity token displayed in URL on GET

http://localhost:3000/collections/2/search/results?utf8=%E2%9C%93&tag_list=&commit=Back+to+Search+Results&_method=delete&authenticity_token=QKxLDuRI3PUggo335CPu4IbTvFBwEaJuId9WnUa9v2k%3D

Hidden Elements, Capybara

I know Capybara isn't designed to interact w hidden elements, still, a bunch of people are able to get this to work, why can't I?

SO post Gist

  scenario "search for note with invalid tags", js: true, features: true do
    find(:xpath, "//input[@id='tag_list']").set "invalid tag "
    # find('#tag_list', visible: false).set "invalid tag "

    click_button 'Find Notes'
    expect(current_path).to eq collection_new_search_path(@collection)
    expect(page).to have_content "Rails"
    expect(page).to have_content "Ruby"
    expect(page).to have_content "Postgres"
    expect(page).to have_content "Uh oh. No record found. Try another search!!"
    expect(page).to have_content "Edit Note"
  end

Using xpath, I can't even find the element.

  1) Find notes search for note with invalid tags
     Failure/Error: find(:xpath, "//input[@id='tag_list']").set "invalid tag "
     Capybara::ElementNotFound:
       Unable to find xpath "//input[@id='tag_list']"
     # ./spec/features/search_spec.rb:61:in `block (2 levels) in <top (required)>'

Using css selectors, I can find, but not set the value.

  1) Find notes search for note with invalid tags
     Failure/Error: find('#tag_list', visible: false).set("invalid tag ")
     Selenium::WebDriver::Error::ElementNotVisibleError:
       Element is not currently visible and so may not be interacted with
     # [remote server] file:///var/folders/32/68ks6735053_dcgrpmcj023r0000gn/T/webdriver-profile20140218-4669-kzexdn/extensions/fxdriver@googlecode.com/components/command_processor.js:8179:in `fxdriver.preconditions.visible'
     # [remote server] file:///var/folders/32/68ks6735053_dcgrpmcj023r0000gn/T/webdriver-profile20140218-4669-kzexdn/extensions/fxdriver@googlecode.com/components/command_processor.js:10814:in `DelayedCommand.prototype.checkPreconditions_'
     # [remote server] file:///var/folders/32/68ks6735053_dcgrpmcj023r0000gn/T/webdriver-profile20140218-4669-kzexdn/extensions/fxdriver@googlecode.com/components/command_processor.js:10831:in `DelayedCommand.prototype.executeInternal_/h'
     # [remote server] file:///var/folders/32/68ks6735053_dcgrpmcj023r0000gn/T/webdriver-profile20140218-4669-kzexdn/extensions/fxdriver@googlecode.com/components/command_processor.js:10836:in `DelayedCommand.prototype.executeInternal_'
     # [remote server] file:///var/folders/32/68ks6735053_dcgrpmcj023r0000gn/T/webdriver-profile20140218-4669-kzexdn/extensions/fxdriver@googlecode.com/components/command_processor.js:10778:in `DelayedCommand.prototype.execute/<'
     # ./spec/features/search_spec.rb:62:in `block (2 levels) in <top (required)>'

Secure connections for working in public places??

If I'm working in a coffee shop or anywhere similar, should I be using some kind of network security setup?

PATH

I think my PATH variable is all screwed up. Should it be this long?

/Users/davemox/.rvm/gems/ruby-2.0.0-p353@md_notes/bin:/Users/davemox/.rvm/gems/ruby-2.0.0-p353@global/bin:/Users/davemox/.rvm/rubies/ruby-2.0.0-p353/bin:/Users/davemox/.rvm/bin:/usr/local/heroku/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/davemox/Desktop/coding_resources/programs/rmap/bin

I need a good intro level book on unix operating systems. And, I don't really understand the file structure of my OS. You know, questions like, what is bin/ and why does it exist?

####Testing dependent::destroy

I'm testing that when I destroy Notes or Tags, the related Taggings are also removed. Should this be a Controller test or a Model test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment