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(9916)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8300)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7781)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Windows APT Warfare by Sheng-Hao Ma(6849)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6584)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6454)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6417)
Kotlin in Action by Dmitry Jemerov(5065)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4317)
Functional Programming in JavaScript by Mantyla Dan(4038)
Solidity Programming Essentials by Ritesh Modi(4009)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3801)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3745)
The Ultimate iOS Interview Playbook by Avi Tsadok(3719)
