How to use runnable method of Reportable Package

Best Minitest_ruby code snippet using Reportable.runnable

detail.rb

Source:detail.rb Github

copy

Full Screen

1class Reports::Detail < Reports::Excel2 def initialize(opts = {})3 super(opts)4 @runnables = opts[:runnables] || ExternalActivity.published5 @report_learners = opts[:report_learners] || report_learners_for_runnables(@runnables)6 @url_helpers = opts[:url_helpers]7 @hide_names = opts[:hide_names] || false8 # stud.id, class, school, user.id, username, student name, teachers, completed, %completed, last_run9 @common_columns = common_header(@hide_names) + [10 Reports::ColumnDefinition.new(:title => "# Completed", :width => 10, :left_border => :thin),11 Reports::ColumnDefinition.new(:title => "% Completed", :width => 10),12 Reports::ColumnDefinition.new(:title => "# Correct", :width => 10),13 Reports::ColumnDefinition.new(:title => "Last run", :width => 20),14 Reports::ColumnDefinition.new(:title => "Remote Endpoint", :width => 100)15 ]16 @reportable_embeddables = {} # keys will be runnables, and value will be an array of reportables for that runnable, in the correct order17 end18 def sorted_learners()19 @report_learners.sort_by {|l| [l.school_name, l.class_name, l.student_name, l.runnable_name]}20 end21 def setup_sheet_for_runnable(runnable, idx)22 # Spreadsheet was dying on ":" and "/" chars. Others?23 sheet_name = runnable.name.gsub /[^a-zA-z0-9 ]/,"_"24 # Add index number, as Spreadsheet is failing when two sheets have the same name.25 sheet_name = "#{idx + 1}. #{sheet_name[0..30]}"26 sheet_name "#{idx + 1}. Unknown" unless sheet_name && sheet_name.size > 027 @runnable_sheet[runnable] = @book.create_worksheet :name => sheet_name28 sheet_defs = @common_columns.clone29 answer_defs = []30 header_defs = [] # top level header31 expected_answers = []32 # save the original assignable so we can refer to it later33 assignable = runnable34 if runnable.is_a?(::ExternalActivity)35 if runnable.template36 runnable = runnable.template37 else38 # we can't report on external activities that don't have templates39 return40 end41 end42 # This needs to account for varying types of runnables...43 containers = get_containers(runnable)44 # offset the reportables counter by 245 reportable_header_counter = sheet_defs.size46 header_defs << Reports::ColumnDefinition.new(:title => sheet_name, :heading_row => 0, :col_index => reportable_header_counter)47 containers.each do |a|48 header_defs << Reports::ColumnDefinition.new(:title => a.name, :width=> 30, :heading_row => 0, :col_index => reportable_header_counter)49 reportable_header_counter += 2 # (two columns per container header)50 end51 reportable_header_counter -= 152 # Iterate containers53 containers.each do |a|54 sheet_defs << Reports::ColumnDefinition.new(:title => "#{a.name}\nAssessments Completed", :width => 4, :left_border => :thin)55 sheet_defs << Reports::ColumnDefinition.new(:title => "% Completed", :width => 4)56 reportable_header_counter = setup_sheet_runnables(a, reportable_header_counter, header_defs, answer_defs, expected_answers)57 end #containers58 col_defs = sheet_defs + answer_defs + header_defs59 write_sheet_headers(@runnable_sheet[assignable], col_defs)60 # Add row with expected answers.61 expected_answers.map! { |a| a.nil? ? "" : a }62 row = @runnable_sheet[assignable].row(@runnable_sheet[assignable].last_row_index + 1)63 row.concat(expected_answers)64 end65 def setup_sheet_runnables(container, reportable_header_counter, header_defs, answer_defs, expected_answers)66 reportables = container.reportable_elements.map {|re| re[:embeddable]}67 first = true68 question_counter = 069 # Iterate Reportables70 reportables.each do |r|71 question_counter += 172 reportable_header_counter += 173 header_defs << Reports::ColumnDefinition.new(:title => container.name, :heading_row => 0, :col_index => reportable_header_counter)74 title = clean_text((r.respond_to?(:prompt) ? r.prompt : r.name))75 title = "#{question_counter}: #{title}"76 answer_defs << Reports::ColumnDefinition.new(:title => title, :width => 25, :left_border => (first ? :thin : :none))77 expected_answers[reportable_header_counter] = get_expected_answer(r)78 if r.is_a?(Embeddable::ImageQuestion)79 reportable_header_counter += 180 answer_defs << Reports::ColumnDefinition.new(:title => 'note', :width => 25, :left_border => :none)81 end82 if r.is_required?83 reportable_header_counter += 184 answer_defs << Reports::ColumnDefinition.new(:title => 'submitted', :width => 10, :left_border => :none)85 end86 first = false87 end # reportables88 return reportable_header_counter89 end90 def run_report91 @book = Reports::Book.new(verbose: @verbose)92 @runnable_sheet = {}93 @runnables = @runnables.to_a94 @runnables.sort!{|a,b| a.name <=> b.name}95 print "Creating #{@runnables.size} worksheets for report" if @verbose96 @runnables.each_with_index do |runnable, idx|97 setup_sheet_for_runnable(runnable, idx)98 end # runnables99 puts " done." if @verbose100 student_learners = sorted_learners.group_by {|l| [l.student_id,l.class_id] }101 print "Filling in student data" if @verbose102 iterate_with_status(student_learners.keys) do |student_class|103 student_id = student_class[0]104 student_learners[student_class].each do |l|105 next unless (runnable = @runnables.detect{|r| l.runnable_type == r.class.to_s && r.id == l.runnable_id})106 # sheets are indexed from the actual runnable107 sheet = @runnable_sheet[runnable]108 if runnable.is_a?(::ExternalActivity)109 if runnable.template110 runnable = runnable.template111 else112 # we can't report on external activities that don't have templates113 next114 end115 end116 correctable = runnable.reportable_elements.select {|r| r[:embeddable].respond_to? :correctable? }117 # <=================================================>118 total_assessments = l.num_answerables119 assess_completed = l.num_submitted120 # <=================================================>121 total_by_container = get_containers(runnable).inject(0) { |a,b| a + b.reportable_elements.size}122 assess_percent = percent(assess_completed, total_assessments)123 last_run = l.last_run || 'never'124 row = sheet.row(sheet.last_row_index + 1)125 assess_completed = "#{assess_completed}/#{total_assessments}(#{total_by_container})"126 assess_correct = "#{l.num_correct}/#{correctable.size}"127 remote_endpoint = @url_helpers.remote_endpoint_url(l.learner)128 row[0, 3] = report_learner_info_cells([l], @hide_names) + [assess_completed, assess_percent, assess_correct, last_run, remote_endpoint]129 all_answers = []130 get_containers(runnable).each do |container|131 # <=================================================>132 reportables = container.reportable_elements.map { |re| re[:embeddable] }133 answers = reportables.map { |r| l.answers["#{r.class.to_s}|#{r.id}"] || default_answer_for(r) }134 #Bellow is bad, it gets the answers in the wrong order!135 #answers = @report_utils[l.offering].saveables(:learner => l, :embeddables => reportables )136 # s[:submitted] may be nil, as this hash key was added much later. Previously there was no notion137 # of submitted question, they were only answered or not. In theory we could add DB migration that138 # would update this hash (see answers attribute in Report::Learner), but that would be non-trivial139 # and migration itself would be very time consuming (I've done some experiments in console).140 submitted_answers = answers.select { |s| s[:submitted].nil? ? s[:answered] : s[:submitted] }141 correct_answers = answers.select { |s| s[:is_correct] }142 # <=================================================>143 # TODO: weed out answers with no length, or which are empty144 row.concat [submitted_answers.size, percent(submitted_answers.size, reportables.size)]...

