GithubHelp home page GithubHelp logo

saasbook / hw-sinatra-saas-wordguesser Goto Github PK

View Code? Open in Web Editor NEW
31.0 22.0 1.9K 254 KB

Wordguess: a scaffolded (!) ESaaS getting-started assignment using Sinatra

Ruby 65.99% HTML 11.46% Gherkin 22.30% Procfile 0.25%

hw-sinatra-saas-wordguesser's Introduction

Wordguesser: a scaffolded (!) ESaaS getting-started assignment

(v1.1, September 2015. Written by Armando Fox and Nick Herson) (some edits by mverdicchio 21 September 2015) (refinements by Armando Fox September 2017)

In this assignment you'll be introduced to part of the basic cycle of creating SaaS in a disciplined way.

NOTE: Do not clone this repo to your workspace. Fork it first, then clone your fork.

Learning Goals

After completing this assignment, you will be able to:

  • Create and deploy simple SaaS apps in your development environment, and deploy them to the public cloud
  • Practice the basic workflow of test-driven development (TDD), in which tests are written before the code (so they fail when first run) and code is then added to make them pass
  • Understand how SaaS frameworks such as Sinatra support the conceptual components of a three-tier SaaS application architecture
  • Understand the challenges of adapting a non-SaaS application to a SaaS environment, including how to identify and manage application state
  • Understand one use case of service-oriented architecture, in which your SaaS app relies on an external service's API (application programming interface) to provide part of the SaaS app's functionality.

Prerequisites

  • You should be familiar with Ruby basics, for example by completing the Ruby Intro or Ruby Calisthenics assignment.
  • You should have read ESaaS Chapter 2, "The Architecture of SaaS Applications", and watched the accompanying videos in the MOOC.
  • You should be comfortable with basic Git usage and how to push your code to GitHub, as described in Appendix A of ESaaS.
  • You will need "survival level" Unix command-line skills and facility with an editor to edit code files.

NOTE: You may find the Sinatra documentation helpful to have on hand.

Introduction

The full Agile/XP cycle we follow in ESaaS includes talking to the customer, using BDD to develop scenarios, turning those scenarios into runnable integration/acceptance tests with Cucumber, using those scenarios plus TDD to drive the creation of actual code, and deploying the result of each iteration's work to the cloud.

In this introductory assignment, we've provided RSpec unit tests to let you use TDD to develop game logic for a word-guessing game. In the full Agile/XP cycle, you'd develop these tests yourself as you code.

You'll then use the Sinatra framework to make the Wordguesser game available as SaaS. Adapting the game logic for SaaS will introduce you to thinking about RESTful routes and service-oriented architecture. As you develop the "SaaS-ified" Wordguessing game, you'll use Cucumber to describe how gameplay will work from the player's point of view and as "full stack" integration tests that will drive SaaS development. In the full Agile/XP cycle, you'd develop Cucumber scenarios yourself based on consultation with the customer, and create the necessary step definitions (Cucumber code that turns plain-English scenarios into runnable tests). In this assignment we provide both the scenarios and step definitions for you.

You'll deploy your game to the cloud using Heroku, giving you experience in automating SaaS deployment.

Why Sinatra?

This assignment uses the simple Sinatra framework rather than Rails, so that you can focus on tools, mechanics, and SaaS concepts, all of which will readily map to Rails later. Since our app doesn't have a database and has very few functions, Sinatra is an easy way to get started.

Contents

hw-sinatra-saas-wordguesser's People

Contributors

timothyaveni avatar

Stargazers

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

Watchers

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

hw-sinatra-saas-wordguesser's Issues

HW URL text files that are rejected by the autograder

NOTE TO STUDENTS:

if you have submitted a text file that produces "socket error" or the spinner just keeps spinning

firstly - the file MUST be ASCII encoded if you do not know what this means then please create your text file in cloud9 exactly as directed in the assignment using the echo command

next - visit the address you have in your text file in your web browser to be sure that your app is running correctly at that address

next - if that is working - note that the assignment specifies the URL of a specific form - the URL in the text file should contain neither http:// nor https:// - it should look like this:

myapp.herokuapp.com

if after that you still are getting a fatal error from the autograder or if the spinner keeps spinning longer than 10 minutes please drag and drop that file to a comment here so we can debug against it


