#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2017
    Posts
    1
    Rep Power
    0

    Pls help to provide the missing codes


    I am new to ruby programming and I'm really having a hard time providing the missing codes to make the tests pass.
    here is the code and the errors when you run the test.

    CODE:
    require 'spec_helper'

    RSpec.describe '00: Respondent Answers' do
    class Response
    def self.count(responses)
    # your code goes here
    responses.size
    end

    def self.for(responses, user)
    # your code goes here
    responses.answer
    end

    def self.present?(responses, user)
    # your code goes here
    end

    def self.positive(responses)
    # your code goes here
    end

    def self.negative(responses)
    # your code goes here
    end

    def self.average(responses)
    # your codes goes here
    end
    end

    let(:responses) do
    [
    { user: "alice@example.com", answer: 1 },
    { user: "bob@example.com", answer: 2 },
    { user: "frank@example.com", answer: 3 },
    { user: "claire@example.com", answer: 4 },
    ]
    end

    context "count" do
    it "counts the number of responses" do
    expect(Response.count(responses)).to eq(4)
    end
    end

    context "for" do
    it "finds the response from frank@example.com" do
    response = Response.for(responses, "frank@example.com")
    expect(response[:answer]).to eq(3)
    end

    it "finds the response from bob@example.com" do
    response = Response.for(responses, "bob@example.com")
    expect(response[:answer]).to eq(2)
    end
    end

    context "present?" do
    it "frank@example.com's response is present" do
    expect(Response.present?(responses, "frank@example.com")).to be true
    end

    it "bill@example.com's response is not present" do
    expect(Response.present?(responses, "bill@example.com")).to be false
    end
    end

    context "positive" do
    it "finds the positive responses (score > 3)" do
    expect(Response.positive(responses)).to eq(1)
    end
    end

    context "negative" do
    it "finds the negative responses (score < 3)" do
    expect(Response.negative(responses)).to eq(2)
    end
    end

    context "average" do
    it "finds the average of the answers" do
    expect(Response.average(responses)).to eq(2.5)
    end
    end
    end

    -------------------------------------------------------
    when you run this test: bundle exec rspec
    here are the errors:

    0: Respondent Answers
    count
    counts the number of responses
    for
    finds the response from frank@example.com (FAILED - 1)

    Failures:

    1) 00: Respondent Answers for finds the response from frank@example.com
    Failure/Error: responses.answer

    NoMethodError:
    undefined method `answer' for #<Array:0x00000000040383e8>
    # ./spec/00_respondents_answers_spec.rb:12:in `for'
    # ./spec/00_respondents_answers_spec.rb:49:in `block (3 levels) in <top (required)>'

    Finished in 0.01567 seconds (files took 2.58 seconds to load)
    2 examples, 1 failure

    Failed examples:

    rspec ./spec/00_respondents_answers_spec.rb:48 # 00: Respondent Answers for finds the response from frank@example.com
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2018
    Posts
    6
    Rep Power
    0
    Hi kalso,
    this is not a forum where we help people with their homework.
    If you need help understanding something please post that.

IMN logo majestic logo threadwatch logo seochat tools logo