Full Screen

Full Screen

offering_student_status.rb

Source:offering_student_status.rb Github

copy

Full Screen

...3 attr_accessor :student4 attr_accessor :offering5 # loosely based on offering_status.rb#student_activities6 def sub_sections7 runnable = offering.runnable8 if runnable.is_a?(::ExternalActivity) && runnable.template9 runnable = runnable.template10 end11 if runnable.is_a? ::Investigation12 runnable.activities.student_only13 else14 [runnable]15 end16 end17 def display_report_link?18 (offering && offering.student_report_enabled? && offering_reportable?)19 end20 def offering_reportable?21 (offering && offering.individual_student_reportable?)22 end23 # this is redundant with the Report::Learner object, but that object doesn't handle24 # students that don't have learners for the offering25 def complete_percent26 if learner27 # check if this is a reportable thing, if not then base the percent on the existance of the learner28 if offering_reportable?29 learner.report_learner.complete_percent || 030 else31 # Offering is not reportable, but it has been started. Return 100%.32 10033 end34 else35 036 end37 end38 def number_correct39 if learner && offering_reportable?40 num_correct = learner.report_learner.num_correct || 041 else42 nil43 end44 end45 # the runnable is passed because in somecases we want the progress for a sub part of the46 # this learners runnable47 def activity_complete_percent(activity)48 if learner49 # this is not efficient it has to do queries for each activity50 learner_activity = learner.learner_activities.find{|la| la.activity_id == activity.id}51 # Since there is a learner for this it actually has been started so perhaps52 # we shouldn't return 0 here53 learner_activity ? learner_activity.complete_percent : 054 else55 056 end57 end58 def last_run59 if learner60 return learner.report_learner.last_run...

Full Screen

Full Screen

detail_spec.rb

Source:detail_spec.rb Github

copy

Full Screen

...10 expect(result).not_to be_nil11 end12 end13 # TODO: auto-generated14 describe '#setup_sheet_for_runnable' do15 xit 'setup_sheet_for_runnable' do16 opts = {}17 detail = described_class.new(opts)18 runnable = double('runnable')19 result = detail.setup_sheet_for_runnable(runnable)20 expect(result).not_to be_nil21 end22 end23 # TODO: auto-generated24 describe '#setup_sheet_runnables' do25 xit 'setup_sheet_runnables' do26 opts = {}27 detail = described_class.new(opts)28 container = double('container')29 reportable_header_counter = double('reportable_header_counter')30 header_defs = double('header_defs')31 answer_defs = double('answer_defs')32 expected_answers = double('expected_answers')33 result = detail.setup_sheet_runnables(container, reportable_header_counter, header_defs, answer_defs, expected_answers)34 expect(result).not_to be_nil35 end36 end37 # TODO: auto-generated38 describe '#run_report' do39 it 'run_report' do40 opts = {}41 detail = described_class.new(opts)42 result = detail.run_report43 expect(result).not_to be_nil44 end45 end46 # TODO: auto-generated47 describe '#default_answer_for' do...

Full Screen

Full Screen

runnable

Using AI Code Generation

copy

Full Screen

1reportable.runnable("1.rb")2 def runnable(file_name)3 File.open(file_name, "r") do |f|4reportable.runnable("2.rb")5reportable.runnable("3.rb")6reportable.runnable("4.rb")7reportable.runnable("5.rb")8reportable.runnable("6.rb")9reportable.runnable("7.rb")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Minitest_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful