From pafahim at gmail.com Sat Sep 1 10:43:56 2012 From: pafahim at gmail.com (Fahim Patel) Date: Sat, 1 Sep 2012 16:13:56 +0530 Subject: [rspec-users] Thanks Message-ID: Selenium automates web browsers. Cucumber automates tests. can u please explain this line?? thanks can u give answer on this questions Q1 if i have 2 sceanario and 1 background . but i want only 1 scenario should used that backgound and 2nd scenario dont use that background. and i want to run them same time. can it is possible ? Q2 What is the diff between Capybara and Webrat? Which one is by default configure with cucumber ? If both are providing same functionality than which one i use? Q3 How to test view in cucumber ? I want to test CSS and body of page(DOM objects) are working perfectly or not ?How to Write in Scenario to test View? Q4 What is this Silenium Framework ? Can i use this for Rails application ? This framework is better than Cucumber for High level testing ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Sep 1 23:59:50 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 1 Sep 2012 19:59:50 -0400 Subject: [rspec-users] Thanks In-Reply-To: References: Message-ID: On Sat, Sep 1, 2012 at 6:43 AM, Fahim Patel wrote: > Selenium automates web browsers. > > Cucumber automates tests. > > > can u please explain this line?? Please read the docs for these tools: http://cukes.info/ http://seleniumhq.org/ > thanks > > can u give answer on this questions All of the questions below are about Cucumber. Please post these questions to https://groups.google.com/forum/?fromgroups#!forum/cukes. > > Q1 > if i have 2 sceanario and 1 background . > but i want only 1 scenario should used that backgound and 2nd scenario > dont use that background. > > > and i want to run them same time. > can it is possible ? > > Q2 > What is the diff between Capybara and Webrat? > Which one is by default configure with cucumber ? > If both are providing same functionality than which one i use? > > > Q3 > How to test view in cucumber ? > I want to test CSS and body of page(DOM objects) are working perfectly or > not ?How to Write in Scenario to test View? > > > Q4 > What is this Silenium Framework ? > Can i use this for Rails application ? > > This framework is better than Cucumber for High level testing ? > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Sun Sep 2 06:20:47 2012 From: lists at ruby-forum.com (David Tishkoff) Date: Sun, 02 Sep 2012 08:20:47 +0200 Subject: [rspec-users] RSpec Selenium Webdriver Html Report with Screenshots Message-ID: <2644b3be84d03b2d9b008b96f61ec7b4@ruby-forum.com> Hello, I'm using Rake + RSpec + Selenium-WebDriver for the web testing, Is there a way to create html report with the screenshot generated on failure? Would really appreciate your help! -- Posted via http://www.ruby-forum.com/. From s.cambour at gmail.com Mon Sep 3 12:00:08 2012 From: s.cambour at gmail.com (Javix) Date: Mon, 3 Sep 2012 05:00:08 -0700 (PDT) Subject: [rspec-users] RSpec Selenium Webdriver Html Report with Screenshots In-Reply-To: <2644b3be84d03b2d9b008b96f61ec7b4@ruby-forum.com> References: <2644b3be84d03b2d9b008b96f61ec7b4@ruby-forum.com> Message-ID: <04d1722d-9453-4ec6-ad25-3721e8900d38@googlegroups.com> Just a piecec pf code to create a screen shot: private void takeScreenShot(RuntimeException e, String fileName) { File screenShot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); try { FileUtils.copyFile(screenShot, new File(fileName + ".png")); } catch (IOException ioe) { throw new RuntimeException(ioe.getMessage(), ioe); } throw e; } On Sunday, September 2, 2012 8:22:15 AM UTC+2, David Tishkoff wrote: > > Hello, > > I'm using Rake + RSpec + Selenium-WebDriver for the web testing, Is > there a way to create html report with the screenshot generated on > failure? Would really appreciate your help! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec... at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From s.cambour at gmail.com Mon Sep 3 11:58:46 2012 From: s.cambour at gmail.com (Javix) Date: Mon, 3 Sep 2012 04:58:46 -0700 (PDT) Subject: [rspec-users] RSpec Selenium Webdriver Html Report with Screenshots In-Reply-To: <2644b3be84d03b2d9b008b96f61ec7b4@ruby-forum.com> References: <2644b3be84d03b2d9b008b96f61ec7b4@ruby-forum.com> Message-ID: You can generate HTML reports with surefire, just addd the folowing to your POM file: org.apache.maven.plugins maven-site-plugin 3.1 org.apache.maven.plugins maven-surefire-report-plugin 2.4.3 See more details on its use at http://maven.apache.org/plugins/maven-surefire-plugin/ adn http://maven.apache.org/plugins/maven-surefire-report-plugin/ for reporting. As for screen shots, see takeScreenShot class in Selenium API: http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html?overview-summary.html On Sunday, September 2, 2012 8:22:15 AM UTC+2, David Tishkoff wrote: > > Hello, > > I'm using Rake + RSpec + Selenium-WebDriver for the web testing, Is > there a way to create html report with the screenshot generated on > failure? Would really appreciate your help! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec... at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Mon Sep 3 17:59:21 2012 From: lists at ruby-forum.com (David Tishkoff) Date: Mon, 03 Sep 2012 19:59:21 +0200 Subject: [rspec-users] RSpec Selenium Webdriver Html Report with Screenshots In-Reply-To: <04d1722d-9453-4ec6-ad25-3721e8900d38@googlegroups.com> References: <2644b3be84d03b2d9b008b96f61ec7b4@ruby-forum.com> <04d1722d-9453-4ec6-ad25-3721e8900d38@googlegroups.com> Message-ID: <0e9acd56e0291a9c6f3477c6a8d33aac@ruby-forum.com> Serguei Cambour wrote in post #1074435: > Just a piecec pf code to create a screen shot: > > private void takeScreenShot(RuntimeException e, String fileName) { > > File screenShot = ((TakesScreenshot) > driver).getScreenshotAs(OutputType.FILE); > > try { > > FileUtils.copyFile(screenShot, new File(fileName + ".png")); > > } catch (IOException ioe) { > > throw new RuntimeException(ioe.getMessage(), ioe); > > } > > throw e; > > } Thank you for the help, sorry I forgot to mention that I'm using ruby and I need screenshots to be included into RSpec html reports. -- Posted via http://www.ruby-forum.com/. From pafahim at gmail.com Tue Sep 4 04:57:26 2012 From: pafahim at gmail.com (Fahim Patel) Date: Tue, 4 Sep 2012 10:27:26 +0530 Subject: [rspec-users] your cuke forum is not opening Message-ID: https://groups.google.com/forum/?fromgroups#!forum/cukes. this link is not opening... can u give me accurate link... thanks Fahim babar patel -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Sep 4 10:38:14 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Sep 2012 06:38:14 -0400 Subject: [rspec-users] your cuke forum is not opening In-Reply-To: References: Message-ID: On Tue, Sep 4, 2012 at 12:57 AM, Fahim Patel wrote: > https://groups.google.com/forum/?fromgroups#!forum/cukes. > > this link is not opening... > can u give me accurate link... Try http://groups.google.com/group/cukes From lists at ruby-forum.com Fri Sep 7 19:14:10 2012 From: lists at ruby-forum.com (Anand K V R.) Date: Fri, 07 Sep 2012 21:14:10 +0200 Subject: [rspec-users] Newbie testing questions In-Reply-To: <116e33fa2c1a6388da420b253881b536@ruby-forum.com> References: <116e33fa2c1a6388da420b253881b536@ruby-forum.com> Message-ID: <49066c38bbe9b562569405e3a998c4a0@ruby-forum.com> Hi Friends. I'm an absolute Tester (little experience on development upto college level) and had been asked to Test an application developed in Rails. As our client selected Rspec, I have no other go. Can anyone help me with a basic program in Rspec how to open GMAIL, enter username / password , then login. Thanks in advance , Aishwarya -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Sep 9 06:00:25 2012 From: lists at ruby-forum.com (jeevan reddy) Date: Sun, 09 Sep 2012 08:00:25 +0200 Subject: [rspec-users] Stub a controller method containing arguments Message-ID: <0bb1d458b13c9d31f0c930d2ab4f7894@ruby-forum.com> controller code: class BooksController < ApplicationController def index param1, param2 = "123", "456" @test = method_1(param1, param2) end private def method_1(param1, param2) return "test" end end controller tests describe "GET index" do it "get books" do param1, param2 = "12334", "456233" controller.stub!(:method_1).with(param1,param2).and_return("test") get :index assert_response :success assigns(:test).should eq("test") end end How to stub a controller private method which will take any arguments -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Sep 9 11:31:56 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 9 Sep 2012 06:31:56 -0500 Subject: [rspec-users] Stub a controller method containing arguments In-Reply-To: <0bb1d458b13c9d31f0c930d2ab4f7894@ruby-forum.com> References: <0bb1d458b13c9d31f0c930d2ab4f7894@ruby-forum.com> Message-ID: On Sun, Sep 9, 2012 at 1:00 AM, jeevan reddy wrote: > controller code: > > class BooksController < ApplicationController > def index > param1, param2 = "123", "456" > @test = method_1(param1, param2) > end > > private > def method_1(param1, param2) > return "test" > end > end > > controller tests > > describe "GET index" do > it "get books" do > param1, param2 = "12334", "456233" > controller.stub!(:method_1).with(param1,param2).and_return("test") > get :index > assert_response :success > assigns(:test).should eq("test") > end > end > > How to stub a controller private method which will take any arguments In your example above, the values of param1 and param2 are different in the rspec example and the controller, so I'm guessing you're getting a failure. If you're constraining a stub with specific args, they have to match. Curious - why do you care about the args in your real spec? From dchelimsky at gmail.com Sun Sep 9 11:51:01 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 9 Sep 2012 06:51:01 -0500 Subject: [rspec-users] Newbie testing questions In-Reply-To: <49066c38bbe9b562569405e3a998c4a0@ruby-forum.com> References: <116e33fa2c1a6388da420b253881b536@ruby-forum.com> <49066c38bbe9b562569405e3a998c4a0@ruby-forum.com> Message-ID: On Fri, Sep 7, 2012 at 2:14 PM, Anand K V R. wrote: > Hi Friends. > > I'm an absolute Tester (little experience on development upto college > level) and had been asked to Test an application developed in Rails. As > our client selected Rspec, I have no other go. > > Can anyone help me with a basic program in Rspec how to open GMAIL, > enter username / password , then login. > > Thanks in advance , > > Aishwarya Take a look at https://github.com/jnicklas/capybara. Everything you need is referenced in the README on that page. From lists at ruby-forum.com Mon Sep 10 21:51:51 2012 From: lists at ruby-forum.com (Fearless Fool) Date: Mon, 10 Sep 2012 23:51:51 +0200 Subject: [rspec-users] Drawing the line between controller and integration tests Message-ID: <153ba8ff3332730d95754dc51849389c@ruby-forum.com> I'm trying to understand what belongs -- and what doesn't belong -- in controller tests and in integration tests. As a common example, assume I have a list of named widgets. Somewhere in my code, I want to verify that widget = FactoryGirl.create(:widget) get :index generates a page that has the string #{widget.name} somewhere therein. But is that a controller test or an integration test? As another example, assume a user must be logged on in order to access the widgets. I can test authentication and authorization separately, but is it considered necessary to write an integration test for this? Or is this something you'd verify at the controller level? Etc. I'm not looking for specific answers to the above as much as guiding principles, or at least pointers to same. Thanks! -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Sep 10 22:28:25 2012 From: lists at ruby-forum.com (Fearless Fool) Date: Tue, 11 Sep 2012 00:28:25 +0200 Subject: [rspec-users] Drawing the line between controller and integration tests In-Reply-To: <153ba8ff3332730d95754dc51849389c@ruby-forum.com> References: <153ba8ff3332730d95754dc51849389c@ruby-forum.com> Message-ID: <8c8e19b15539d60f703e139e90e46a7d@ruby-forum.com> One addendum: One thing I'd specifically like to know is where/how do you test the *contents* of generated responses? That seems beyond the purview of a controller test, but it doesn't require multiple transactions or cross-controller interactions that would require an integration test. -- Posted via http://www.ruby-forum.com/. From ossareh at twitch.tv Mon Sep 10 23:52:20 2012 From: ossareh at twitch.tv (Mike Ossareh) Date: Mon, 10 Sep 2012 16:52:20 -0700 Subject: [rspec-users] Drawing the line between controller and integration tests In-Reply-To: <153ba8ff3332730d95754dc51849389c@ruby-forum.com> References: <153ba8ff3332730d95754dc51849389c@ruby-forum.com> Message-ID: On Mon, Sep 10, 2012 at 2:51 PM, Fearless Fool wrote: > I'm trying to understand what belongs -- and what doesn't belong -- in > controller tests and in integration tests. > > As a common example, assume I have a list of named widgets. Somewhere > in my code, I want to verify that > > widget = FactoryGirl.create(:widget) > get :index > > generates a page that has the string #{widget.name} somewhere therein. > But is that a controller test or an integration test? > Having spent a majority of my time writing test cases I've found there are two main types, unit tests and integration tests. An integration test is called such because it crosses a logical boundary (either in code or over a socket, talking to a database, etc). Unit tests are usually self contained. In your case you're talking about a "controller" test, if I try to fit that into my mental model I can see it as either an integration test or a unit test - and you just need to decide which you want to use. Usually I've found integration tests to have the best bang for buck in terms of stability and unit tests to be very very helpful in fixing bugs and alleviating poor performance in chunks of code. Assuming you had the following flow: 1. User posts a form 2. Controller creates a "widget" 3. Controller redirects user to a list with "widget.name" in it. You would be best served writing an integration test, imho. The fact it is testing the controller and the model is neither here nor there. Let us assume there are some functions that exist on Widget that are not directly called by an HTTP action - then you'd want a unit test. That is the following would be integration tests. Widget #new #update_attributes Where as the following may be unit tests: Widget #friendly_name #synchronize_to_external_service > As another example, assume a user must be logged on in order to access > the widgets. I can test authentication and authorization separately, > but is it considered necessary to write an integration test for this? > Or is this something you'd verify at the controller level? > > Etc. I'm not looking for specific answers to the above as much as > guiding principles, or at least pointers to same. Thanks! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at jbrains.ca Tue Sep 11 14:25:37 2012 From: me at jbrains.ca (J. B. Rainsberger) Date: Tue, 11 Sep 2012 10:25:37 -0400 Subject: [rspec-users] Drawing the line between controller and integration tests In-Reply-To: <153ba8ff3332730d95754dc51849389c@ruby-forum.com> References: <153ba8ff3332730d95754dc51849389c@ruby-forum.com> Message-ID: On Mon, Sep 10, 2012 at 5:51 PM, Fearless Fool wrote: > I'm trying to understand what belongs -- and what doesn't belong -- in > controller tests and in integration tests. > > As a common example, assume I have a list of named widgets. Somewhere > in my code, I want to verify that > > widget = FactoryGirl.create(:widget) > get :index > > generates a page that has the string #{widget.name} somewhere therein. > But is that a controller test or an integration test? > What's the controller's responsibility here? I see two things: * choose the right view * assign the right values to the right variables Actually rendering the right page with the right text on it sounds like a view responsibility. Therefore, how to check that the controller chooses the right view and assigns the variables correctly? As another example, assume a user must be logged on in order to access > the widgets. I can test authentication and authorization separately, > but is it considered necessary to write an integration test for this? > Or is this something you'd verify at the controller level? > I find this slightly trickier. Again, what's the controller's responsibility? * ask to authenticate the user for certain routes * ask to authorize the user for certain routes It seems clear which tests to write for the controller, but I don't want to have to check authentication and authorization for every example I run on a specific route. Therefore, check authentication for each route in its own test. Also, check authorization for each route in its own test. Bad news: this will result in a lot of duplication in tests; good news: I find it easy to remove this duplication into a single set of authentication and authorization checks. Imagine something like this: describe "authenticate the user" do ROUTES_REQUIRING_AUTHENTICATION = [?] ROUTES_REQUIRING_AUTHENTICATION.each do | route | example "when requesting the resource at route #{route}" do authentication_service.should_receive(?) get route end end end The authorization policy checks will be a bit more complicated, but at least you can gather them all in the same place for easy reference. Etc. I'm not looking for specific answers to the above as much as > guiding principles, or at least pointers to same. Thanks! > My guiding principles haven't changed in almost 15 years: http://link.jbrains.ca/simple-design -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Author, JUnit Recipes Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From cnk at ugcs.caltech.edu Tue Sep 11 20:25:15 2012 From: cnk at ugcs.caltech.edu (Cynthia Kiser) Date: Tue, 11 Sep 2012 13:25:15 -0700 Subject: [rspec-users] Drawing the line between controller and integration tests In-Reply-To: <153ba8ff3332730d95754dc51849389c@ruby-forum.com> References: <153ba8ff3332730d95754dc51849389c@ruby-forum.com> Message-ID: <20120911202515.GD10926@ugcs.caltech.edu> Quoting Fearless Fool : > I'm trying to understand what belongs -- and what doesn't belong -- in > controller tests and in integration tests. > > As a common example, assume I have a list of named widgets. Somewhere > in my code, I want to verify that > > widget = FactoryGirl.create(:widget) > get :index > > generates a page that has the string #{widget.name} somewhere therein. > But is that a controller test or an integration test? First, one of the other responses in this thread split the world into unit tests vs integration tests. For the most part, the tests generated by the Rails framework are all set up to be unit tests (provided you use mocks and stubs instead of the supporting objects that you are not directly testing in a particular file). In your example above, since you created the object instead of using a stub or mock, this is an integration test, not a straight unit test for the controller. This test could fail for reasons having nothing to do with the controller (e.g. you added a required field ot the widget model and forgot to update your factory) - that makes it an integration test. To make that into a controller unit test, you need to mock the widget and just test that the controller makes available an instance variable containing 'widget'. Then you need a view spec that provides a mock for the @widget variable and then makes sure that the view displays the widget name. Or, as one of the other people pointed out, make an integration test that does all of what you outlined above. > As another example, assume a user must be logged on in order to access > the widgets. I can test authentication and authorization separately, > but is it considered necessary to write an integration test for this? > Or is this something you'd verify at the controller level? I usually take the road mentioned by one of the other respondents and create a separate file containing my authorization tests. Because in that file I am only focusing on the return status from the request, I am more or less making unit tests for my authorization configuration. > One addendum: One thing I'd specifically like to know is where/how > do you test the *contents* of generated responses? That seems > beyond the purview of a controller test, but it doesn't require > multiple transactions or cross-controller interactions that would > require an integration test. In a Rails context, you test the contents of the generated responses in view tests. -- Cynthia N. Kiser cnk at ugcs.caltech.edu From sahmed1020 at gmail.com Fri Sep 14 16:20:56 2012 From: sahmed1020 at gmail.com (S Ahmed) Date: Fri, 14 Sep 2012 12:20:56 -0400 Subject: [rspec-users] how to stop rspec from creating helper/view specs? Message-ID: I tried adding this to my application.rb: config.generators do |g| g.view_specs false g.helper_specs false end But it didn't stop the generator from creating view/helper specs. What am I doing wrong? Also also tried doing this the configuration section: config.view_specs = false config.helper_specs = false But it didn't do anything. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Sep 14 16:30:30 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Sep 2012 11:30:30 -0500 Subject: [rspec-users] how to stop rspec from creating helper/view specs? In-Reply-To: References: Message-ID: On Fri, Sep 14, 2012 at 11:20 AM, S Ahmed wrote: > I tried adding this to my application.rb: > > config.generators do |g| > g.view_specs false > g.helper_specs false > end See "Customizing your workflow" on http://guides.rubyonrails.org/generators.html According to that, you need to something like this, but I've never tried it, so if it doesn't work please consult the rails mailing list (although, do let us know whether it does). config.generators do |g| g.test_framework :rspec, :view_specs => false, :helper_specs => false end HTH, David > > > But it didn't stop the generator from creating view/helper specs. > > What am I doing wrong? > > Also also tried doing this the configuration section: > > config.view_specs = false > config.helper_specs = false > > > But it didn't do anything. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Fri Sep 14 16:31:19 2012 From: lists at ruby-forum.com (ankush m.) Date: Fri, 14 Sep 2012 18:31:19 +0200 Subject: [rspec-users] Rspec for thor script Message-ID: <4e323165dbe5193add933a98e9597883@ruby-forum.com> Hello all, I recently developed a CLI extending thor API. While i was trying to write specs for thor's tasks, I couldn't find any way to write the same for tasks with mandatory options or with options. So can anyone please guide me for the same? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Sep 14 16:47:35 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Sep 2012 11:47:35 -0500 Subject: [rspec-users] Rspec for thor script In-Reply-To: <4e323165dbe5193add933a98e9597883@ruby-forum.com> References: <4e323165dbe5193add933a98e9597883@ruby-forum.com> Message-ID: On Fri, Sep 14, 2012 at 11:31 AM, ankush m. wrote: > Hello all, > I recently developed a CLI extending thor API. > While i was trying to write specs for thor's tasks, I couldn't find any > way to write the same for tasks with mandatory options or with options. > So can anyone please guide me for the same? I haven't written any myself, but I'd recommend taking a look at thor's own specs for guidance: https://github.com/wycats/thor/tree/master/spec HTH, David From sahmed1020 at gmail.com Sun Sep 23 23:55:43 2012 From: sahmed1020 at gmail.com (S Ahmed) Date: Sun, 23 Sep 2012 19:55:43 -0400 Subject: [rspec-users] How can I create a active-record model w/o depending on the database? Message-ID: I have a class that takes a class that inherits from activerecord as a parameter, e.g.: class SomeModel < ActiveRecord::Base end class MyClass attr_accessor :model def initialize(model) @model = model end end The class MyClass will then iterate over the Models attributes etc. Also I will need to know each attributes data type in mysql like: integer, boolean, etc. So my unit tests shouldnt' rely on the database, but I'm a little confused on how I can create stub/mock that will have attributes on it similiar to how it would be if I was creating a model and it reading the mysql columns as attributes. Thoughts on how I can do this w/o actually having to depend on a database for my spec tests? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Sep 24 00:31:56 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 23 Sep 2012 20:31:56 -0400 Subject: [rspec-users] How can I create a active-record model w/o depending on the database? In-Reply-To: References: Message-ID: On Sun, Sep 23, 2012 at 7:55 PM, S Ahmed wrote: > I have a class that takes a class that inherits from activerecord as a > parameter, e.g.: > > class SomeModel < ActiveRecord::Base > end > > class MyClass > attr_accessor :model > def initialize(model) > @model = model > end > end > > > The class MyClass will then iterate over the Models attributes etc. > > Also I will need to know each attributes data type in mysql like: integer, > boolean, etc. > > So my unit tests shouldnt' rely on the database, but I'm a little confused > on how I can create stub/mock that will have attributes on it similiar to > how it would be if I was creating a model and it reading the mysql columns > as attributes. > > Thoughts on how I can do this w/o actually having to depend on a database > for my spec tests? There is a guideline that says "Don't mock types you don't own," which I've just learned was coined by my colleague at DRW, Joe Walnes [1]. In this case, this guideline suggests that you stub/mock MyClass in tests for the objects that interact with it, thereby isolating _them_ from the database, but that the tests for MyClass itself are allowed to interact w/ the database through the AR model. This limits your dependency on AR to MyClass and its tests, so changes to ActiveRecord and/or decisions to move to a different database abstraction don't fan out very far. Make sense? Make sense? From sahmed1020 at gmail.com Mon Sep 24 00:56:12 2012 From: sahmed1020 at gmail.com (S Ahmed) Date: Sun, 23 Sep 2012 20:56:12 -0400 Subject: [rspec-users] How can I create a active-record model w/o depending on the database? In-Reply-To: References: Message-ID: Yes, I think I get it. The actual class can interact since it is kinda necessary and vital to testing int anyhow, but when other classes are depending on MyClass, you can stub/mock since they are outside the scope or domain of the MyClass, so they shouldn't have to be depending on the dependancies of Myclass. On Sun, Sep 23, 2012 at 8:31 PM, David Chelimsky wrote: > On Sun, Sep 23, 2012 at 7:55 PM, S Ahmed wrote: > > I have a class that takes a class that inherits from activerecord as a > > parameter, e.g.: > > > > class SomeModel < ActiveRecord::Base > > end > > > > class MyClass > > attr_accessor :model > > def initialize(model) > > @model = model > > end > > end > > > > > > The class MyClass will then iterate over the Models attributes etc. > > > > Also I will need to know each attributes data type in mysql like: > integer, > > boolean, etc. > > > > So my unit tests shouldnt' rely on the database, but I'm a little > confused > > on how I can create stub/mock that will have attributes on it similiar to > > how it would be if I was creating a model and it reading the mysql > columns > > as attributes. > > > > Thoughts on how I can do this w/o actually having to depend on a database > > for my spec tests? > > There is a guideline that says "Don't mock types you don't own," which > I've just learned was coined by my colleague at DRW, Joe Walnes [1]. > > In this case, this guideline suggests that you stub/mock MyClass in > tests for the objects that interact with it, thereby isolating _them_ > from the database, but that the tests for MyClass itself are allowed > to interact w/ the database through the AR model. This limits your > dependency on AR to MyClass and its tests, so changes to ActiveRecord > and/or decisions to move to a different database abstraction don't fan > out very far. > > Make sense? > > Make sense? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Sep 24 01:01:54 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 23 Sep 2012 21:01:54 -0400 Subject: [rspec-users] How can I create a active-record model w/o depending on the database? In-Reply-To: References: Message-ID: On Sun, Sep 23, 2012 at 8:56 PM, S Ahmed wrote: > Yes, I think I get it. > > The actual class can interact since it is kinda necessary and vital to > testing int anyhow, but when other classes are depending on MyClass, you can > stub/mock since they are outside the scope or domain of the MyClass, so they > shouldn't have to be depending on the dependancies of Myclass. That's basically it. > > On Sun, Sep 23, 2012 at 8:31 PM, David Chelimsky > wrote: >> >> On Sun, Sep 23, 2012 at 7:55 PM, S Ahmed wrote: >> > I have a class that takes a class that inherits from activerecord as a >> > parameter, e.g.: >> > >> > class SomeModel < ActiveRecord::Base >> > end >> > >> > class MyClass >> > attr_accessor :model >> > def initialize(model) >> > @model = model >> > end >> > end >> > >> > >> > The class MyClass will then iterate over the Models attributes etc. >> > >> > Also I will need to know each attributes data type in mysql like: >> > integer, >> > boolean, etc. >> > >> > So my unit tests shouldnt' rely on the database, but I'm a little >> > confused >> > on how I can create stub/mock that will have attributes on it similiar >> > to >> > how it would be if I was creating a model and it reading the mysql >> > columns >> > as attributes. >> > >> > Thoughts on how I can do this w/o actually having to depend on a >> > database >> > for my spec tests? >> >> There is a guideline that says "Don't mock types you don't own," which >> I've just learned was coined by my colleague at DRW, Joe Walnes [1]. >> >> In this case, this guideline suggests that you stub/mock MyClass in >> tests for the objects that interact with it, thereby isolating _them_ >> from the database, but that the tests for MyClass itself are allowed >> to interact w/ the database through the AR model. This limits your >> dependency on AR to MyClass and its tests, so changes to ActiveRecord >> and/or decisions to move to a different database abstraction don't fan >> out very far. >> >> Make sense? >> >> Make sense? >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From kannan.deepak at gmail.com Wed Sep 26 15:16:06 2012 From: kannan.deepak at gmail.com (deepak kannan) Date: Wed, 26 Sep 2012 20:46:06 +0530 Subject: [rspec-users] i cannot seem to use at_least Message-ID: hi, Problem is that i want to test chained method calls. Where the method chain is optional But if the method chain is called then certain assertions apply on the method chain itself The object may or may not call a method. But if it does call the method then it has to call another method on it (ie. method chain) with certain arguments I wrote a comment explaining my actual usecase at https://github.com/rspec/rspec-mocks/issues/133#issuecomment-8886264 kind-of obfuscated and simplified code example is at https://gist.github.com/3788035 code snippet: mock = mock('Monitor') mock.should_receive(:ping).with('DS1').and_return(stub.as_null_object) devops.should_receive(:monitor).and_return(proxy) i read these issues https://github.com/rspec/rspec-mocks/issues/131 https://github.com/rspec/rspec-mocks/issues/133 -- best, deepak w: https://gist.github.com/deepak -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.lovell at gmail.com Wed Sep 26 15:35:02 2012 From: benjamin.lovell at gmail.com (Ben Lovell) Date: Wed, 26 Sep 2012 16:35:02 +0100 Subject: [rspec-users] i cannot seem to use at_least In-Reply-To: References: Message-ID: Hi On 26 September 2012 16:16, deepak kannan wrote: > hi, > > Problem is that i want to test chained method calls. Where the method > chain is optional > But if the method chain is called then certain assertions apply on the > method chain itself > > The object may or may not call a method. > But if it does call the method then it has to call another method on it > (ie. method chain) with certain arguments > I wrote a comment explaining my actual usecase at > https://github.com/rspec/rspec-mocks/issues/133#issuecomment-8886264 > > kind-of obfuscated and simplified code example is at > https://gist.github.com/3788035 > > code snippet: > mock = mock('Monitor') > mock.should_receive(:ping).with('DS1').and_return(stub.as_null_object) > devops.should_receive(:monitor).and_return(proxy) > > i read these issues > https://github.com/rspec/rspec-mocks/issues/131 > https://github.com/rspec/rspec-mocks/issues/133 > > -- > best, > deepak > w: https://gist.github.com/deepak > Did you read the discussion from the issue? https://github.com/rspec/rspec-mocks/issues/133 It makes a strong case as to why at_least(0) makes no sense. Cheers, Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick at collinatorstudios.com Wed Sep 26 16:16:01 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 26 Sep 2012 09:16:01 -0700 (PDT) Subject: [rspec-users] what would be the best way to stub out an XHR request's response? Message-ID: If I have a javascript ajax request happening that fetches json data from a remote service, and I want to be running an integration test with rspec-- what would be the best way to stub out that service? The ideas that I've come up is: manually add a route + open up application controller from within my spec and dynamically create an action that returns mock json... Then make my .js a .js.erb file, and do something like: $.ajax({ url: <%= Rails.env.test? ? "/my_added_route_that_hits_the_controller_method_that_returns_json" : "http://somewebservice.com/feed" %> }); Can anyone come up with any better solutions? Patrick J. Collins http://collinatorstudios.com From webervin at gmail.com Wed Sep 26 17:26:16 2012 From: webervin at gmail.com (Ervin Weber) Date: Wed, 26 Sep 2012 20:26:16 +0300 Subject: [rspec-users] what would be the best way to stub out an XHR request's response? In-Reply-To: References: Message-ID: You could create some function (say window.GiveMeUrlForAjax) that returns uri for ajax request, your test could then easily overwrite that function before triggering event to perform ajax. Also you might consider creating a function that returns data (in production it would take url from "GiveMeUrlForAjax" and do real ajax)" so you could "stub" it in unit tests also. In my opinion it is good to avoid all "if test?" statements in production code (you always can refactor them all into single config file). On Wed, Sep 26, 2012 at 7:16 PM, Patrick J. Collins wrote: > If I have a javascript ajax request happening that fetches json data > from a remote service, and I want to be running an integration test with > rspec-- what would be the best way to stub out that service? > > The ideas that I've come up is: > > manually add a route + open up application controller from within my > spec and dynamically create an action that returns mock json... Then > make my .js a .js.erb file, and do something like: > > $.ajax({ url: <%= Rails.env.test? ? > "/my_added_route_that_hits_the_controller_method_that_returns_json" : > "http://somewebservice.com/feed" %> }); > > Can anyone come up with any better solutions? > > Patrick J. Collins > http://collinatorstudios.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From adam.sroka at gmail.com Wed Sep 26 17:36:05 2012 From: adam.sroka at gmail.com (Adam Sroka) Date: Wed, 26 Sep 2012 10:36:05 -0700 Subject: [rspec-users] what would be the best way to stub out an XHR request's response? In-Reply-To: References: Message-ID: I would just wrap the method that makes the ajax call and spec it from Jasmine. Then you can just stub the wrapper to return the data you want and expect the right thing to happen in the callback method (or however the data gets stored/displayed.) On Wed, Sep 26, 2012 at 10:26 AM, Ervin Weber wrote: > You could create some function (say window.GiveMeUrlForAjax) that > returns uri for ajax request, your test could then easily overwrite > that function before triggering event to perform ajax. Also you might > consider creating a function that returns data (in production it would > take url from "GiveMeUrlForAjax" and do real ajax)" so you could > "stub" it in unit tests also. > In my opinion it is good to avoid all "if test?" statements in > production code (you always can refactor them all into single config > file). > > On Wed, Sep 26, 2012 at 7:16 PM, Patrick J. Collins > wrote: >> If I have a javascript ajax request happening that fetches json data >> from a remote service, and I want to be running an integration test with >> rspec-- what would be the best way to stub out that service? >> >> The ideas that I've come up is: >> >> manually add a route + open up application controller from within my >> spec and dynamically create an action that returns mock json... Then >> make my .js a .js.erb file, and do something like: >> >> $.ajax({ url: <%= Rails.env.test? ? >> "/my_added_route_that_hits_the_controller_method_that_returns_json" : >> "http://somewebservice.com/feed" %> }); >> >> Can anyone come up with any better solutions? >> >> Patrick J. Collins >> http://collinatorstudios.com >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From patrick at collinatorstudios.com Wed Sep 26 18:26:19 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 26 Sep 2012 11:26:19 -0700 (PDT) Subject: [rspec-users] what would be the best way to stub out an XHR request's response? In-Reply-To: References: Message-ID: > I would just wrap the method that makes the ajax call and spec it from > Jasmine. Then you can just stub the wrapper to return the data you > want and expect the right thing to happen in the callback method (or > however the data gets stored/displayed.) Sorry, I am not sure if I am understanding you correctly... Are you saying, in the test environment, load jasmine via