How to use stringify_keys method of Queries Package

Best Capybara code snippet using Queries.stringify_keys

ar_queries_spec.rb

Source:ar_queries_spec.rb Github

copy

Full Screen

...6 subject { to_lead_or_not_to_lead.as_json }7 it 'retrieves the correct information' do8 expected_result = [9 { id: 4685, ord: 3}10 ].map{ |el| el.stringify_keys }11 expect(subject).to contain_exactly(*expected_result)12 end13 it 'hits the database exactly once' do14 expect{ subject }.to make_database_queries(count: 1)15 end16end17describe 'highest_score' do18 subject { highest_score.as_json }19 it 'retrieves the correct information' do20 expected_result = [21 { id: 2, title: "Shawshank Redemption, The"},22 { id: 12, title: "Godfather, The"},23 { id: 241, title: "Shichinin no samurai"},24 { id: 331, title: "Wo hu zang long"}25 ].map{ |el| el.stringify_keys }26 expect(subject).to contain_exactly(*expected_result)27 end28 it 'hits the database exactly once' do29 expect{ subject }.to make_database_queries(count: 1)30 end31end32describe 'star_wars_movies' do33 subject { star_wars_movies.as_json }34 it 'retrieves the correct information' do35 expected_result = [36 { id: 1, title: "Star Wars", yr: 1977 },37 { id: 5, title: "Star Wars: Episode V - The Empire Strikes Back", yr: 1980 },38 { id: 13, title: "Star Wars: Episode VI - Return of the Jedi", yr: 1983 },39 { id: 17, title: "Star Wars: Episode I - The Phantom Menace", yr: 1999 }40 ].map{ |el| el.stringify_keys }41 expect(subject).to contain_exactly(*expected_result)42 end43 it 'hits the database exactly once' do44 expect{ subject }.to make_database_queries(count: 1)45 end46end47describe 'wesley_movies' do48 subject { wesley_movies.as_json }49 it 'retrieves the correct information' do50 expected_result = [51 { id: 369, title: "Demolition Man", score: 6.1 },52 { id: 497, title: "U.S. Marshals", score: 6.2 },53 { id: 213, title: "Blade", score: 6.7 },54 { id: 1654, title: "Drop Zone", score: 5.5 },55 { id: 1585, title: "New Jack City", score: 6.1 },56 { id: 1243, title: "Money Train", score: 5.1 },57 { id: 1191, title: "Passenger 57", score: 5.4 },58 { id: 1277, title: "Murder at 1600", score: 6.0 },59 { id: 1294, title: "To Wong Foo, Thanks for Everything, Julie Newmar", score: 5.5 },60 { id: 880, title: "Rising Sun", score: 6.0 },61 { id: 1054, title: "Fan, The", score: 5.4 },62 { id: 751, title: "White Men Can't Jump", score: 6.2 }63 ].map{ |el| el.stringify_keys }64 expect(subject).to contain_exactly(*expected_result)65 end66 it 'hits the database exactly once' do67 expect{ subject }.to make_database_queries(count: 1)68 end69end70describe 'michelle_movies' do71 subject { michelle_movies.as_json }72 it 'retrieves the correct information' do73 expected_result = [ 74 { id: 281, title: "Dangerous Liaisons", yr: 1988 },75 { id: 350, title: "Scarface", yr: 1983 },76 { id: 506, title: "Prince of Egypt, The", yr: 1998 },77 { id: 856, title: "Age of Innocence, The", yr: 1993 },78 { id: 429, title: "What Lies Beneath", yr: 2000 },79 { id: 1012, title: "Fabulous Baker Boys, The", yr: 1989 },80 { id: 1284, title: "Frankie and Johnny", yr: 1991 },81 { id: 1035, title: "Midsummer Night's Dream, A", yr: 1999 },82 { id: 493, title: "Witches of Eastwick, The", yr: 1987 },83 { id: 748, title: "One Fine Day", yr: 1996 },84 { id: 205, title: "Batman Returns", yr: 1992 },85 { id: 1546, title: "Deep End of the Ocean, The", yr: 1999 },86 { id: 1644, title: "Russia House, The", yr: 1990 },87 { id: 802, title: "Wolf", yr: 1994 },88 { id: 1239, title: "Up Close & Personal", yr: 1996 },89 { id: 970, title: "Tequila Sunrise", yr: 1988 },90 { id: 894, title: "Dangerous Minds", yr: 1995 },91 { id: 1115, title: "Story of Us, The", yr: 1999 },92 { id: 1845, title: "Hollywood Knights, The", yr: 1980 },93 { id: 1275, title: "Amazon Women on the Moon", yr: 1987 },94 { id: 1024, title: "Grease 2", yr: 1982 }95 ].map{ |el| el.stringify_keys }96 expect(subject).to eq(expected_result)97 end98 it 'hits the database exactly once' do99 expect{ subject }.to make_database_queries(count: 1)100 end101end102describe 'actor_ids_from_grease' do103 subject { actor_ids_from_grease }104 it 'retrieves the correct information' do105 expect(subject).to contain_exactly(106 34, 317, 1413, 1764, 2956, 3434, 3832, 4136107 )108 end109 it 'hits the database exactly once' do110 expect{ subject.as_json }.to make_database_queries(count: 1)111 end112end113describe 'susan_supporting_roles' do114 subject { susan_supporting_roles.as_json }115 it 'retrieves the correct information' do116 expected_result = [117 { id: 575, title: "Bull Durham" },118 { id: 493, title: "Witches of Eastwick, The" },119 { id: 193, title: "Rocky Horror Picture Show, The" },120 { id: 1528, title: "Twilight" },121 { id: 1608, title: "Hunger, The" },122 { id: 1788, title: "Atlantic City" },123 { id: 1377, title: "Cradle Will Rock" },124 { id: 756, title: "Stepmom" }125 ].map{ |el| el.stringify_keys }126 expect(subject).to contain_exactly(*expected_result)127 end128 it 'hits the database exactly once' do129 expect{ subject }.to make_database_queries(count: 1)130 end131end132describe 'best_years' do133 subject { best_years }134 it 'retrieves the correct information' do135 expected_result = [1943,136 1935,137 1934,138 1933,139 1930,140 1922,141 1936,142 1939,143 1938,144 1925,145 1929,146 1927,147 1952]148 expect(subject).to contain_exactly(*expected_result)149 end150 it 'hits the database exactly once' do151 expect{ subject }.to make_database_queries(count: 1)152 end153end154describe 'smallest_cast' do155 subject { smallest_cast.as_json }156 it 'retrieves the correct information' do157 expected_result = [158 { id: 905, title: "Wallace & Gromit: A Grand Day Out" },159 { id: 165, title: "Wallace & Gromit: The Wrong Trousers" },160 { id: 383, title: "Wallace & Gromit: A Close Shave" }161 ].map{ |el| el.stringify_keys }162 expect(subject).to contain_exactly(*expected_result)163 end164 it 'hits the database exactly once' do165 expect{ subject }.to make_database_queries(count: 1)166 end167end168describe 'not_too_good' do169 subject { not_too_good.as_json }170 it 'retrieves the correct information' do171 expected_result = [172 { id: 1407, title: "Nothing But Trouble" },173 { id: 1797, title: "Friday the 13th Part 3: 3D" },174 { id: 1521, title: "Dracula: Dead and Loving It" },175 { id: 1413, title: "Hanging Up" },176 { id: 1301, title: "Book of Shadows: Blair Witch 2" }177 ].map{ |el| el.stringify_keys }178 expect(subject).to contain_exactly(*expected_result)179 end180 it 'hits the database exactly once' do181 expect{ subject }.to make_database_queries(count: 1)182 end183end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful