 
        roberto santelices
Joined
        150 Experience
      
    
        0 Lessons Completed
      
    
        0 Questions Solved
      
    Activity
HEy Chris do you know a way to configure rspec with rails 4 
            Posted in docker mysql
Hey guys i was wondering if you ever get to connect a rails app in local host without dockerizing it and be able to use a docker image of mysql with it.
i already got the mysql image running in docker ps but i would like to be able to get access to it from my rails apps that are not dockerized anybody knows how to achieve this?
            i already got the mysql image running in docker ps but i would like to be able to get access to it from my rails apps that are not dockerized anybody knows how to achieve this?
Posted in caller
Nice man thanks!
Posted in caller
i dont have more code but i do have the spec which needs to pass, i havent been able to resolve it yet
require_relative 'game'
require_relative 'dsl'
describe Game do
  context '#move' do
    it 'should not move unless called within a light' do
      game = Game.play do |g|
        g ||= self
        g.move
      end
      expect(game.distance).to eq 0a
    end
  end
  context '#redlight!' do
    it 'should do nothing if move was not called' do
      game = Game.play do |g|
        g ||= self
        g.redlight! {}
      end
      expect(game.result).to be_nil
    end
    it 'should finish and lose the game if move is called' do
      game = Game.play do |g|
        g ||= self
        g.redlight! do
          g.move
        end
      end
      expect(game.lost?).to be true
      expect(game.distance).to eq 0
    end
  end
  context '#greenlight!' do
    it 'should move if move is called' do
      game = Game.play do |g|
        g ||= self
        g.greenlight! do
          g.move
        end
      end
      expect(game.distance).to eq 10
    end
    it 'should finish and win the game if move is called enough times' do
      game = Game.play do |g|
        g ||= self
        g.greenlight! do
          11.times do
            g.move
          end
        end
      end
      expect(game.won?).to be true
      expect(game.distance).to eq 100
    end
  end
  context 'bonus' do
    it 'should be a true dsl' do
      begin
        game = Game.play do
          greenlight! do
            3.times { move }
          end
          redlight! {}
          greenlight! do
            2.times {move}
          end
          redlight! {}
          greenlight! do
            3.times {move}
          end
          greenlight! do
            2.times {move}
          end
        end
        expect(game.won?).to be true
      rescue NoMethodError
        # fail
      end
    end
  end
end
Posted in caller
Jacob thanks for taking a look, im trying to make that if i call the method move insight the method redligt then it makes the status lose
Posted in caller
nobody? hehe
Posted in caller
I have trouble solving the following excercise, i was wondering if there is any way in ruby where i can get which method called which i think caller but i havent figured out yet
require_relative 'game'
class Game::DSL
  MOVE_DISTANCE = 10
  WIN_DISTANCE  = 100
  def initialize(game)
    @game = game
  end
  # TODO
  # Moving during a redlight will cause the game to end and lose
  def redlight!
  end
  # TODO
  # Moving during a greenlight will allow the player to move
  def greenlight!
  end
  # TODO
  # If called outside a #greenlight! or #redlight! nothing happens
  # Moves the player MOVE_DISTANCE
  # If MOVE_DISTANCE >= WIN_DISTANCE game ends and wins
  def move
  end
end
class Game
  STATUS  = %i[standby playing finished]
  RESULTS = %i[won lost]
  attr_accessor :result, :distance
  def self.play(&block)
    new.play(&block)
  end
  def initialize
    @status   = :standby
    @distance = 0
    @dsl = Game::DSL.new(self)
  end
  # TODO Bonus!
  # Change this so the game truly acts like a DSL
  def play
    catch :finish! do
      start!
      yield @dsl
      finish!
    end
    self
  end
  def start!
    @status = :playing
  end
  # NOTE Call me from Game::DSL to end the game!
  def finish!
    @status = :finished
    freeze
    throw :finish!
  end
  # Defines #result=
  # Ensures you don't typo out of the valid results
  def result=(value)
    raise "'#{value}' is not a valid result. (Check for Typos)" unless RESULTS.include? value
    @result = value
  end
  # Defines #standby? #playing? #finished?
  STATUS.each do |status|
    define_method("#{status}?") { @status == status }
  end
  # Defines #won? #lost?
  RESULTS.each do |result|
    define_method "#{result}?" do
      raise "##{__method__} called before game finished!" unless finished?
      @result == result
    end
  end
end
I put comments in it