code school testing with spec(1)

#level 1 ###describe (lets start writing a specification for the Tweet class. Write a describe block for the Tweet model without any example inside it)

class Tweet 
end

answer

describe Tweet do 
end

###it(create a pending test called “can be status”)

class Tweet 
end

answer

describe Tweet do 
  it "can be status" 
end

###expectation(now let’s write the example. Go ahead and instantiate a tweet, give it the status “Nom nom nom”, and test the status has been properly set to this value using an ==)

class Tweet 
  attr_accessor :status 
  
  def initialize(option = {})
    self.status = options[:status]
  end
  
  def public?
    self.status && self.status[0] != "@"
  end
end

answer

describe Tweet do 
  it "can set status" do 
    tweet = Tweet.new 
    tweet.status = "Nom nom nom"
    tweet.status.should = "Nom nom nom"
  end
end

###matchers(using a predicate “be” matcher, make sure that a tweet like “Nom nom nom”(which is bit a reply because it doesn’t start with a “@” sign)is publish)

class Tweet
attr_accessor :status 

def initialize(options={})
  self.status = options[:status]
end

def public? 
  self.status && self.status[0] != "@" 
end

answer

describe Tweet do 
  it "without a leading @ symbol should be public" do 
    tweet = Tweet.new(status: "Nom nom nom")
    tweet.should be_public
  end
end

###comparsion matchers(finish the example below to ensure that our tweet.status.length is less than ir equal to 140 character use a be mathcer in your spec)

class Tweet
  attr_accessor :status

  def initialize(options={})
    self.status = options[:status]
  end

  def public?
    self.status && self.status[0] != "@"                                 
  end

  def status=(status)
    @status = status ? status[0...140] : status
  end
end

answer

describe Tweet do 
  it "truncates the status to 140 characters" do 
    tweet = Tweet.new(status: "Nom nom nom" * 100)
    tweet.status.length.should be <= 140 
  end
end