NOTE TO ADMIN:

  • this file contains 'https'and throws the socket error TEXT_FILE_HIDDEN

  • this file is UTF16 and causes the grader to hang indefinitely TEXT_FILE_HIDDEN

  • this file is UTF8 and contain this text: '–n “myapp.herokuapp.com”' but curiously unlike the others this does not make the grader choke but completes successfully with 0/80 grade but her grade would have been 75/80 TEXT_FILE_HIDDEN

edit this post to get the files

perhaps a grader regex like http://rubular.com/r/NiHjcUCHIs

Versioning in Sinatra

From Part 4 - Link

Hey from the gitter / slack group for the saas moc - found an issue which bundle install / bundle update alone didn't help.

Fix for me was one of the 3 elements (I'm in a rush so not backtracking to isolate):

Config file in spec_helper - Link
Version of rspec too far behind - Link
Version of capybara too far behind - Link

My gem file at time of working ....

Gemfile

source 'https://rubygems.org'
ruby '2.3.0'

gem 'sinatra', '>= 1.4'
gem 'sinatra-flash', '0.3.0'

group :development, :test do
  gem 'cucumber', '2.0.0'
  gem 'cucumber-sinatra', '0.5.0'
  gem 'capybara', '~> 2.8'

  gem 'rspec', '3.5.0'
  gem 'rspec-autotest', '1.0.0'

  gem 'rack-test', '0.6.3'
  gem 'rack_session_access', '0.1.1'

  gem 'byebug', '5.0.0'
  gem 'launchy', '2.4.3'

  gem 'simplecov', '0.10.0'
  gem 'webmock', '1.21.0'
  gem 'ZenTest', '4.11.0'
  
  # Added per tutorial
  gem 'rerun'

end

My spec file

spec/spec_helper.rb
#require 'simplecov'
#SimpleCov.start

require File.join(File.dirname(__FILE__), '..', 'app.rb')

require 'sinatra'
require 'rack/test'
require 'webmock/rspec'
require 'byebug'

# setup test environment
set :environment, :test
set :run, false
set :raise_errors, true
set :logging, false

use Rack::Session::Cookie

def app
  HangpersonApp.new!
end

def session
  last_request.env['rack.session']
end

# The following lines disable web usage and causes the external API to be stubbed out,
# eliminating randomness to aid in testing
def stub_random_word(word)
  stub_request(:post, 'http://watchout4snakes.com/wo4snakes/Random/RandomWord').to_return(:body => word)
end

WebMock.disable_net_connect!(allow_localhost: true)

RSpec.configure do |config|
  config.include Rack::Test::Methods

  config.before(:each) do
    stub_request(:post, "http://watchout4snakes.com/wo4snakes/Random/RandomWord").to_return(:body => "foobar")
  end
  config.color = true
end

links to references on git

requested by Rose:

more linkage to the part of the textbook that covers forking and cloning which some students struggled with

Incorrect URI?

In line 21 of hangperson_game.rb, line 13 of game_steps.rb and line 4 of webmocks.rb

the URI http://watchout4snakes.com/wo4snakes/Random/RandomWord is being used

however when I call the class method HangpersonGame.get_random_word in the irb or play the game deployed on Heroku, it appears that POST to that URI does not actually return a random word

it appears that the correct URI is http://watchout4snakes.com/Random/RandomWord? which works in irb and when app is deployed to Heroku

no longer need quotes for rerun on C9

from KSM:

this line no longer seems to apply: "Note that you need to put everything except rerun in quotes in order to make the command unambiguous in Cloud9.

Testing wrong

Guessing context 'correctly' says that @Valid should return true, then surely context 'incorrectly' should expect that @Valid should return false

Two misleading places, and one error.

1/ hangperson_game_spec: There are several big blocks of pending, and within each of them have several small blocks of pending. Once The big blocks changed to not pending ( i.e. remove ;pending = true or change to pending = false), the small ones inside will got RED ERRORS even if it's still pending, and no matter you've rightly implemented those scripts or not. -- This is misleading, don't know if it's a bug of rspec's. IMHO it's worth mention in the instructions.

2/ Corner case, return :lose if (@guesses + @wrong_guesses).length > 6 , rspec should notice this kind of error, by add one or two correct letters in the 'should be lose after 7 incorrect guesses' test scenario.

3/ Minor ERROR: rerun -- cucumber features/ leads to endless cycle of reruns after first codes update, even if there's no codes update afterwards.

Thanks :)

