Shopify Application Development by Larkin Michael
Author:Larkin, Michael
Language: eng
Format: epub, mobi, pdf
Published: 2015-06-17T16:00:00+00:00
3. Create the test in /spec/services/contest_results_spec.rb: describe ContestResults do
context "initialize" do
it "should raise exception if not an array" do expect {ContestResults.new([1])}.to_not raise_error expect {ContestResults.new([1,2,3,4])}.to_not raise_error expect {ContestResults.new(["a","b"])}.to_not raise_error expect {ContestResults.new("")}.to raise_error expect {ContestResults.new(nil)}.to raise_error expect {ContestResults.new([])}.to raise_error expect {ContestResults.new}.to raise_error
end
end context "results" do
it "should return the proper results" do contest_results = ContestResults.new([1,2,3,4]) contest_results.results.should be_a Integer contest_results.results(1).should be_a Integer contest_results.results(2).should be_a Array contest_results.results(0).should be_a Integer contest_results.results(nil).should be_a Integer
contest_results = ContestResults.new(["a","b","c","d"]) contest_results.results.should be_a String
contest_results.results(1).should be_a String contest_results.results(2).should be_a Array contest_results.results(0).should be_a String contest_results.results(nil).should be_a String
end
end
end
4. Now that we have tests, we can fill in the methods we stubbed out earlier with code. As mentioned, we are going to use the Array#sample method and return the results. If we later decide to use a different algorithm to choose a winner, we only need to make the change in one class, and we already have tests in place that will ensure that we don't break existing code elsewhere in the app: class ContestResults
def initialize(array)
raise ArgumentError.new("array is required") if array.blank? @array = array
end
#Picks <count> winners def results(count=1) if count.to_i < 2 @array.sample
else
@array.sample(count) end
end
end
Download
Shopify Application Development by Larkin Michael.mobi
Shopify Application Development by Larkin Michael.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9365)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9336)
The Mikado Method by Ola Ellnestam Daniel Brolund(9300)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7845)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7397)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7304)
Grails in Action by Glen Smith Peter Ledbrook(7291)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7111)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5951)
Kotlin in Action by Dmitry Jemerov(4633)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(3848)
Functional Programming in JavaScript by Mantyla Dan(3718)
Learning Java by Patrick Niemeyer & Daniel Leuck(2867)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2830)
Mastering Python for Finance by Weiming James Ma;(2825)
WordPress Plugin Development Cookbook by Yannick Lefebvre(2578)
Mastering Java 9 by Dr. Edward Lavieri(2569)
Architecting Modern Java EE Applications: Designing lightweight, business-oriented enterprise applications in the age of cloud, containers, and Java EE 8 by Daschner Sebastian(2555)
Learning Concurrency in Python by Elliot Forbes(2547)