Giter Site home page Giter Site logo

basic-sinatra-forms-lab's Introduction

Sinatra Forms Lab

Overview

In this lab, you'll practice building forms in Sinatra by creating a basketball team sign-up sheet. Your application will have a basic HTML form, and will display the data from the form after it has been submitted by the user.

Instructions

  1. Run bundle install

  2. Run shotgun

  3. Make a form

    Create a route that responds to a GET request at /newteam. Add a form to the newteam.erb template and render it in the GET /newteam route.

    The form should have fields for: Team name ('name') Coach ('coach') Point Guard ('pg') Shooting Guard ('sg') Power Forward ('pf') Small Forward ('sf') Center ('c')

It should look something like this:

form for basketball team

When creating your form, your "Submit" button will need to be identified by an id attribute with value of "Submit". We're telling this to you now because our test framework, Capybara, requires buttons to be findable by an id, title, or value attribute.

  1. Handle form submission

    Create a route that responds to a POST request at /team. Have the form send a POST request to this route. Upon submission, pass the submitted data to the team.erb template.

  2. Final Output

    Update the team.erb template so when you post to this form, it displays the name of the team and each member of the team.

    Your view should display something like this:

    completed form

  3. Deliverables

Pass the tests! Make sure you read the test output carefully!

Resources

basic-sinatra-forms-lab's People

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

basic-sinatra-forms-lab's Issues

Spelling error

Attribute is duplicated, please see below!

When creating your form, your "Submit" button will need to be identified by an id attribute attribute with value of "Submit". We're telling this to you now because our test frame work, Capybara, requires buttons to be findable by an id, title, or value attribute.

id/name attribute for submit button

There is a paragraph in the instructions of this lab that states, "When creating your form, your "Submit" button will need to be identified by either an id attribute or a name attribute with value of "Submit"." I have found two issues with this instruction. For both of the issues below I receive the same error.

Capybara::ElementNotFound: Unable to find visible button "submit"

  1. The value has to be "submit" not "Submit" to get the tests to pass.
  2. Secondly, setting an attribute as name and it's value as "submit" brings about the error above as well. I could be setting the name attribute incorrectly, but I don't think so since I followed how we previously did it in labs and looked at W3 school for clarification on attributes for input and button tags. When I changed the attribute to either 'id' or 'value' all of the tests pass.

REST

Not using restful conventions.

Spec missing small forward

The spec checks Shooting guard twice and never checks small forward.

basic_sinatra_forms_spec.rb

check lines 49 - 56
and
check lines 67 -74

Solution seems off

In the solution file, app.rb seems funny:
There is never a call to erb :team so the team.erb file is never in play
The instance variables are from the previous lesson and in the wrong place, and there is leftover code from previous lesson where we reversed a string using a form.
Here is what I think it sould look like:

require 'sinatra/base'

class App < Sinatra::Base

get '/newteam' do
erb :newteam
end

post '/team' do
@name = params["name"]
@coach = params["coach"]
@pg = params["pg"]
@sg = params["sg"]
@sf = params["sf"]
@pf = params["pf"]
@c = params["c"]
erb :team
end

end

Change "/team" to "/newteam"

The post request should be from /newteam, not /team. This is how it's explained in the prior lessons and is the only way to make the tests pass. The form information comes from /newteam and gets passed to the /team page through post /newteam. Please see below and note that the solution code needs to be edited as well.

Original: "Create a route that responds to a POST request at /team"
Corrected: "Create a route that responds to a POST request at /newteam"
*changed "/team" to "/newteam"

spelling error

Your application will have a basic HTML form, and will display the data from the form after it has been submitted by the user.

if there is no spelling error please explain what it means!!!

I found a few issues with the tests.

Hi. I found a few issues with the tests. The most important one is that there is a test missing for the Small Forward in the describe 'POST /team' block. I think it needs to look something like this:

it "displays the small forward's name in the browser" do
      visit '/newteam'

      fill_in(:sf, :with => "Ian")
      click_button "Submit"

      expect(page).to have_text("Small Forward: Ian")
    end

The second issue is that the tests are in a different order than the output shown in the README.

Lastly, there's a small typo in the it "displays the shooting gaurd's name in the browser" block (Line 65, as of now). "gaurd" should be "guard".

Thanks for looking into this! As I said, the first issue here is the most important one; the other two don't need to be high priorities (in my opinion).

---Sdcrouse

Incorrect statement - should be "both" instead of "either"

"When creating your form, your "Submit" button will need to be identified by
either an id attribute or a name attribute with value of "Submit"."

This statement is misleading. It says that the form should have EITHER an id attribute OR a name attribute with the value of "submit", but the only way to make the tests pass is if BOTH the type AND the id are set to "submit".

Missing submit button

I was getting the following error:
Failure/Error: click_button "submit" Capybara::ElementNotFound: Unable to find button "submit"

I got it to pass by setting an id value of submit for the button.

typo

In your instructions for this lab, it says that capybara is looking for a name or id of "Submit". In the tests however, it is looking for a name of label of "submit". Lower case s. If it is uppercase, as in the instructions, the test will fail. I recommend changing the instructions or test to reflect each other.

the submit button needs an ID, which is non-obvious

Hi,

From previous lessons, it was not apparent that capybara's test suite needs to have the submit button have an id of "submit"

Team name:

Coach:

Point guard:

Shooting Guard:

Power Forward:

Small Forward:

Center:

The above works, but it also works with:

which is confusing since the app works and does what is expected, but the tests don't pass..?

Failed to load capybara/poltergeist in 'spec_helper.rb'

Had error loading the 'require "capybara/poltergeist"'

Got tests to pass after modifying the 'spec_helper.rb' file to this

ENV["SINATRA_ENV"] = "test"
require_relative '../config/environment'
require 'rack/test'
# require 'capybara/poltergeist'
require 'capybara/rspec'
require 'capybara/dsl'

# Capybara.javascript_driver = :poltergeist

RSpec.configure do |config|
  config.include Capybara::DSL
  config.include Rack::Test::Methods
  config.order = 'default'
end

def app
  Rack::Builder.parse_file('config.ru').first
end

Capybara.app = app

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.