Passes the test with a wrong behaviour

Hello
I don't understand why my program passes this test ?
Instead of "a---a-", my method returns "------" as I checked with byebug. Also, my post /guess is still empty!

  post '/guess' do
    letter = params[:guess].to_s[0]
    ### YOUR CODE HERE ###
    flash[:message]="You have already used that letter." if not @game.word.include?(letter)
    redirect '/show'
  end
    Given I start a new game with word "animal"             # features/step_definitions/game_steps.rb:12

[47, 56] in /home/user/edx/agile_dev_basics/hw-sinatra-saas-hangperson/lib/hangperson_game.rb
 # def word_with_guesses
   47: 	dashed_word=@word.clone
   48: 	dashed_word.each_char do |l|
   49: 		dashed_word.gsub! l,"-" if not guesses.include?(l)
   50: 	end
   51:         byebug
=> 52: 	dashed_word
   53:   end
   54: 
   55:   def check_win_or_lose
   56: 	return :win if not word_with_guesses.include? ("-")
(byebug) "------"
(byebug)     When I guess "a"                                        # features/step_definitions/game_steps.rb:19
    Then I should see "a---a-" within "span.word"           # features/step_definitions/game_steps.rb:71

Kind regards.

Some possible changes to the instructions?

From one of the SPOC instructors:

Before we could run git push heroku master:
— The instructions for getting set up on Heroku did not include setting up the keys. We had to use heroku keys:add ~/.ssh/id_rsa.pub
— We needed to use git remote add heroku [email protected]:.git

Tests:
— We had to run bundle install before we could run autotest
— odd errors in autotest on pending tests
— there seems to be an error on the third test for context ‘incorrectly’ - it appears to be looking for valid to be true when the guess is not correct

Perhaps some of these things should be added to the instructions.

Student pass all cucumber and rspec tests without setting flash

Apparently, there are no tests that check to see that the flash is getting set at all (let alone, properly).

If I take a proper solution and substitute this code for the guess method in app.rb, all the tests still pass:

    # Use existing methods in HangpersonGame to process a guess.
    # If a guess is repeated, set flash[:message] to "You have already used that letter."
    # If a guess is invalid, set flash[:message] to "Invalid guess."
    post '/guess' do
      begin
        letter = params[:guess].to_s[0] #this code was given
        #flash[:message] = "You have already used that letter." if ! @game.guess(letter)
        valid = @game.guess(letter)
      rescue ArgumentError
        #flash[:message] = "Invalid guess."
      end
      redirect '/show'
    end

Incorrect Spec?

Hi guys!

In hangperson_game_spec.rb line 45

it 'returns true' do
   expect(@valid).not_to be false
end

Which is wrong because the word is 'garply' and the guess is 'z': @valid = @game.guess('z')?

Shouldn't it be the other way around?

it 'returns false' do
   expect(@valid).not_to be true
end

unknown method 'normalize_params' when running cucumber test

This is the error when trying to run the guess.feature test:

➜  hw-sinatra-saas-hangperson git:(master) ✗ cucumber features/guess.feature:7
Feature: guess correct letter

  As a player playing Hangperson
  So that I can make progress toward the goal
  I want to see when my guess is correct

  Scenario: guess correct letter that occurs once # features/guess.feature:7
    Given I start a new game with word "garply"   # features/step_definitions/game_steps.rb:12
    When I guess "r"                              # features/step_definitions/game_steps.rb:19
      undefined method `normalize_params' for Rack::Utils:Module (NoMethodError)
      ./features/step_definitions/game_steps.rb:22:in `/^I guess "(.*)"(?: again)?$/'
      features/guess.feature:10:in `When I guess "r"'
    Then I should see "r" within "span.word"      # features/step_definitions/game_steps.rb:71

Failing Scenarios:
cucumber features/guess.feature:7 # Scenario: guess correct letter that occurs once

1 scenario (1 failed)
3 steps (1 failed, 1 skipped, 1 passed)
0m0.050s
Coverage report generated for Cucumber Features to /Users/miafro/Documents/edx/saasbook/hw-sinatra-saas-hangperson/coverage. 43 / 61 LOC (70.49%) covered.

This seems to be an issue related to the click_button method in the game_steps.rb file.

SOLUTION FOUND: Updating to the latest Capybara release 2.16.1 fixed the issue for me.
Has anyone else seen this issue?

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.