-3

Below is my active admin resource file and the rspec feature.

When I run the rspec...it fails Failure/Error: select "Full-Year", from: "From Finance Month" Capybara::ElementNotFound: Unable to find option "Full-Year" Can anyone please help ???

****Resource file:(i have jst posted the form action of my resource file which is relavent to the problem faced by me)****

ActiveAdmin.register ------------(code)
 --------------------------------(code)
form do |f|
f.inputs do

  f.input :from_model_id, as: :select, collection: P*****::FinanceModel.all, label: 'From Finance Model', input_html: {
      onchange: remote_get('p**_***_revenue_variance_mapping_from_model_id', 'p**_***_revenue_variance_mapping_from_finance_month_id')}

  f.input :lrp_from_year, as: :select, collection: ["LRP 1st YEAR","LRP 2nd YEAR"], input_html: {disabled: true }, label: 'Lrp From Year'
  f.input :from_finance_month_id, as: :select, collection: P*****::FinanceMonth.for_revenue_variance_mapping(f.object.from_model_id), label: 'From Finance Month'

end

f.actions
end
end

Feature spec (This spec tests that when a new resource button is clicked and the form is filled with the corresponding values, the respective record should be displayed on the index page)

 require 'spec_helper'---(code)

 ------------------------(code)
def i_click_on_new_revenue_variance_mapping
click_on "New Revenue Variance Mapping"
select "2012", from: "From year"
select "Budget", from: "From Finance Model"
select "Full-Year", from: "From Finance Month"

click_on "Create Revenue variance mapping"
 end

 def i_should_see_the_new_revenue_variance_mapping_in_the_index
  -----(code)
  )

 end
 end

FinanceMonth Model:(the method 'for_revenue_variance_mapping' in this model is called in the form action of the resource file above )

module P######
 class FinanceMonth < ActiveRecord::Base
  include HasNamespacedName
  ------(code)
    def self.for_revenue_variance_mapping finance_model
  if !finance_model.nil?
  full_year_model_types = P****::FinanceModelType.where(P*****::FinanceModelType.arel_table[:finance_model_type_name].not_eq('CURRENT YEAR -    MONTHLY'))
  full_year_models = P*****::FinanceModel.order(:display_order).where(finance_model_type_id: full_year_model_types.map(&:finance_model_type_id))
  finance_model_ids = full_year_models.map(&:finance_model_id)
  if finance_model_ids.include? (finance_model.to_i)
models = [P*****::FinanceMonth.yearly_month]
  else if finance_model_ids.include? (finance_model)
         models = [P*****::FinanceMonth.yearly_month]
       else
         models = *****::FinanceMonth.twelve_months
       end
  end
Ananyaa
  • 1
  • 1
  • 1
    Please format the code so that it is readable. You may want to review the tips on asking a good question: http://stackoverflow.com/help/how-to-ask – zetetic Nov 10 '15 at 07:52

1 Answers1

2
Capybara::ElementNotFound: Unable to find option "Full-Year"

This means what it says: the element was not found. Specifically, Capybara expects to find an option with the value "Full-Year" in a select element called "From Finance Month". But why? Without seeing the test actually run in the browser, it's very difficult to know the cause.

You'll need to provide some more detail about the output produced by the test. Perhaps you could try the suggestions from Debugging Capybara to see what elements are present on the page.

zetetic
  • 47,184
  • 10
  • 111
  • 119
  • if you see the resource file -> form action (f.input :from_finance_month_id, as::select,collection:PamClient::FinanceMonth.for_revenue_variance_mapping(f.obj‌​ect.from_model_id), label: 'From Finance Month', the method 'fir_revenue_variance_mapping' is used on model 'FinanceMonth' There are also some ajax calls made in the form action for some of the select elements of the resource file above. I think i have to use stubs or mocks bt i dont know how to use it to get the values @zetetic – Ananyaa Nov 12 '15 at 10:57